def setUp(self):
     self.date = str(datetime.date.today())
     self.folder = os.path.join("tests", "test06_%s" % self.date)
     self.number = 30
     self.custom_command = "run -N %d -p test.param -o %s" % (self.number, self.folder)
     self.cosmo, self.data, self.command_line, _ = initialise(self.custom_command)
     sampler.run(self.cosmo, self.data, self.command_line)
    def test_block_behaviour(self):
        """
        Are the mcmc arguments well grouped by block?
        """
        # The block separation must have selected three blocks, of size
        # respectively 2, 1, and 1 (the two test nuisance likelihoods are
        # sharing a nuisance parameter)
        self.assertEqual(self.data.block_parameters, [2, 3, 4], "The block selection went wrong")

        # By default, the over-sampling should be set to 1
        self.assertEqual(self.data.over_sampling, [1, 1, 1], "The default over sampling is messed up")

        # For the sake of the test, set them to something else
        self.data.over_sampling = [1, 3, 5]
        self.data.assign_over_sampling_indices()
        self.assertEqual(self.data.over_sampling_indices, [0, 1, 2, 2, 2, 3, 3, 3, 3, 3])

        # Run the sampler
        sampler.run(self.cosmo, self.data, self.command_line)

        # Verify that the output is well behaved
        output_path = os.path.join(self.folder, "%s_%d__1.txt" % (self.date, self.number))
        with open(output_path, "r") as output_file:
            chain = np.loadtxt(output_file)
        for index in range(2, 4):
            self.assertLessEqual(
                len(np.unique(chain[:, index])), float(self.number) / 10 * 2, "%s" % np.unique(chain[:, index])
            )
        self.assertLessEqual(len(np.unique(chain[:, 3])), float(self.number) / 10 * 3)
        self.assertLessEqual(len(np.unique(chain[:, 4])), float(self.number) / 10 * 5)
Esempio n. 3
0
 def setUp(self):
     self.date = str(datetime.date.today())
     self.folder = os.path.join('tests', 'test06_%s' % self.date)
     self.number = 30
     self.custom_command = ('run -N %d -p test.param -o %s' %
                            (self.number, self.folder))
     self.cosmo, self.data, self.command_line, _ = initialise(
         self.custom_command)
     sampler.run(self.cosmo, self.data, self.command_line)
    def test_cosmological_arguments(self):
        """
        Are the cosmological arguments well set?
        """
        # After the initialisation, the dictionnary mcmc_parameters should
        # contain five Parameter instances
        self.assertEqual(len(self.data.mcmc_parameters), 5, "mcmc_parameters badly defined")

        # Run the sampler
        sampler.run(self.cosmo, self.data, self.command_line)
        self.assertEqual(
            self.data.mcmc_parameters["omega_b"]["current"] * self.data.mcmc_parameters["omega_b"]["scale"],
            self.data.cosmo_arguments["omega_b"],
            "the cosmo_arguments dict was not updated properly",
        )
Esempio n. 5
0
    def test_cosmological_arguments(self):
        """
        Are the cosmological arguments well set?
        """
        # After the initialisation, the dictionnary mcmc_parameters should
        # contain five Parameter instances
        self.assertEqual(len(self.data.mcmc_parameters), 5,
                         "mcmc_parameters badly defined")

        # Run the sampler
        sampler.run(self.cosmo, self.data, self.command_line)
        self.assertEqual(
            self.data.mcmc_parameters['omega_b']['current'] *
            self.data.mcmc_parameters['omega_b']['scale'],
            self.data.cosmo_arguments['omega_b'],
            "the cosmo_arguments dict was not updated properly")
Esempio n. 6
0
    def test_block_behaviour(self):
        """
        Are the mcmc arguments well grouped by block?
        """
        # The block separation must have selected three blocks, of size
        # respectively 2, 1, and 1 (the two test nuisance likelihoods are
        # sharing a nuisance parameter)
        self.assertEqual(
            self.data.block_parameters,
            [2, 3, 4],
            "The block selection went wrong")

        # By default, the over-sampling should be set to 1
        self.assertEqual(
            self.data.over_sampling,
            [1, 1, 1],
            "The default over sampling is messed up")

        # For the sake of the test, set them to something else
        self.data.over_sampling = [1, 3, 5]
        self.data.assign_over_sampling_indices()
        self.assertEqual(
            self.data.over_sampling_indices,
            [0, 1, 2, 2, 2, 3, 3, 3, 3, 3])

        # Run the sampler
        sampler.run(self.cosmo, self.data, self.command_line)

        # Verify that the output is well behaved
        output_path = os.path.join(
            self.folder, '%s_%d__1.txt' % (self.date, self.number))
        with open(output_path, 'r') as output_file:
            chain = np.loadtxt(output_file)
        for index in range(2, 4):
            self.assertLessEqual(
                len(np.unique(chain[:, index])),
                float(self.number)/10*2,
                "%s" % np.unique(chain[:, index]))
        self.assertLessEqual(
            len(np.unique(chain[:, 3])),
            float(self.number)/10*3)
        self.assertLessEqual(
            len(np.unique(chain[:, 4])),
            float(self.number)/10*5)
 def test_behaviour(self):
     """Check Nested Sampling global behaviour"""
     self.assertTrue(os.path.exists(os.path.join(self.folder, "NS")))
     sampler.run(self.cosmo, self.data, self.command_line)
Esempio n. 8
0
 def test_behaviour(self):
     """Check PolyChord global behaviour"""
     self.assertTrue(os.path.exists(
         os.path.join(self.folder, 'PC')))
     sampler.run(self.cosmo, self.data, self.command_line)
Esempio n. 9
0
 def test_behaviour(self):
     """Check Nested Sampling global behaviour"""
     self.assertTrue(os.path.exists(os.path.join(self.folder, 'NS')))
     sampler.run(self.cosmo, self.data, self.command_line)