本文整理汇总了Python中neat.DefaultStagnation方法的典型用法代码示例。如果您正苦于以下问题:Python neat.DefaultStagnation方法的具体用法?Python neat.DefaultStagnation怎么用?Python neat.DefaultStagnation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类neat
的用法示例。
在下文中一共展示了neat.DefaultStagnation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_valid_fitness_criterion
# 需要导入模块: import neat [as 别名]
# 或者: from neat import DefaultStagnation [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 DefaultStagnation [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 DefaultStagnation [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 DefaultStagnation [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 DefaultStagnation [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_bad_configA
# 需要导入模块: import neat [as 别名]
# 或者: from neat import DefaultStagnation [as 别名]
def test_serial_bad_configA():
"""Test if bad_configurationA causes a RuntimeError on trying to create the population."""
# Load configuration.
local_dir = os.path.dirname(__file__)
config_path = os.path.join(local_dir, 'bad_configurationA')
config = neat.Config(neat.DefaultGenome, neat.DefaultReproduction,
neat.DefaultSpeciesSet, neat.DefaultStagnation,
config_path)
try:
# Create the population, which is the top-level object for a NEAT run.
p = neat.Population(config)
except RuntimeError:
pass
else:
raise Exception(
"Should have had a RuntimeError with bad_configurationA")
示例7: test_parallel
# 需要导入模块: import neat [as 别名]
# 或者: from neat import DefaultStagnation [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 DefaultStagnation [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 DefaultStagnation [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_nn_recurrent_bad
# 需要导入模块: import neat [as 别名]
# 或者: from neat import DefaultStagnation [as 别名]
def test_run_nn_recurrent_bad():
"""Make sure nn.recurrent 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_nn_recurrent_bad, 19)
except Exception: # again, may change to more specific in nn.recurrent
pass
else:
raise Exception("Did not get Exception for bad input to nn.recurrent")
示例11: test_run_ctrnn_bad
# 需要导入模块: import neat [as 别名]
# 或者: from neat import DefaultStagnation [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")
示例12: test_run_iznn_bad
# 需要导入模块: import neat [as 别名]
# 或者: from neat import DefaultStagnation [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")
示例13: test_config_save_error
# 需要导入模块: import neat [as 别名]
# 或者: from neat import DefaultStagnation [as 别名]
def test_config_save_error(self):
"""Check if get error on saving bad partial configuration"""
config_filename_initial = 'test_configuration2'
config_filename_save = 'save_bad_configuration'
# Get config path
local_dir = os.path.dirname(__file__)
config_path_initial = os.path.join(local_dir, config_filename_initial)
config_path_save = os.path.join(local_dir, config_filename_save)
# Load initial configuration from file
config_initial = neat.Config(neat.DefaultGenome, neat.DefaultReproduction,
neat.DefaultSpeciesSet, neat.DefaultStagnation,
config_path_initial)
config_initial.genome_config.connection_fraction = 1.5
try:
config_initial.save(config_path_save)
except RuntimeError:
pass
else:
raise Exception("Did not get RuntimeError on attempt to save bad partial configuration")
示例14: _run
# 需要导入模块: import neat [as 别名]
# 或者: from neat import DefaultStagnation [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)
示例15: _run
# 需要导入模块: import neat [as 别名]
# 或者: from neat import DefaultStagnation [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)