コード例 #1
0
ファイル: test_StudentTRestraint.py プロジェクト: salilab/imp
 def create_particles(self):
     x = Nuisance.setup_particle(IMP.Particle(self.m), 2.0)
     mu = Nuisance.setup_particle(IMP.Particle(self.m), 1.0)
     sigma = Scale.setup_particle(IMP.Particle(self.m), 2.0)
     nu = Scale.setup_particle(IMP.Particle(self.m), 3.0)
     all_nuis = [x, mu, sigma, nu]
     return all_nuis
コード例 #2
0
 def create_particles(self):
     x = Nuisance.setup_particle(IMP.Particle(self.m), 2.0)
     mu = Nuisance.setup_particle(IMP.Particle(self.m), 1.0)
     sigma = Scale.setup_particle(IMP.Particle(self.m), 2.0)
     nu = Scale.setup_particle(IMP.Particle(self.m), 3.0)
     all_nuis = [x, mu, sigma, nu]
     return all_nuis
コード例 #3
0
 def test_nuisance_down(self):
     n=IMP.kernel.Particle(self.m)
     Nuisance.setup_particle(n,1.0)
     Nuisance(n).set_lower(0.5)
     Nuisance(n).set_upper(1.5)
     n.set_value(Nuisance.get_nuisance_key(), 0.1)
     self.m.evaluate(False)
     self.assertAlmostEqual(n.get_value(Nuisance.get_nuisance_key()),
         0.5, delta=1e-7)
     self.assertAlmostEqual(self.rs.values[0],0.5)
コード例 #4
0
 def setUp(self):
     IMP.test.TestCase.setUp(self)
     # IMP.base.set_log_level(IMP.MEMORY)
     IMP.base.set_log_level(0)
     self.m = IMP.kernel.Model()
     self.sigma = Scale.setup_particle(IMP.kernel.Particle(self.m), 2.0)
     self.mu = Nuisance.setup_particle(IMP.kernel.Particle(self.m), 1.0)
     self.x = Nuisance.setup_particle(IMP.kernel.Particle(self.m), 2.0)
     self.locations = [self.x, self.mu]
     self.all = self.locations + [self.sigma]
     self.DA = IMP.DerivativeAccumulator()
コード例 #5
0
 def setUp(self):
     IMP.test.TestCase.setUp(self)
     #IMP.base.set_log_level(IMP.MEMORY)
     IMP.base.set_log_level(0)
     self.m = IMP.Model()
     self.sigma = Scale.setup_particle(IMP.Particle(self.m), 2.0)
     self.mu = Nuisance.setup_particle(IMP.Particle(self.m), 1.0)
     self.x = Nuisance.setup_particle(IMP.Particle(self.m), 2.0)
     self.locations=[self.x, self.mu]
     self.all = self.locations+[self.sigma]
     self.DA = IMP.DerivativeAccumulator()
コード例 #6
0
 def test_nuisance_down(self):
     n=IMP.Particle(self.m)
     Nuisance.setup_particle(n,1.0)
     Nuisance(n).set_lower(0.5)
     Nuisance(n).set_upper(1.5)
     self.m.add_score_state(IMP.core.SingletonConstraint(
         IMP.isd.NuisanceRangeModifier(), None, n))
     n.set_value(Nuisance.get_nuisance_key(), 0.1)
     self.m.evaluate(False)
     self.assertAlmostEqual(n.get_value(Nuisance.get_nuisance_key()),
         0.5, delta=1e-7)
     self.assertAlmostEqual(self.rs.values[0],0.5)
コード例 #7
0
 def test_Switching(self):
     "Test that a Switching can be converted to a Nuisance"
     n = Switching.setup_particle(IMP.Particle(self.m))
     n.set_lower(-10)
     n.set_upper(10)
     self.assertTrue(Nuisance.get_is_setup(n.get_particle()))
     self.assertFalse(Switching.get_is_setup(n.get_particle()))
コード例 #8
0
 def test_Setup2(self):
     si = Nuisance.setup_particle(IMP.Particle(self.m), 2.0)
     si.set_lower(0.1)
     si.set_upper(10)
     self.assertAlmostEqual(float(si.get_nuisance()),2.0, delta=1e-6)
     self.assertAlmostEqual(float(si.get_lower()),0.1, delta=1e-6)
     self.assertAlmostEqual(float(si.get_upper()),10.0, delta=1e-6)
コード例 #9
0
 def test_Switching(self):
     "test that a Switching can be converted to a Nuisance"
     n=Switching.setup_particle(IMP.Particle(self.m))
     n.set_lower(-10)
     n.set_upper(10)
     self.assertTrue(Nuisance.particle_is_instance(n.get_particle()))
     self.assertFalse(Switching.particle_is_instance(n.get_particle()))
