Exemplo n.º 1
0
 def test_sampling_H0_only(self):
     mcmc_sampler = MCMCSampler(self.z_L,
                                self.z_S,
                                self.D_d_samples,
                                self.D_dt_samples,
                                sampling_option="H0_only",
                                omega_m_fixed=self.omega_m_true,
                                omega_mh2_fixed=self.omega_m_true *
                                (self.H0_true / 100)**2)
     walkerRatio = 10
     n_run = 10
     n_burn = 10
     mean_start = [self.H0_true]
     sigma_start = [2]
     mcmc_samples = mcmc_sampler.mcmc_CH(walkerRatio,
                                         n_run,
                                         n_burn,
                                         mean_start,
                                         sigma_start,
                                         threadCount=1,
                                         init_pos=None,
                                         mpi_monch=False)
     H0_mean = np.mean(mcmc_samples)
     npt.assert_almost_equal(H0_mean / self.H0_true, 1, decimal=1)
     sigma = np.sqrt(np.var(mcmc_samples))
     npt.assert_almost_equal(sigma, 1.5, decimal=0)
Exemplo n.º 2
0
 def test_sampling_H0_omega_m_sklearn(self):
     mcmc_sampler = MCMCSampler(self.z_L,
                                self.z_S,
                                self.D_d_samples,
                                self.D_dt_samples,
                                sampling_option="H0_omega_m",
                                omega_m_fixed=self.omega_m_true,
                                omega_mh2_fixed=self.omega_m_true *
                                (self.H0_true / 100)**2,
                                kde_type='gaussian',
                                bandwidth=10)
     walkerRatio = 10
     n_run = 10
     n_burn = 10
     mean_start = [self.H0_true, self.omega_m_true]
     sigma_start = [5, 0.1]
     mcmc_samples = mcmc_sampler.mcmc_CH(walkerRatio,
                                         n_run,
                                         n_burn,
                                         mean_start,
                                         sigma_start,
                                         threadCount=1,
                                         init_pos=None,
                                         mpi_monch=False)
     H0_mean = np.mean(mcmc_samples[:, 0])
     npt.assert_almost_equal(H0_mean / self.H0_true, 1, decimal=1)
     sigma = np.sqrt(np.var(mcmc_samples[:, 0]))
     print(sigma)
     npt.assert_almost_equal(sigma, 2.6, decimal=0)
Exemplo n.º 3
0
 def test_sampling_curvature(self):
     mcmc_sampler = MCMCSampler(self.z_L,
                                self.z_S,
                                self.D_d_samples,
                                self.D_dt_samples,
                                sampling_option="H0_omega_m_omega_de",
                                omega_m_fixed=self.omega_m_true,
                                omega_mh2_fixed=self.omega_m_true *
                                (self.H0_true / 100)**2)
     walkerRatio = 4
     n_run = 10
     n_burn = 10
     mean_start = [self.H0_true, self.omega_m_true, 1 - self.omega_m_true]
     sigma_start = [5, 0.1, 0.1]
     mcmc_samples = mcmc_sampler.mcmc_CH(walkerRatio,
                                         n_run,
                                         n_burn,
                                         mean_start,
                                         sigma_start,
                                         threadCount=1,
                                         init_pos=None,
                                         mpi_monch=False)
     H0_mean = np.mean(mcmc_samples[:, 0])
     npt.assert_almost_equal(H0_mean / self.H0_true, 1, decimal=1)
     Om0_mean = np.mean(mcmc_samples[:, 1])
     npt.assert_almost_equal(Om0_mean / self.omega_m_true, 1, decimal=0)
Exemplo n.º 4
0
 def test_sampling_H0_omega_m(self):
     mcmc_sampler = MCMCSampler(self.z_L,
                                self.z_S,
                                self.D_d_samples,
                                self.D_dt_samples,
                                sampling_option="H0_omega_m",
                                omega_m_fixed=self.omega_m_true,
                                omega_mh2_fixed=self.omega_m_true *
                                (self.H0_true / 100)**2)
     n_walkers = 10
     n_run = 10
     n_burn = 10
     mean_start = [self.H0_true, self.omega_m_true]
     sigma_start = [5, 0.1]
     mcmc_samples = mcmc_sampler.mcmc_emcee(n_walkers, n_run, n_burn,
                                            mean_start, sigma_start)
     H0_mean = np.mean(mcmc_samples[:, 0])
     npt.assert_almost_equal(H0_mean / self.H0_true, 1, decimal=1)
