def testLogisticModel(self): lm = population.LogisticModel( 0.05, 100000, population.CarryingCapacity(1000000, [ population.Dimension('Dim1', [lambda x: 0.1 * x, lambda x: -0.05 * x]), population.Dimension('Dim2', [lambda x: 0.2 * x, lambda x: -0.1 * x]) ])) self.assertEqual(int(lm(10000, 0)), 495) self.assertEqual(int(lm(10495, 1)), 519) self.assertEqual(int(lm(11014, 2)), 545)
def testCarryingCapacity(self): cc = population.CarryingCapacity(1000000, [ population.Dimension( 'Dim1', [lambda x: 0.1 * x, lambda x: 0.2 * x, lambda x: -0.05 * x]), population.Dimension( 'Dim2', [lambda x: 0.1 * x, lambda x: 0.3 * x, lambda x: -0.02 * x]) ]) self.assertEqual(cc(0), 1000000) self.assertEqual(cc(1), 1250000) self.assertEqual(cc(2), 1500000)
def runContinuousChange(animate): space = population.Dimension( 'space', [util.PolyChangeFtn(0.2, 100), util.PolyChangeFtn(-0.35, 10)]) water = population.Dimension( 'water', [util.PolyChangeFtn(0.2, 50), util.PolyChangeFtn(-0.25, 20)]) food = population.Dimension( 'food', [util.PolyChangeFtn(0.10, 100), util.PolyChangeFtn(-0.15, 20)]) capacity = population.CarryingCapacity(10000000, [space, water, food]) model = population.LogisticModel(0.02, 4500000, capacity) t, p = population.solve(model, maxTime=250) if animate: population.animate(model, t, p, legend='lower right') else: population.plot(model, t, p)
def runPiecewiseChange(animate): space = population.Dimension('space', [ util.PiecewiseFtn([50, 100], [0.0, 0.10, 0.20]), util.PiecewiseFtn([10, 25, 40], [0.0, -0.15, -0.30, -0.35]) ]) water = population.Dimension('water', [ util.PiecewiseFtn([25, 50], [0.0, 0.10, 0.20]), util.PiecewiseFtn([10, 20, 30], [-0.05, -0.10, -0.20, -0.25]) ]) food = population.Dimension('food', [ util.PiecewiseFtn([70, 100], [0.0, 0.05, 0.10]), util.PiecewiseFtn([20, 30, 40], [0.0, -0.05, -0.10, -0.15]) ]) capacity = population.CarryingCapacity(10000000, [space, water, food]) model = population.LogisticModel(0.02, 4500000, capacity) t, p = population.solve(model, maxTime=250) if animate: population.animate(model, t, p, legend='lower right') else: population.plot(model, t, p)
def testDimension(self): dim = population.Dimension( 'foobar', [lambda x: x + 5, lambda x: 2 * x, lambda x: x]) self.assertEqual(dim(0), 5) self.assertEqual(dim(1), 9) self.assertEqual(dim(5), 25)