コード例 #10
0
ファイル: test_Nuisance.py プロジェクト: AljGaber/imp
 def test_GetSet_Particle(self):
     "Test nuisance get and set (border check) with particles"
     nuisance = Nuisance.setup_particle(IMP.Particle(self.m), 50.0)
     lower = Nuisance.setup_particle(IMP.Particle(self.m), 10.0)
     upper = Nuisance.setup_particle(IMP.Particle(self.m), 80.0)
     nuisance.set_lower(lower)
     nuisance.set_upper(upper)
     for si in range(1, 100):
         nuisance.set_nuisance(si)
         if si < 10:
             est = 10
         elif si > 80:
             est = 80
         else:
             est = si
         self.assertAlmostEqual(nuisance.get_nuisance(), est, delta=1e-6)
コード例 #11
0
 def test_GetSet_Particle(self):
     "Test nuisance get and set (border check) with particles"
     nuisance = Nuisance.setup_particle(IMP.Particle(self.m), 50.0)
     lower = Nuisance.setup_particle(IMP.Particle(self.m), 10.0)
     upper = Nuisance.setup_particle(IMP.Particle(self.m), 80.0)
     nuisance.set_lower(lower)
     nuisance.set_upper(upper)
     for si in range(1, 100):
         nuisance.set_nuisance(si)
         if si < 10:
             est = 10
         elif si > 80:
             est = 80
         else:
             est = si
         self.assertAlmostEqual(nuisance.get_nuisance(), est, delta=1e-6)
コード例 #12
0
ファイル: test_NuisanceScoreState.py プロジェクト: sirusb/imp
 def unprotected_evaluate(self, accum):
     e = 0
     self.values = [
         p.get_value(Nuisance.get_nuisance_key())
         for p in self.get_model().get_particles()
     ]
     return e
コード例 #13
0
ファイル: test_NuisanceScoreState.py プロジェクト: sirusb/imp
 def test_nuisance_get_has_lower(self):
     p = IMP.kernel.Particle(self.m)
     n = Nuisance.setup_particle(p, 1.0)
     self.assertFalse(n.get_has_lower())
     n.set_lower(0.5)
     self.assertTrue(n.get_has_lower())
     n.remove_lower()
     self.assertFalse(n.get_has_lower())
コード例 #14
0
 def test_Setup2(self):
     "Test nuisance parameter setup with lower/upper"
     si = Nuisance.setup_particle(IMP.Particle(self.m), 2.0)
     si.set_lower(0.1)
     si.set_upper(10)
     self.assertAlmostEqual(float(si.get_nuisance()), 2.0, delta=1e-6)
     self.assertAlmostEqual(float(si.get_lower()), 0.1, delta=1e-6)
     self.assertAlmostEqual(float(si.get_upper()), 10.0, delta=1e-6)
コード例 #15
0
 def test_nuisance_get_has_lower(self):
     p=IMP.kernel.Particle(self.m)
     n=Nuisance.setup_particle(p,1.0)
     self.assertFalse(n.get_has_lower())
     n.set_lower(0.5)
     self.assertTrue(n.get_has_lower())
     n.remove_lower()
     self.assertFalse(n.get_has_lower())
コード例 #16
0
ファイル: test_Nuisance.py プロジェクト: apolitis/imp
 def test_Setup2(self):
     "Test nuisance parameter setup with lower/upper"
     si = Nuisance.setup_particle(IMP.kernel.Particle(self.m), 2.0)
     si.set_lower(0.1)
     si.set_upper(10)
     self.assertAlmostEqual(float(si.get_nuisance()),2.0, delta=1e-6)
     self.assertAlmostEqual(float(si.get_lower()),0.1, delta=1e-6)
     self.assertAlmostEqual(float(si.get_upper()),10.0, delta=1e-6)
コード例 #17
0
 def testdsigma(self):
     "Test LognormalRestraint(3) sigma derivative"
     gr = LognormalRestraint(*self.all)
     for i in range(100):
         map(self.change_value, self.all)
         gr.evaluate(True)
         self.assertAlmostEqual(
             Nuisance(self.sigma).get_nuisance_derivative(),
             self.deriv_sigma(*self.all))
コード例 #18
0
 def testdmu(self):
     "Test GaussianRestraint(3) mu derivative"
     gr = GaussianRestraint(*self.all)
     for i in range(100):
         map(self.change_value, self.all)
         map(self.change_sign, self.locations)
         gr.evaluate(True)
         self.assertAlmostEqual(
             Nuisance(self.mu).get_nuisance_derivative(),
             self.deriv_mu(*self.all))