Exemplo n.º 5
0
 def test_sampling_fix_omega_mh2(self):
     mcmc_sampler = MCMCSampler(self.z_L,
                                self.z_S,
                                self.D_d_samples,
                                self.D_dt_samples,
                                sampling_option="fix_omega_mh2",
                                omega_m_fixed=self.omega_m_true,
                                omega_mh2_fixed=self.omega_m_true *
                                (self.H0_true / 100)**2)
     n_walkers = 10
     n_run = 10
     n_burn = 10
     mean_start = [self.H0_true]
     sigma_start = [2]
     mcmc_samples = mcmc_sampler.mcmc_emcee(n_walkers, n_run, n_burn,
                                            mean_start, sigma_start)
     H0_mean = np.mean(mcmc_samples)
     npt.assert_almost_equal(H0_mean / self.H0_true, 1, decimal=1)
     sigma = np.sqrt(np.var(mcmc_samples))
     npt.assert_almost_equal(sigma, 1.5, decimal=0)
Exemplo n.º 6
0
 def test_sampling_H0_omega_m_sklearn(self):
     mcmc_sampler = MCMCSampler(self.z_L,
                                self.z_S,
                                self.D_d_samples,
                                self.D_dt_samples,
                                sampling_option="H0_omega_m",
                                omega_m_fixed=self.omega_m_true,
                                omega_mh2_fixed=self.omega_m_true *
                                (self.H0_true / 100)**2,
                                kde_type='gaussian',
                                bandwidth=10)
     n_walkers = 10
     n_run = 10
     n_burn = 10
     mean_start = [self.H0_true, self.omega_m_true]
     sigma_start = [5, 0.1]
     mcmc_samples = mcmc_sampler.mcmc_emcee(n_walkers, n_run, n_burn,
                                            mean_start, sigma_start)
     print(mcmc_samples, 'test samples')
     H0_mean = np.mean(mcmc_samples[:, 0])
     npt.assert_almost_equal(H0_mean / self.H0_true, 1, decimal=1)
     sigma = np.sqrt(np.var(mcmc_samples[:, 0]))
     print(sigma)
     npt.assert_almost_equal(sigma, 2.6, decimal=0)
Exemplo n.º 7
0
    def test_mcmc_emcee(self):
        n_walkers = 6
        n_run = 2
        n_burn = 2
        mean_start = [self.H0_true]
        sigma_start = [5]
        mcmc_sampler = MCMCSampler(self.z_L,
                                   self.z_S,
                                   self.D_d_samples,
                                   self.D_dt_samples,
                                   sampling_option="H0_only",
                                   omega_m_fixed=self.omega_m_true,
                                   omega_mh2_fixed=self.omega_m_true *
                                   (self.H0_true / 100)**2)
        samples = mcmc_sampler.mcmc_emcee(n_walkers, n_run, n_burn, mean_start,
                                          sigma_start)
        assert len(samples) == n_walkers * n_run

        mean_start = [self.H0_true, self.omega_m_true]
        sigma_start = [5, 0.1]
        mcmc_sampler = MCMCSampler(self.z_L,
                                   self.z_S,
                                   self.D_d_samples,
                                   self.D_dt_samples,
                                   sampling_option="H0_omega_m",
                                   omega_m_fixed=self.omega_m_true,
                                   omega_mh2_fixed=self.omega_m_true *
                                   (self.H0_true / 100)**2)
        samples = mcmc_sampler.mcmc_emcee(n_walkers, n_run, n_burn, mean_start,
                                          sigma_start)
        assert len(samples) == n_walkers * n_run

        mean_start = [self.H0_true]
        sigma_start = [5]
        mcmc_sampler = MCMCSampler(self.z_L,
                                   self.z_S,
                                   self.D_d_samples,
                                   self.D_dt_samples,
                                   sampling_option="fix_omega_mh2",
                                   omega_m_fixed=self.omega_m_true,
                                   omega_mh2_fixed=self.omega_m_true *
                                   (self.H0_true / 100)**2)
        samples = mcmc_sampler.mcmc_emcee(n_walkers, n_run, n_burn, mean_start,
                                          sigma_start)
        assert len(samples) == n_walkers * n_run

        mean_start = [self.H0_true, self.omega_m_true, 1 - self.omega_m_true]
        sigma_start = [5, 0.1, 0.1]
        mcmc_sampler = MCMCSampler(self.z_L,
                                   self.z_S,
                                   self.D_d_samples,
                                   self.D_dt_samples,
                                   sampling_option="H0_omega_m_omega_de",
                                   omega_m_fixed=self.omega_m_true,
                                   omega_mh2_fixed=self.omega_m_true *
                                   (self.H0_true / 100)**2)
        samples = mcmc_sampler.mcmc_emcee(n_walkers, n_run, n_burn, mean_start,
                                          sigma_start)
        assert len(samples) == n_walkers * n_run