Beispiel #1
0
    def test_raise(self):
        self.sigma_Dd = 100
        self.sigma_Ddt = 100
        num_samples = 100
        cosmo = FlatLambdaCDM(H0=70, Om0=0.3, Ob0=0.05)
        z_L = 0.3
        z_S = 2
        lensCosmo = LensCosmo(z_L, z_S, cosmo=cosmo)
        self.Dd_true = lensCosmo.D_d
        self.D_dt_true = lensCosmo.D_dt
        D_dt_samples = np.random.normal(self.D_dt_true, self.sigma_Ddt, num_samples)
        D_d_samples = np.random.normal(self.Dd_true, self.sigma_Dd, num_samples)
        self.cosmoL = CosmoLikelihood(z_L, z_S, D_d_samples, D_dt_samples, sampling_option="H0_only", omega_m_fixed=0.3,
                                      omega_lambda_fixed=0.7, omega_mh2_fixed=0.14157, kde_type='scipy_gaussian',
                                      bandwidth=1, flat=True)

        self.cosmoL.sampling_option = 'WRONG'
        with self.assertRaises(ValueError):
            self.cosmoL(a=[])
        with self.assertRaises(ValueError):
            self.cosmoL.likelihood(a=[])
        with self.assertRaises(ValueError):
            self.cosmoL.computeLikelihood(ctx=[])
        with self.assertRaises(ValueError):
            param = CosmoParam(sampling_option='WRONG')
            param.numParam
        with self.assertRaises(ValueError):
            param = CosmoParam(sampling_option='WRONG')
            param.param_bounds
 def setup(self):
     self.sigma_Dd = 100
     self.sigma_Ddt = 100
     num_samples = 100
     cosmo = FlatLambdaCDM(H0=70, Om0=0.3, Ob0=0.05)
     z_L = 0.3
     z_S = 2
     lensCosmo = LensCosmo(z_L, z_S, cosmo=cosmo)
     self.Dd_true = lensCosmo.D_d
     self.D_dt_true = lensCosmo.D_dt
     D_dt_samples = np.random.normal(self.D_dt_true, self.sigma_Ddt,
                                     num_samples)
     D_d_samples = np.random.normal(self.Dd_true, self.sigma_Dd,
                                    num_samples)
     self.cosmoL = CosmoLikelihood(z_L,
                                   z_S,
                                   D_d_samples,
                                   D_dt_samples,
                                   sampling_option="H0_only",
                                   omega_m_fixed=0.3,
                                   omega_lambda_fixed=0.7,
                                   omega_mh2_fixed=0.14157,
                                   kde_type='scipy_gaussian',
                                   bandwidth=1,
                                   flat=True)
Beispiel #3
0
class TestCosmoLikelihood(object):

    def setup(self):
        self.sigma_Dd = 100
        self.sigma_Ddt = 100
        num_samples = 100
        cosmo = FlatLambdaCDM(H0=70, Om0=0.3, Ob0=0.05)
        z_L = 0.3
        z_S = 2
        lensCosmo = LensCosmo(z_L, z_S, cosmo=cosmo)
        self.Dd_true = lensCosmo.D_d
        self.D_dt_true = lensCosmo.D_dt
        D_dt_samples = np.random.normal(self.D_dt_true, self.sigma_Ddt, num_samples)
        D_d_samples = np.random.normal(self.Dd_true, self.sigma_Dd, num_samples)
        self.cosmoL = CosmoLikelihood(z_L, z_S, D_d_samples, D_dt_samples, sampling_option="H0_only", omega_m_fixed=0.3,
                                 omega_lambda_fixed=0.7, omega_mh2_fixed=0.14157, kde_type='scipy_gaussian',
                                 bandwidth=1, flat=True)

    def test_prior_H0(self):
        logL, bool = CosmoLikelihood.prior_H0(H0=10, H0_min=50, H0_max=100)
        assert bool is False

    def test_prior_omega_mh2(self):
        prior, bool = self.cosmoL.prior_omega_mh2(h=1, omega_m=2, h_max=2)
        assert bool is False

    def test_prior_omega_m(self):
        penalty, bool = self.cosmoL.prior_omega_m(omega_m=0, omega_m_min=0.05, omega_m_max=1)
        assert bool is False

    def test_call(self):
        self.cosmoL.sampling_option = 'H0_only'
        a = [70]
        logL, _ = self.cosmoL(a)
        npt.assert_almost_equal(logL, -11, decimal=-1)

        self.cosmoL.sampling_option = 'H0_omega_m'
        a = [70, 0.3]
        logL, _ = self.cosmoL(a)
        npt.assert_almost_equal(logL, -11, decimal=-1)

        self.cosmoL.sampling_option = "fix_omega_mh2"
        a = [70]
        logL, _ = self.cosmoL(a)
        npt.assert_almost_equal(logL, -11, decimal=-1)

        self.cosmoL.sampling_option = 'H0_omega_m_omega_de'
        a = [70, 0.3, 0.7]
        logL, _ = self.cosmoL(a)
        npt.assert_almost_equal(logL, -11, decimal=-1)
 def test_prior_H0(self):
     logL, bool = CosmoLikelihood.prior_H0(H0=10, H0_min=50, H0_max=100)
     assert bool is False