コード例 #19
0
 def testdmu(self):
     "Test LognormalRestraint(3) mu derivative"
     gr = LognormalRestraint(*self.all)
     self.m.add_restraint(gr)
     for i in range(100):
         map(self.change_value, self.all)
         self.m.evaluate(True)
         self.assertAlmostEqual(
             Nuisance(self.mu).get_nuisance_derivative(),
             self.deriv_mu(*self.all))
コード例 #20
0
 def testdx(self):
     "Test GaussianRestraint(3) x derivative"
     gr = GaussianRestraint(*self.all)
     self.m.add_restraint(gr)
     for i in xrange(100):
         map(self.change_value, self.all)
         map(self.change_sign, self.locations)
         self.m.evaluate(True)
         self.assertAlmostEqual(
             Nuisance(self.x).get_nuisance_derivative(),
             self.deriv_x(*self.all))
コード例 #21
0
 def test_NormalMover_MC_ok(self):
     "Test nuisance scorestate with MonteCarlo mover"
     nuis = Nuisance.setup_particle(IMP.kernel.Particle(self.m), 50.0)
     lower = Nuisance.setup_particle(IMP.kernel.Particle(self.m), 10.0)
     upper = Nuisance.setup_particle(IMP.kernel.Particle(self.m), 90.0)
     nuis.set_nuisance_is_optimized(True)
     nuis.set_lower(1.0)
     nuis.set_lower(lower)
     nuis.set_upper(upper)
     nuis.set_upper(80.0)
     nmv = IMP.core.NormalMover([nuis],
                                IMP.FloatKeys([IMP.FloatKey("nuisance")]), 10.0)
     mc = IMP.core.MonteCarlo(self.m)
     mc.set_return_best(False)
     mc.set_kt(1.0)
     mc.add_mover(nmv)
     for i in range(100):
         mc.optimize(10)
         self.assertTrue(nuis.get_nuisance() >= nuis.get_lower()
                         and nuis.get_nuisance() <= nuis.get_upper())
コード例 #22
0
 def test_NormalMover_MC_fails(self):
     "Test nuisance scorestate with MonteCarlo mover"
     nuis = Nuisance.setup_particle(IMP.Particle(self.m), 50.0)
     lower = Nuisance.setup_particle(IMP.Particle(self.m), 10.0)
     upper = Nuisance.setup_particle(IMP.Particle(self.m), 90.0)
     nuis.set_lower(1.0)
     nuis.set_lower(lower)
     nuis.set_upper(upper)
     nuis.set_upper(80.0)
     nuis.set_nuisance_is_optimized(True)
     nmv = IMP.core.NormalMover([nuis],
                                IMP.FloatKeys([IMP.FloatKey("nuisance")]), 10.0)
     mc = IMP.core.MonteCarlo(self.m)
     mc.set_return_best(False)
     mc.set_kt(1.0)
     mc.add_mover(nmv)
     for i in range(100):
         mc.optimize(10)
         self.assertTrue(nuis.get_nuisance() >= nuis.get_lower()
                         and nuis.get_nuisance() <= nuis.get_upper())
コード例 #23
0
 def test_GetSet2(self):
     "tests get and set (border check)"
     nuisance = Nuisance.setup_particle(IMP.Particle(self.m), 50.0)
     nuisance.set_lower(10)
     nuisance.set_upper(80)
     for si in range(1,100):
         nuisance.set_nuisance(si)
         if si < 10:
             est = 10
         elif si > 80:
             est = 80
         else:
             est = si
         self.assertAlmostEqual(nuisance.get_nuisance(), est, delta=1e-6)
コード例 #24
0
 def test_GetSet2(self):
     "Test nuisance get and set (border check)"
     nuisance = Nuisance.setup_particle(IMP.kernel.Particle(self.m), 50.0)
     nuisance.set_lower(10)
     nuisance.set_upper(80)
     for si in range(1, 100):
         nuisance.set_nuisance(si)
         if si < 10:
             est = 10
         elif si > 80:
             est = 80
         else:
             est = si
         self.assertAlmostEqual(nuisance.get_nuisance(), est, delta=1e-6)
コード例 #25
0
 def test_nuisance_down(self):
     n = IMP.Particle(self.m)
     Nuisance.setup_particle(n, 1.0)
     Nuisance(n).set_lower(0.5)
     Nuisance(n).set_upper(1.5)
     n.set_value(Nuisance.get_nuisance_key(), 0.1)
     self.rs.evaluate(False)
     self.assertAlmostEqual(n.get_value(Nuisance.get_nuisance_key()),
                            0.5, delta=1e-7)
     self.assertAlmostEqual(self.rs.values[0], 0.5)
