本文整理汇总了Python中neat.DefaultReproduction方法的典型用法代码示例。如果您正苦于以下问题:Python neat.DefaultReproduction方法的具体用法?Python neat.DefaultReproduction怎么用?Python neat.DefaultReproduction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类neat
的用法示例。
在下文中一共展示了neat.DefaultReproduction方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_valid_fitness_criterion
# 需要导入模块: import neat [as 别名]
# 或者: from neat import DefaultReproduction [as 别名]
def test_valid_fitness_criterion(self):
for c in ('max', 'min', 'mean'):
# Load configuration.
local_dir = os.path.dirname(__file__)
config_path = os.path.join(local_dir, 'test_configuration')
config = neat.Config(neat.DefaultGenome, neat.DefaultReproduction,
neat.DefaultSpeciesSet, neat.DefaultStagnation,
config_path)
config.fitness_criterion = c
p = neat.Population(config)
def eval_genomes(genomes, config):
for genome_id, genome in genomes:
genome.fitness = 1.0
p.run(eval_genomes, 10)
示例2: test_bad_config_unknown_option
# 需要导入模块: import neat [as 别名]
# 或者: from neat import DefaultReproduction [as 别名]
def test_bad_config_unknown_option():
"""Check that an unknown option (at least in some sections) raises an exception."""
local_dir = os.path.dirname(__file__)
config_path = os.path.join(local_dir, 'bad_configuration2')
try:
config = neat.Config(neat.DefaultGenome, neat.DefaultReproduction,
neat.DefaultSpeciesSet, neat.DefaultStagnation,
config_path)
except NameError:
pass
else:
raise Exception("Did not get a NameError from an unknown configuration file option (in the 'DefaultSpeciesSet' section)")
config3_path = os.path.join(local_dir, 'bad_configuration3')
try:
config = neat.Config(neat.DefaultGenome, neat.DefaultReproduction,
neat.DefaultSpeciesSet, neat.DefaultStagnation,
config3_path)
except NameError:
pass
else:
raise Exception("Did not get a NameError from an unknown configuration file option (in the 'NEAT' section)")
示例3: test_serial_bad_input
# 需要导入模块: import neat [as 别名]
# 或者: from neat import DefaultReproduction [as 别名]
def test_serial_bad_input():
"""Make sure get error for bad input."""
# Load configuration.
local_dir = os.path.dirname(__file__)
config_path = os.path.join(local_dir, 'test_configuration')
config = neat.Config(neat.DefaultGenome, neat.DefaultReproduction,
neat.DefaultSpeciesSet, neat.DefaultStagnation,
config_path)
# Create the population, which is the top-level object for a NEAT run.
p = neat.Population(config)
try:
p.run(eval_dummy_genomes_nn_bad, 45)
except Exception: # may change in nn.feed_forward code to more specific...
pass
else:
raise Exception("Did not get Exception from bad input")
示例4: test_serial4_bad
# 需要导入模块: import neat [as 别名]
# 或者: from neat import DefaultReproduction [as 别名]
def test_serial4_bad():
"""Make sure no_fitness_termination and n=None give an error."""
# Load configuration.
local_dir = os.path.dirname(__file__)
config_path = os.path.join(local_dir, 'test_configuration4')
config = neat.Config(neat.DefaultGenome, neat.DefaultReproduction,
neat.DefaultSpeciesSet, neat.DefaultStagnation,
config_path)
if VERBOSE:
print("config.genome_config.__dict__: {!r}".format(
config.genome_config.__dict__))
# Create the population, which is the top-level object for a NEAT run.
p = neat.Population(config)
try:
p.run(eval_dummy_genomes_nn, None)
except RuntimeError:
pass
else:
raise Exception(
"Should have had a RuntimeError with n=None and no_fitness_termination")
示例5: test_serial_bad_config
# 需要导入模块: import neat [as 别名]
# 或者: from neat import DefaultReproduction [as 别名]
def test_serial_bad_config():
"""Test if bad_configuration1 causes a LookupError or TypeError on trying to run."""
# Load configuration.
local_dir = os.path.dirname(__file__)
config_path = os.path.join(local_dir, 'bad_configuration1')
config = neat.Config(neat.DefaultGenome, neat.DefaultReproduction,
neat.DefaultSpeciesSet, neat.DefaultStagnation,
config_path)
# Create the population, which is the top-level object for a NEAT run.
p = neat.Population(config)
try:
p.run(eval_dummy_genomes_nn, 19)
except (LookupError, TypeError):
pass
else:
raise Exception(
"Should have had a LookupError/TypeError with bad_configuration1")
示例6: test_serial_extinction_exception
# 需要导入模块: import neat [as 别名]
# 或者: from neat import DefaultReproduction [as 别名]
def test_serial_extinction_exception():
"""Test for complete extinction with exception."""
# Load configuration.
local_dir = os.path.dirname(__file__)
config_path = os.path.join(local_dir, 'test_configuration')
config = neat.Config(neat.DefaultGenome, neat.DefaultReproduction,
neat.DefaultSpeciesSet, neat.DefaultStagnation,
config_path)
config.stagnation_config.max_stagnation = 1
config.stagnation_config.species_elitism = 0
# Create the population, which is the top-level object for a NEAT run.
p = neat.Population(config)
# Add a stdout reporter to show progress in the terminal.
p.add_reporter(neat.StdOutReporter(True))
try:
# Run for up to 45 generations.
p.run(eval_dummy_genomes_nn, 45)
except Exception:
pass
else:
raise Exception("Should have had a complete extinction at some point!")
示例7: test_parallel
# 需要导入模块: import neat [as 别名]
# 或者: from neat import DefaultReproduction [as 别名]
def test_parallel():
"""Test parallel run using ParallelEvaluator (subprocesses)."""
# Load configuration.
local_dir = os.path.dirname(__file__)
config_path = os.path.join(local_dir, 'test_configuration')
config = neat.Config(neat.DefaultGenome, neat.DefaultReproduction,
neat.DefaultSpeciesSet, neat.DefaultStagnation,
config_path)
# Create the population, which is the top-level object for a NEAT run.
p = neat.Population(config)
# Add a stdout reporter to show progress in the terminal.
p.add_reporter(neat.StdOutReporter(VERBOSE))
stats = neat.StatisticsReporter()
p.add_reporter(stats)
p.add_reporter(neat.Checkpointer(1, 5))
# Run for up to 19 generations.
pe = neat.ParallelEvaluator(1 + multiprocessing.cpu_count(), eval_dummy_genome_nn)
p.run(pe.evaluate, 19)
stats.save()
示例8: test_threaded_evaluation
# 需要导入模块: import neat [as 别名]
# 或者: from neat import DefaultReproduction [as 别名]
def test_threaded_evaluation():
"""Tests a neat evolution using neat.threaded.ThreadedEvaluator"""
# Load configuration.
local_dir = os.path.dirname(__file__)
config_path = os.path.join(local_dir, 'test_configuration')
config = neat.Config(neat.DefaultGenome, neat.DefaultReproduction,
neat.DefaultSpeciesSet, neat.DefaultStagnation,
config_path)
# Create the population, which is the top-level object for a NEAT run.
p = neat.Population(config)
# Add a stdout reporter to show progress in the terminal.
p.add_reporter(neat.StdOutReporter(True))
stats = neat.StatisticsReporter()
p.add_reporter(stats)
p.add_reporter(neat.Checkpointer(1, 5))
# Run for up to 19 generations.
pe = neat.ThreadedEvaluator(4, eval_dummy_genome_nn)
p.run(pe.evaluate, 19)
stats.save()
示例9: test_run_nn_recurrent
# 需要导入模块: import neat [as 别名]
# 或者: from neat import DefaultReproduction [as 别名]
def test_run_nn_recurrent():
"""Basic test of nn.recurrent function."""
# Load configuration.
local_dir = os.path.dirname(__file__)
config_path = os.path.join(local_dir, 'test_configuration')
config = neat.Config(neat.DefaultGenome, neat.DefaultReproduction,
neat.DefaultSpeciesSet, neat.DefaultStagnation,
config_path)
config.feed_forward = False
# Create the population, which is the top-level object for a NEAT run.
p = neat.Population(config)
# Add a stdout reporter to show progress in the terminal.
p.add_reporter(neat.StdOutReporter(VERBOSE))
stats = neat.StatisticsReporter()
p.add_reporter(stats)
p.add_reporter(neat.Checkpointer(1, 5))
# Run for up to 19 generations.
p.run(eval_dummy_genomes_nn_recurrent, 19)
stats.save()
示例10: test_run_ctrnn_bad
# 需要导入模块: import neat [as 别名]
# 或者: from neat import DefaultReproduction [as 别名]
def test_run_ctrnn_bad():
"""Make sure ctrnn gives error on bad input."""
# Load configuration.
local_dir = os.path.dirname(__file__)
config_path = os.path.join(local_dir, 'test_configuration')
config = neat.Config(neat.DefaultGenome, neat.DefaultReproduction,
neat.DefaultSpeciesSet, neat.DefaultStagnation,
config_path)
config.feed_forward = False
# Create the population, which is the top-level object for a NEAT run.
p = neat.Population(config)
try:
p.run(eval_dummy_genomes_ctrnn_bad, 19)
except RuntimeError:
pass
else:
raise Exception("Did not get RuntimeError for bad input to ctrnn")
示例11: test_run_iznn_bad
# 需要导入模块: import neat [as 别名]
# 或者: from neat import DefaultReproduction [as 别名]
def test_run_iznn_bad():
"""Make sure iznn gives error on bad input."""
# Load configuration.
local_dir = os.path.dirname(__file__)
config_path = os.path.join(local_dir, 'test_configuration_iznn')
config = neat.Config(neat.iznn.IZGenome, neat.DefaultReproduction,
neat.DefaultSpeciesSet, neat.DefaultStagnation,
config_path)
# Create the population, which is the top-level object for a NEAT run.
p = neat.Population(config)
try:
p.run(eval_dummy_genomes_iznn_bad, 19)
except RuntimeError:
pass
else:
raise Exception("Did not get RuntimeError for bad input to iznn")
示例12: _run
# 需要导入模块: import neat [as 别名]
# 或者: from neat import DefaultReproduction [as 别名]
def _run(self, config_file, n):
config = neat.Config(neat.DefaultGenome, neat.DefaultReproduction,
neat.DefaultSpeciesSet, neat.DefaultStagnation,
config_file)
# p = neat.Population(config)
p = neat.Checkpointer.restore_checkpoint(self.file_name)
p.add_reporter(neat.StdOutReporter(True))
p.add_reporter(neat.Checkpointer(5))
stats = neat.StatisticsReporter()
p.add_reporter(stats)
print("loaded checkpoint...")
winner = p.run(self._eval_genomes, n)
win = p.best_genome
pickle.dump(winner, open('winner.pkl', 'wb'))
pickle.dump(win, open('real_winner.pkl', 'wb'))
visualize.draw_net(config, winner, True)
visualize.plot_stats(stats, ylog=False, view=True)
visualize.plot_species(stats, view=True)
示例13: _run
# 需要导入模块: import neat [as 别名]
# 或者: from neat import DefaultReproduction [as 别名]
def _run(self, config_file, n):
config = neat.Config(neat.DefaultGenome, neat.DefaultReproduction,
neat.DefaultSpeciesSet, neat.DefaultStagnation,
config_file)
p = neat.Population(config)
p.add_reporter(neat.StdOutReporter(True))
p.add_reporter(neat.Checkpointer(5))
stats = neat.StatisticsReporter()
p.add_reporter(stats)
print("loaded checkpoint...")
winner = p.run(self._eval_genomes, n)
win = p.best_genome
pickle.dump(winner, open('winner.pkl', 'wb'))
pickle.dump(win, open('real_winner.pkl', 'wb'))
visualize.draw_net(config, winner, True)
visualize.plot_stats(stats, ylog=False, view=True)
visualize.plot_species(stats, view=True)
示例14: main
# 需要导入模块: import neat [as 别名]
# 或者: from neat import DefaultReproduction [as 别名]
def main():
local_dir = os.path.dirname(__file__)
config = Config(neat.DefaultGenome, neat.DefaultReproduction,
neat.DefaultSpeciesSet, neat.DefaultStagnation,
os.path.join(local_dir, 'train_config.txt'))
config.save_best = True
config.checkpoint_time_interval = 3
pop = population.Population(config)
stats = neat.StatisticsReporter()
pop.add_reporter(stats)
pop.add_reporter(neat.StdOutReporter(True))
pop.add_reporter(neat.StatisticsReporter())
pop.add_reporter(neat.Checkpointer(2))
winner = pop.run(eval_fitness, 100)
with open('winner.pkl', 'wb') as f:
pickle.dump(winner, f)
示例15: run
# 需要导入模块: import neat [as 别名]
# 或者: from neat import DefaultReproduction [as 别名]
def run():
config = neat.Config(neat.DefaultGenome, neat.DefaultReproduction,
neat.DefaultSpeciesSet, neat.DefaultStagnation, CONFIG)
pop = neat.Population(config)
# recode history
stats = neat.StatisticsReporter()
pop.add_reporter(stats)
pop.add_reporter(neat.StdOutReporter(True))
pop.add_reporter(neat.Checkpointer(5))
pop.run(eval_genomes, 10) # train 10 generations
# visualize training
visualize.plot_stats(stats, ylog=False, view=True)
visualize.plot_species(stats, view=True)