本文整理汇总了Python中Bio.GA.Organism.function_population方法的典型用法代码示例。如果您正苦于以下问题:Python Organism.function_population方法的具体用法?Python Organism.function_population怎么用?Python Organism.function_population使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bio.GA.Organism
的用法示例。
在下文中一共展示了Organism.function_population方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: find_schemas
# 需要导入模块: from Bio.GA import Organism [as 别名]
# 或者: from Bio.GA.Organism import function_population [as 别名]
def find_schemas(self, fitness, num_schemas):
"""Find the given number of unique schemas using a genetic algorithm
Arguments:
o fitness - A callable object (ie. function) which will evaluate
the fitness of a motif.
o num_schemas - The number of unique schemas with good fitness
that we want to generate.
"""
start_population = \
Organism.function_population(self.motif_generator.random_motif,
self.initial_population,
fitness)
finisher = SimpleFinisher(num_schemas, self.min_generations)
# set up the evolver and do the evolution
evolver = GenerationEvolver(start_population, self.selector)
evolved_pop = evolver.evolve(finisher.is_finished)
# convert the evolved population into a PatternRepository
schema_info = {}
for org in evolved_pop:
# convert the Genome from a MutableSeq to a Seq so that
# the schemas are just strings (and not array("c")s)
seq_genome = org.genome.toseq()
schema_info[str(seq_genome)] = org.fitness
return PatternRepository(schema_info)
示例2: test_function_population
# 需要导入模块: from Bio.GA import Organism [as 别名]
# 或者: from Bio.GA.Organism import function_population [as 别名]
def test_function_population(self):
"""Create a population using a function to generate genomes.
"""
num_orgs = 10
new_pop = Organism.function_population(genome_generator,
num_orgs, fitness_calculator)
self.assertEqual(len(new_pop), num_orgs, "Expected %s organisms, "
"got %s" % (num_orgs, len(new_pop)))
for org in new_pop:
self.assertIsInstance(org, Organism.Organism,
"Expected to get an organism, got %r" % org)
exp_fit = fitness_calculator(org.genome)
self.assertEqual(org.fitness, exp_fit, "Expected fitness of %s, "
"got %s" % (org.fitness, exp_fit))
示例3: test_function_population
# 需要导入模块: from Bio.GA import Organism [as 别名]
# 或者: from Bio.GA.Organism import function_population [as 别名]
def test_function_population(self):
"""Create a population using a function to generate genomes.
"""
num_orgs = 10
new_pop = Organism.function_population(genome_generator,
num_orgs, fitness_calculator)
assert len(new_pop) == num_orgs, "Expected %s organisms, got %s" \
% (num_orgs, len(new_pops))
for org in new_pop:
assert isinstance(org, Organism.Organism), \
"Expected to get an organism, got %r" % org
exp_fit = fitness_calculator(org.genome)
assert org.fitness == exp_fit, \
"Expected fitness of %s, got %s" % (org.fitness, exp_fit)