How to use the abcpy.distributions.Uniform function in abcpy

To help you get started, we’ve selected a few abcpy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github eth-cscs / abcpy / tests / distributions_tests.py View on Github external
def setUp(self):
        prior = Uniform([3.,0.,1.],[5.,1.,20.],seed=1)
        self.distribution = Ricker(prior, n_timestep=100, seed=1)
github eth-cscs / abcpy / tests / distributions_tests.py View on Github external
def test_set_parameters(self):
        distribution = Uniform([-101], [-100], seed=1)
        sample = distribution.sample(1)[0, 0]
        self.assertLessEqual(sample, -100)
        self.assertGreaterEqual(sample, -101)

        distribution.set_parameters([[100], [101]])
        sample = distribution.sample(1)[0, 0]
        self.assertLessEqual(sample, 101)
        self.assertGreaterEqual(sample, 100)

        self.distribution_multid.set_parameters([[1,[1.3,[1.2,0.2]]],[[[2,2],[[2.5,2.5],[[1,0],[0,1]]]]]])
        self.assertTrue(self.distribution_multid.get_parameters()==[[1, [1.3, [1.2, 0.2]]], [[[2, 2], [[2.5, 2.5], [[1, 0], [0, 1]]]]]]
)
github eth-cscs / abcpy / tests / distributions_tests.py View on Github external
def setUp(self):
        self.distribution = Uniform([-1.0, -1.0], [1.0, 1.0], seed=1)
        self.distribution_graph = Uniform(self.distribution, self.distribution, seed=1)
        helper_distribution = Normal(1,0.5,seed=1)
        helper_distribution_2 = MultiNormal([1,1],[[1,0],[0,1]],seed=1)
        self.distribution_multid = Uniform([0,helper_distribution],[helper_distribution_2], seed=1)
github eth-cscs / abcpy / tests / distributions_tests.py View on Github external
def setUp(self):
        self.distribution = Uniform([-1.0, -1.0], [1.0, 1.0], seed=1)
        self.distribution_graph = Uniform(self.distribution, self.distribution, seed=1)
        helper_distribution = Normal(1,0.5,seed=1)
        helper_distribution_2 = MultiNormal([1,1],[[1,0],[0,1]],seed=1)
        self.distribution_multid = Uniform([0,helper_distribution],[helper_distribution_2], seed=1)
github eth-cscs / abcpy / tests / distributions_tests.py View on Github external
def setUp(self):
        prior = Uniform([1,.1],[3,.3],seed=1)
        self.distribution = StochLorenz95(prior, initial_state=None, n_timestep = 160, seed=1)
github eth-cscs / abcpy / tests / distributions_tests.py View on Github external
def test_pdf(self):
        new_prior = Uniform(np.array([0.0]), np.array([10.0]), seed=1)
        self.assertEqual(new_prior.pdf(0), 0.1)
        self.assertEqual(new_prior.pdf(-1), 0)
        self.assertEqual(new_prior.pdf(11), 0)
github eth-cscs / abcpy / tests / distributions_tests.py View on Github external
def setUp(self):
        np.random.seed(1)
        self.mean = 0.5
        self.df = 2
        self.distribution = StudentT(self.mean, self.df, seed=1)
        self.distribution_graph = StudentT(Uniform([-1.],[1.],seed=1), Uniform([0.],[1.],seed=1),seed=1)
github eth-cscs / abcpy / tests / distributions_tests.py View on Github external
expected_means = np.array([1.0034, 2.0012, 3.0000])
        expected_var = np.array([0.4911, 0.4912, 0.4961])
        self.assertTrue((np.abs(computed_means-expected_means)<0.15).all())
        self.assertTrue((np.abs(computed_var-expected_var)<0.15).all())

        self.distribution_graph = MixtureNormal(self.distribution, seed=1)
        samples_graph = self.distribution_graph.sample(100)
        computed_means_graph = samples_graph.mean(axis=0)
        computed_var_graph = samples_graph.var(axis=0)

        expected_means_graph = np.array([1.0187, 2.0171, 3.0260])
        expected_var_graph = np.array([0.4911, 0.4912, 0.4961])
        self.assertTrue((np.abs(computed_means_graph-expected_means_graph)<1.5).all())
        self.assertTrue((np.abs(computed_var_graph-expected_var_graph)<0.15).all())

        self.distribution_uniform = MixtureNormal(Uniform([1,2],[3,4],seed=1),seed=1)
        self.distribution_1d = MixtureNormal([Normal(1,0.5,seed=1),StudentT(1,2,seed=1)],seed=1)

        samples_uniform = self.distribution_uniform.sample(100)
        samples_1d = self.distribution_1d.sample(100)
