Esempio n. 1
0
 def testQuickReplicator2(self):
     """Population should not change when fitnesses are equal"""
     f = [1.0]*10
     for i in xrange(50):
         p = Dynamics.RandomDistribution(10)        
         r = Dynamics._QuickReplicator(p, f)
         self.failIf(not AlmostEqual(p, r))
Esempio n. 2
0
 def testReplicator4(self):
     """Little noise should only matter a little"""
     for i in xrange(50):
         p = Dynamics.RandomDistribution(100)
         f = array([random.random() for k in xrange(100)])
         r = Dynamics._QuickReplicator(p, f)
         r2 = Dynamics._Replicator(p, f, 0.01)
         self.failUnless(AlmostEqual(r, r2, 0.0101))
Esempio n. 3
0
 def testReplicator3(self):
     """Noise should matter"""
     for i in xrange(50):
         p = Dynamics.RandomDistribution(100)
         f = array([random.random() for k in xrange(100)])
         r = Dynamics._QuickReplicator(p, f)
         r2 = Dynamics._Replicator(p, f, 0.5)
         self.failIf(AlmostEqual(r, r2))            
Esempio n. 4
0
 def testReplicator2(self):
     """Replicator should yield the same results as QR if noise = 0.0"""
     for i in xrange(50):
         p = Dynamics.RandomDistribution(20)
         f = array([random.random() for k in xrange(20)])
         r = Dynamics._QuickReplicator(p, f)
         r2 = Dynamics._Replicator(p, f, 0.0)
         self.failUnless(AlmostEqual(r, r2))
Esempio n. 5
0
 def testQuickReplicator3(self):
     """Different fitness values ought to have an impact"""
     p = Dynamics.UniformDistribution(10)
     f = array([1.0, 0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1])
     for i in xrange(5):
         r = Dynamics._QuickReplicator(p, f)
         for k in range(len(r)-1):
             self.failIf(r[k+1]>=r[k])
         p = r
Esempio n. 6
0
 def testQuickReplicator1(self):
     """Results of QuickReplicator should be sound"""
     for i in xrange(50):
         p = Dynamics.RandomDistribution(50)
         f = array([random.random() for k in xrange(50)])
         r = Dynamics._QuickReplicator(p, f)
         for x in r:
             self.failIf(x < 0.0 or x > 1.0)
         self.failUnless(AlmostEqual(sum(r), 1.0))
Esempio n. 7
0
 def testQuickReplicator4(self):
     """Extinct species should stay extinct."""
     for i in xrange(50):
         f = array([random.uniform(0.5, 1.5) for k in xrange(10)])
         x = random.randint(1, 9)
         p = Dynamics.UniformDistribution(x, 0.5)
         p = concatenate((p, array([0.0] * (10-x))))
         idx = [l for l in range(10) if p[l] == 0.0]
         r = Dynamics._QuickReplicator(p, f)
         for l in idx:
             self.failIf(r[l] != 0.0)