コード例 #26
0
 def setUp(self):
     IMP.test.TestCase.setUp(self)
     # IMP.set_log_level(IMP.MEMORY)
     IMP.set_log_level(0)
     self.m = IMP.Model()
     self.sigma = Nuisance.setup_particle(IMP.Particle(self.m), 1.0)
コード例 #27
0
 def unprotected_evaluate(self, accum):
     e=0
     self.values = [ p.get_value(Nuisance.get_nuisance_key())
             for p in self.get_model().get_particles()]
     return e
コード例 #28
0
ファイル: test_Scale.py プロジェクト: drussel/imp
 def test_Nuisance(self):
     "Test that a Nuisance can be converted to a Scale"
     n=Nuisance.setup_particle(IMP.Particle(self.m),3.0)
     n.set_lower(0)
     self.assertTrue(Scale.particle_is_instance(n.get_particle()))
コード例 #29
0
 def unprotected_evaluate(self, accum):
     m = self.get_model()
     e = 0
     self.values = [m.get_attribute(Nuisance.get_nuisance_key(), p)
                    for p in m.get_particle_indexes()]
     return e
コード例 #30
0
 def get_value(self, p):
     try:
         v = Nuisance(p).get_nuisance()
     except:
         v = p
     return v
コード例 #31
0
ファイル: test_Nuisance.py プロジェクト: AljGaber/imp
 def setUp(self):
     IMP.test.TestCase.setUp(self)
     # IMP.set_log_level(IMP.MEMORY)
     IMP.set_log_level(0)
     self.m = IMP.Model()
     self.sigma = Nuisance.setup_particle(IMP.Particle(self.m), 1.0)
コード例 #32
0
 def test_Nuisance(self):
     "Test that a Nuisance can be converted to a Switching"
     n = Nuisance.setup_particle(IMP.Particle(self.m), 0.5)
     n.set_lower(0)
     n.set_upper(1)
     self.assertTrue(Switching.get_is_setup(n.get_particle()))
コード例 #33
0
 def test_Setup1(self):
     si = Nuisance.setup_particle(IMP.Particle(self.m))
     self.assertAlmostEqual(float(si.get_nuisance()),1.0, delta=1e-6)
     self.assertTrue(math.isinf(-si.get_lower()))
     self.assertTrue(math.isinf(si.get_upper()))
コード例 #34
0
ファイル: test_Nuisance.py プロジェクト: AljGaber/imp
 def test_Setup1(self):
     "Test nuisance parameter setup without lower/upper"
     si = Nuisance.setup_particle(IMP.Particle(self.m))
     self.assertAlmostEqual(float(si.get_nuisance()), 1.0, delta=1e-6)
     self.assertEqual(si.get_lower(), -1e3000)  # -1e3000 ~= -inf
     self.assertEqual(si.get_upper(), 1e3000)  # 1e3000 ~= inf
コード例 #35
0
 def test_Nuisance(self):
     "test that a Nuisance can be converted to a Switching"
     n=Nuisance.setup_particle(IMP.Particle(self.m),0.5)
     n.set_lower(0)
     n.set_upper(1)
     self.assertTrue(Switching.particle_is_instance(n.get_particle()))
コード例 #36
0
 def change_value(self, p, min=0.1, max=100):
     try:
         n = Nuisance(p)
     except:
         return
     n.set_nuisance(random.uniform(min, max))
コード例 #37
0
 def change_sign(self, p):
     try:
         n = Nuisance(p)
     except:
         return
     n.set_nuisance(n.get_nuisance() * (2 * random.randint(2) - 1))
コード例 #38
0
ファイル: test_Scale.py プロジェクト: sirusb/imp
 def test_Nuisance(self):
     "Test that a Nuisance can be converted to a Scale"
     n = Nuisance.setup_particle(IMP.kernel.Particle(self.m), 3.0)
     n.set_lower(0)
     self.assertTrue(Scale.get_is_setup(n.get_particle()))
コード例 #39
0
 def test_Setup1(self):
     "Test nuisance parameter setup without lower/upper"
     si = Nuisance.setup_particle(IMP.Particle(self.m))
     self.assertAlmostEqual(float(si.get_nuisance()), 1.0, delta=1e-6)
     self.assertEqual(si.get_lower(), -1e3000)  # -1e3000 ~= -inf
     self.assertEqual(si.get_upper(), 1e3000)  # 1e3000 ~= inf
コード例 #40
0
 def change_value(self, p, min=0.1, max=100):
     try:
         n = Nuisance(p)
     except:
         return
     n.set_nuisance(random.uniform(min,max))
コード例 #41
0
 def change_sign(self, p):
     try:
         n = Nuisance(p)
     except:
         return
     n.set_nuisance(n.get_nuisance() * (2 * random.randint(2) - 1))