当前位置: 首页>>代码示例>>Python>>正文


Python Population.advance_generation方法代码示例

本文整理汇总了Python中population.Population.advance_generation方法的典型用法代码示例。如果您正苦于以下问题:Python Population.advance_generation方法的具体用法?Python Population.advance_generation怎么用?Python Population.advance_generation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在population.Population的用法示例。


在下文中一共展示了Population.advance_generation方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_advance

# 需要导入模块: from population import Population [as 别名]
# 或者: from population.Population import advance_generation [as 别名]
    def test_advance(self):
        big_pop = Population(
            [MockOrganism(1), MockOrganism(2),
                MockOrganism(90)], 3)

        big_pop.advance_generation()
        self.assertLessEqual(len(big_pop), 3)
开发者ID:jaredc-s,项目名称:structure_and_landscapes,代码行数:9,代码来源:test_population.py

示例2: TestPopulationBitstring

# 需要导入模块: from population import Population [as 别名]
# 或者: from population.Population import advance_generation [as 别名]
class TestPopulationBitstring(unittest.TestCase):
    def setUp(self):
        bit0 = Bitstring("0000")
        bit1 = Bitstring("1111")
        col0 = ColicinBit(bit0)
        col1 = ColicinBit(bit1)
        org = Organism([col0], [ImmunityBit(bit0, 2)])
        self.pop = Population([org for _ in range(5)])

    def test_replicate(self):
        self.assertEqual(len(self.pop), 5)
        self.pop.replicate()
        self.assertEqual(len(self.pop), 10)

    def test_remove_self_toxic(self):
        self.assertEqual(len(self.pop), 5)
        self.pop.remove_self_toxic()
        self.assertEqual(len(self.pop), 5)

    def test_cull_by_iterative_colicin(self):
        self.assertEqual(len(self.pop), 5)
        self.pop.cull_by_iterative_colicin()
        self.assertEqual(len(self.pop), 5)

    def test_advance_generation(self):
        self.pop.advance_generation()

    def test_sample_with_replacement(self):
        self.pop.sample_with_replacement()
开发者ID:jaredc-s,项目名称:evolution_of_novel_colicins,代码行数:31,代码来源:test_population.py

示例3: colicin_int_demo

# 需要导入模块: from population import Population [as 别名]
# 或者: from population.Population import advance_generation [as 别名]
def colicin_int_demo():
    org = Organism([Colicin(0)], [Immunity(0, 5)])
    pop = Population(org for _ in range(5))
    for gen in range(1000):
        pop.advance_generation()
        average_id = average_colicin_int(pop)
        if gen % 100 == 0:
            print("{}\t{}".format(gen, average_id))
开发者ID:jaredc-s,项目名称:evolution_of_novel_colicins,代码行数:10,代码来源:main.py

示例4: colicin_bitstring_demo

# 需要导入模块: from population import Population [as 别名]
# 或者: from population.Population import advance_generation [as 别名]
def colicin_bitstring_demo():
    mutate.mutation_rate = 0.05
    bit = Bitstring("0000000000000000000")
    bit2 = Bitstring("1000000000000000000")
    col = ColicinBit(bit)
    imm = ImmunityBit(bit2, 1)
    org = Organism([col], [imm, imm])
    pop = Population(org for _ in range(100))
    for gen in range(101):
        pop.advance_generation()
        if gen % 10 == 0:
            average_dist = average_colicin_bitstring_distance(pop, col)
            print("{}\t{}".format(gen, average_dist))
开发者ID:jaredc-s,项目名称:evolution_of_novel_colicins,代码行数:15,代码来源:main.py

示例5: TestPopulation

# 需要导入模块: from population import Population [as 别名]
# 或者: from population.Population import advance_generation [as 别名]
class TestPopulation(unittest.TestCase):
    def setUp(self):
        self.col = Colicin(0)
        self.imm = Immunity(-5, 5)
        self.org = Organism([self.col], [self.imm])
        self.pop = Population([self.org.duplicate() for _ in range(10)])

    def test_len(self):
        self.assertEqual(len(self.pop), 10)

    def test_replicate(self):
        self.pop.replicate()
        self.assertEqual(self.pop.pop.count(self.org), 10)
        self.assertEqual(len(self.pop), 20)

    def test_iter(self):
        for org in self.pop:
            self.assertEqual(org, self.org)
        else:
            return
        self.fail()

    def test_remove_self_toxic(self):
        org_toxic = Organism([Colicin(0)], [Immunity(10, 5)])
        org_not_toxic = Organism([Colicin(0)], [Immunity(0, 5)])
        self.pop.pop = [org_not_toxic, org_toxic]
        self.assertEqual(len(self.pop), 2)

        self.pop.remove_self_toxic()
        self.assertEqual(len(self.pop), 1)
        self.assertSequenceEqual(self.pop.pop, [org_not_toxic])

    def test_cull_by_all_colicins(self):
        org_winner = Organism([Colicin(5)], [Immunity(0, 5)])
        self.pop.pop.append(org_winner)
        self.pop.cull_by_all_colicins()
        self.assertSequenceEqual(self.pop.pop, [org_winner])

    def test_cull_by_all_colicins_extinction(self):
        org_other = Organism([Colicin(5)], [Immunity(10, 5)])
        self.pop.pop.append(org_other)
        self.pop.cull_by_all_colicins()
        self.assertEqual(len(self.pop), 0)

    def test_cull_by_single_colicin(self):
        org_other = Organism([Colicin(100)], [Immunity(100, 5)])
        self.pop.pop.extend(org_other for _ in range(10))
        self.pop.cull_by_single_colicin()
        self.assertEqual(len(self.pop), 10)

    def test_cull_by_single_colicin_extinction(self):
        self.pop.cull_by_single_colicin(Colicin(5))
        self.assertEqual(len(self.pop), 0)

    def test_cull_by_iterative_colicin(self):
        org_winner = Organism([Colicin(5)], [Immunity(0, 5)])
        self.pop.pop.append(org_winner)
        self.pop.cull_by_iterative_colicin()
        self.assertSequenceEqual(self.pop.pop, [org_winner])

    def test_cull_by_iterative_colicin_extinction(self):
        org_other = Organism([Colicin(5)], [Immunity(10, 5)])
        self.pop.pop.extend(org_other for _ in range(10))
        self.pop.cull_by_iterative_colicin()
        self.assertEqual(len(self.pop), 10)

    def test_colicins_produced(self):
        colicins = set(self.pop.colicins_produced())
        self.assertSetEqual({self.col}, colicins)

        other_colicin = Colicin(5)
        self.pop.pop.append(Organism([other_colicin], [Immunity(0, 5)]))
        colicins = set(self.pop.colicins_produced())
        self.assertSetEqual({self.col, other_colicin}, colicins)

    def test_sample_with_replacement(self):
        self.pop.pop.extend(self.org for _ in range(20))
        self.assertEqual(len(self.pop), 30)
        self.pop.sample_with_replacement()
        self.assertEqual(len(self.pop), 10)

        self.pop.pop = self.pop.pop[::2]
        self.assertEqual(len(self.pop), 5)
        self.pop.sample_with_replacement()
        self.assertEqual(len(self.pop), 10)

        self.assertEqual(self.pop.carrying_capacity, 10)

    def test_advance_generation(self):
        self.pop.advance_generation()
        self.assertEqual(len(self.pop), 10)
开发者ID:jaredc-s,项目名称:evolution_of_novel_colicins,代码行数:93,代码来源:test_population.py


注:本文中的population.Population.advance_generation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。