Exemplo n.º 1
0
class TestTakeStepProbability(unittest.TestCase):
    
    def setUp(self):
        self.ndim = 42
        self.k = 100
        self.bdim = 2
        self.origin = np.zeros(self.ndim)
        self.potential = Harmonic(self.origin, self.k, bdim=self.bdim, com=False)
        self.potential_pattern = Harmonic(self.origin, self.k, bdim=self.bdim, com=False)
        self.temp = 1
        self.nr_steps = 1e4
        self.mc = MC(self.potential, self.origin, self.temp, self.nr_steps)
        self.mc_pattern = MC(self.potential_pattern, self.origin, self.temp, self.nr_steps)
        
    def test_frequencies(self):
        self.tsA = GaussianCoordsDisplacement(42, 1, self.ndim)
        self.tsA_pattern = GaussianCoordsDisplacement(42, 1, self.ndim)
        self.tsB = GaussianCoordsDisplacement(44, 2, self.ndim)
        self.tsB_pattern = GaussianCoordsDisplacement(44, 2, self.ndim)
        self.step = TakeStepProbabilities(42)
        self.step.add_step(self.tsA, 1)
        self.step.add_step(self.tsB, 3)
        self.step_pattern = TakeStepPattern()
        self.step_pattern.add_step(self.tsA_pattern, 1)
        self.step_pattern.add_step(self.tsB_pattern, 3)
        freqA = 1 / (1 + 3)
        freqB = 1 - freqA
        self.mc.set_takestep(self.step)
        self.mc.run()
        self.mc_pattern.set_takestep(self.step_pattern)
        self.mc_pattern.run()
        self.assertAlmostEqual(freqA, self.tsA.get_count() / self.nr_steps, delta=1e-2)
        self.assertAlmostEqual(freqB, self.tsB.get_count() / self.nr_steps, delta=1e-2)
        self.assertAlmostEqual(freqA, self.tsA_pattern.get_count() / self.nr_steps, delta=1e-2)
        self.assertAlmostEqual(freqB, self.tsB_pattern.get_count() / self.nr_steps, delta=1e-2)
Exemplo n.º 2
0
 def test_frequencies(self):
     self.tsA = GaussianCoordsDisplacement(42, 1, self.ndim)
     self.tsA_pattern = GaussianCoordsDisplacement(42, 1, self.ndim)
     self.tsB = GaussianCoordsDisplacement(44, 2, self.ndim)
     self.tsB_pattern = GaussianCoordsDisplacement(44, 2, self.ndim)
     self.step = TakeStepProbabilities(42)
     self.step.add_step(self.tsA, 1)
     self.step.add_step(self.tsB, 3)
     self.step_pattern = TakeStepPattern()
     self.step_pattern.add_step(self.tsA_pattern, 1)
     self.step_pattern.add_step(self.tsB_pattern, 3)
     freqA = 1 / (1 + 3)
     freqB = 1 - freqA
     self.mc.set_takestep(self.step)
     self.mc.run()
     self.mc_pattern.set_takestep(self.step_pattern)
     self.mc_pattern.run()
     self.assertAlmostEqual(freqA, self.tsA.get_count() / self.nr_steps, delta=1e-2)
     self.assertAlmostEqual(freqB, self.tsB.get_count() / self.nr_steps, delta=1e-2)
     self.assertAlmostEqual(freqA, self.tsA_pattern.get_count() / self.nr_steps, delta=1e-2)
     self.assertAlmostEqual(freqB, self.tsB_pattern.get_count() / self.nr_steps, delta=1e-2)