示例#1
0
    def test_weight_and_integration_1d(self):
        """
        Test that the Gaussian distribution intagrates to the weight.
        """
        weight = 1.0
        gaussian = Gaussian(cov=2.0,
                            mean=4.0,
                            log_weight=np.log(weight),
                            var_names=["a"])
        definite_integral, _ = integrate.quad(gaussian.potential, -100.0,
                                              100.0)
        self.assertAlmostEqual(definite_integral, weight)

        # test another weight and with canonical form
        weight = 2.0
        gaussian = Gaussian(cov=2.0,
                            mean=4.0,
                            log_weight=np.log(weight),
                            var_names=["a"])

        gaussian._update_canform()

        gaussian.covform = False
        definite_integral, _ = integrate.quad(gaussian.potential, -100.0,
                                              100.0)
        self.assertAlmostEqual(definite_integral, weight)
示例#2
0
 def test_log_potential_no_form(self):
     """
     Test that the log_potential function raises an exception if the Gaussian has no form.
     """
     gaussian = Gaussian(cov=1.0,
                         mean=1.0,
                         log_weight=np.log(1.0),
                         var_names=["a"])
     gaussian.covform = False
     with self.assertRaises(Exception):
         gaussian.log_potential(x_val=0)
示例#3
0
 def test_copy_no_form(self):
     """
     Test that the copy function raises an exception when a Gaussian does not have either of its form updated.
     """
     gaussian_no_form = Gaussian(cov=1.0,
                                 mean=0.0,
                                 log_weight=0.0,
                                 var_names=["a"])
     gaussian_no_form.covform = False
     with self.assertRaises(Exception):
         gaussian_no_form.copy()