github eth-cscs / abcpy / examples / extensions / simplemodels / gaussian_f90 / pmcabc-gaussian_model_simple.py View on Github external
def infer_parameters():
    # define observation for true parameters mean=170, std=15
    y_obs = [160.82499176, 167.24266737, 185.71695756, 153.7045709, 163.40568812, 140.70658699, 169.59102084, 172.81041696, 187.38782738, 179.66358934, 176.63417241, 189.16082803, 181.98288443, 170.18565017, 183.78493886, 166.58387299, 161.9521899, 155.69213073, 156.17867343, 144.51580379, 170.29847515, 197.96767899, 153.36646527, 162.22710198, 158.70012047, 178.53470703, 170.77697743, 164.31392633, 165.88595994, 177.38083686, 146.67058471763457, 179.41946565658628, 238.02751620619537, 206.22458790620766, 220.89530574344568, 221.04082532837026, 142.25301427453394, 261.37656571434275, 171.63761180867033, 210.28121820385866, 237.29130237612236, 175.75558340169619, 224.54340549862235, 197.42448680731226, 165.88273684581381, 166.55094082844519, 229.54308602661584, 222.99844054358519, 185.30223966014586, 152.69149367593846, 206.94372818527413, 256.35498655339154, 165.43140916577741, 250.19273595481803, 148.87781549665536, 223.05547559193792, 230.03418198709608, 146.13611923127021, 138.24716809523139, 179.26755740864527, 141.21704876815426, 170.89587081800852, 222.96391329259626, 188.27229523693822, 202.67075179617672, 211.75963110985992, 217.45423324370509]

    # define prior
    from abcpy.distributions import Uniform
    prior = Uniform([150, 5],[200, 25])
    
    # define the model
    model = Gaussian(prior)
    
    # define statistics
    from abcpy.statistics import Identity
    statistics_calculator = Identity(degree = 2, cross = False)
    
    # define distance
    from abcpy.distances import LogReg
    distance_calculator = LogReg(statistics_calculator)
    
    # define kernel
    from abcpy.distributions import MultiStudentT
    mean, cov, df = np.array([.0, .0]), np.eye(2), 3.
    kernel = MultiStudentT(mean, cov, df)
github eth-cscs / abcpy / examples / backends / apache_spark / pmcabc_gaussian.py View on Github external
def infer_parameters():
    # define observation for true parameters mean=170, std=15
    y_obs = [160.82499176, 167.24266737, 185.71695756, 153.7045709, 163.40568812, 140.70658699, 169.59102084, 172.81041696, 187.38782738, 179.66358934, 176.63417241, 189.16082803, 181.98288443, 170.18565017, 183.78493886, 166.58387299, 161.9521899, 155.69213073, 156.17867343, 144.51580379, 170.29847515, 197.96767899, 153.36646527, 162.22710198, 158.70012047, 178.53470703, 170.77697743, 164.31392633, 165.88595994, 177.38083686, 146.67058471763457, 179.41946565658628, 238.02751620619537, 206.22458790620766, 220.89530574344568, 221.04082532837026, 142.25301427453394, 261.37656571434275, 171.63761180867033, 210.28121820385866, 237.29130237612236, 175.75558340169619, 224.54340549862235, 197.42448680731226, 165.88273684581381, 166.55094082844519, 229.54308602661584, 222.99844054358519, 185.30223966014586, 152.69149367593846, 206.94372818527413, 256.35498655339154, 165.43140916577741, 250.19273595481803, 148.87781549665536, 223.05547559193792, 230.03418198709608, 146.13611923127021, 138.24716809523139, 179.26755740864527, 141.21704876815426, 170.89587081800852, 222.96391329259626, 188.27229523693822, 202.67075179617672, 211.75963110985992, 217.45423324370509]

    # define prior
    from abcpy.distributions import Uniform
    prior = Uniform([150, 5],[200, 25], seed=1)

    # define the model
    from abcpy.models import Gaussian
    model = Gaussian(prior, seed=1)

    # define statistics
    from abcpy.statistics import Identity
    statistics_calculator = Identity(degree = 2, cross = False)

    # define distance
    from abcpy.distances import LogReg
    distance_calculator = LogReg(statistics_calculator)

    # define kernel
    from abcpy.distributions import MultiStudentT
    mean, cov, df = np.array([.0, .0]), np.eye(2), 3.