本文整理汇总了Python中neat.StatisticsReporter方法的典型用法代码示例。如果您正苦于以下问题:Python neat.StatisticsReporter方法的具体用法?Python neat.StatisticsReporter怎么用?Python neat.StatisticsReporter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类neat
的用法示例。
在下文中一共展示了neat.StatisticsReporter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_parallel
# 需要导入模块: import neat [as 别名]
# 或者: from neat import StatisticsReporter [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()
示例2: test_threaded_evaluation
# 需要导入模块: import neat [as 别名]
# 或者: from neat import StatisticsReporter [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()
示例3: test_run_nn_recurrent
# 需要导入模块: import neat [as 别名]
# 或者: from neat import StatisticsReporter [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()
示例4: _run
# 需要导入模块: import neat [as 别名]
# 或者: from neat import StatisticsReporter [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)
示例5: _run
# 需要导入模块: import neat [as 别名]
# 或者: from neat import StatisticsReporter [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)
示例6: main
# 需要导入模块: import neat [as 别名]
# 或者: from neat import StatisticsReporter [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)
示例7: run
# 需要导入模块: import neat [as 别名]
# 或者: from neat import StatisticsReporter [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)
示例8: run
# 需要导入模块: import neat [as 别名]
# 或者: from neat import StatisticsReporter [as 别名]
def run():
# 128x128 thumbnails, 1500x1500 rendered images, 1100x810 viewer, grayscale images, 4 worker processes.
pb = PictureBreeder(128, 128, 1500, 1500, 1100, 810, 'gray', 4)
# Determine path to configuration file.
local_dir = os.path.dirname(__file__)
config_path = os.path.join(local_dir, 'interactive_config')
# Note that we provide the custom stagnation class to the Config constructor.
config = neat.Config(neat.DefaultGenome, neat.DefaultReproduction,
neat.DefaultSpeciesSet, InteractiveStagnation,
config_path)
# Make sure the network has the expected number of outputs.
if pb.scheme == 'color':
config.output_nodes = 3
else:
config.output_nodes = 1
config.pop_size = pb.num_cols * pb.num_rows
pop = neat.Population(config)
# Add a stdout reporter to show progress in the terminal.
pop.add_reporter(neat.StdOutReporter(True))
stats = neat.StatisticsReporter()
pop.add_reporter(stats)
while 1:
pb.generation = pop.generation + 1
pop.run(pb.eval_fitness, 1)
示例9: run
# 需要导入模块: import neat [as 别名]
# 或者: from neat import StatisticsReporter [as 别名]
def run():
# Load the config file, which is assumed to live in
# the same directory as this script.
local_dir = os.path.dirname(__file__)
config_path = os.path.join(local_dir, 'config-feedforward')
config = neat.Config(neat.DefaultGenome, neat.DefaultReproduction,
neat.DefaultSpeciesSet, neat.DefaultStagnation,
config_path)
pop = neat.Population(config)
stats = neat.StatisticsReporter()
pop.add_reporter(stats)
pop.add_reporter(neat.StdOutReporter(True))
pe = neat.ParallelEvaluator(multiprocessing.cpu_count(), eval_genome)
winner = pop.run(pe.evaluate)
# Save the winner.
with open('winner-feedforward', 'wb') as f:
pickle.dump(winner, f)
print(winner)
visualize.plot_stats(stats, ylog=True, view=True, filename="feedforward-fitness.svg")
visualize.plot_species(stats, view=True, filename="feedforward-speciation.svg")
node_names = {-1: 'x', -2: 'dx', -3: 'theta', -4: 'dtheta', 0: 'control'}
visualize.draw_net(config, winner, True, node_names=node_names)
visualize.draw_net(config, winner, view=True, node_names=node_names,
filename="winner-feedforward.gv")
visualize.draw_net(config, winner, view=True, node_names=node_names,
filename="winner-feedforward-enabled.gv", show_disabled=False)
visualize.draw_net(config, winner, view=True, node_names=node_names,
filename="winner-feedforward-enabled-pruned.gv", show_disabled=False, prune_unused=True)
示例10: run
# 需要导入模块: import neat [as 别名]
# 或者: from neat import StatisticsReporter [as 别名]
def run():
# Load the config file, which is assumed to live in
# the same directory as this script.
local_dir = os.path.dirname(__file__)
config_path = os.path.join(local_dir, 'config-ctrnn')
config = neat.Config(neat.DefaultGenome, neat.DefaultReproduction,
neat.DefaultSpeciesSet, neat.DefaultStagnation,
config_path)
pop = neat.Population(config)
stats = neat.StatisticsReporter()
pop.add_reporter(stats)
pop.add_reporter(neat.StdOutReporter(True))
pe = neat.ParallelEvaluator(multiprocessing.cpu_count(), eval_genome)
winner = pop.run(pe.evaluate)
# Save the winner.
with open('winner-ctrnn', 'wb') as f:
pickle.dump(winner, f)
print(winner)
visualize.plot_stats(stats, ylog=True, view=True, filename="ctrnn-fitness.svg")
visualize.plot_species(stats, view=True, filename="ctrnn-speciation.svg")
node_names = {-1: 'x', -2: 'dx', -3: 'theta', -4: 'dtheta', 0: 'control'}
visualize.draw_net(config, winner, True, node_names=node_names)
visualize.draw_net(config, winner, view=True, node_names=node_names,
filename="winner-ctrnn.gv")
visualize.draw_net(config, winner, view=True, node_names=node_names,
filename="winner-ctrnn-enabled.gv", show_disabled=False)
visualize.draw_net(config, winner, view=True, node_names=node_names,
filename="winner-ctrnn-enabled-pruned.gv", show_disabled=False, prune_unused=True)
示例11: run
# 需要导入模块: import neat [as 别名]
# 或者: from neat import StatisticsReporter [as 别名]
def run(config_file):
# Load configuration.
config = neat.Config(neat.DefaultGenome, neat.DefaultReproduction,
neat.DefaultSpeciesSet, neat.DefaultStagnation,
config_file)
# 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(5))
# Run for up to 300 generations.
winner = p.run(eval_genomes, 300)
# Display the winning genome.
print('\nBest genome:\n{!s}'.format(winner))
# Show output of the most fit genome against training data.
print('\nOutput:')
winner_net = neat.nn.FeedForwardNetwork.create(winner, config)
for xi, xo in zip(xor_inputs, xor_outputs):
output = winner_net.activate(xi)
print("input {!r}, expected output {!r}, got {!r}".format(xi, xo, output))
node_names = {-1:'A', -2: 'B', 0:'A XOR B'}
visualize.draw_net(config, winner, True, node_names=node_names)
visualize.plot_stats(stats, ylog=False, view=True)
visualize.plot_species(stats, view=True)
p = neat.Checkpointer.restore_checkpoint('neat-checkpoint-4')
p.run(eval_genomes, 10)
示例12: run
# 需要导入模块: import neat [as 别名]
# 或者: from neat import StatisticsReporter [as 别名]
def run(config_file):
# Load configuration.
config = neat.Config(neat.DefaultGenome, neat.DefaultReproduction,
neat.DefaultSpeciesSet, neat.DefaultStagnation,
config_file)
# 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)
# Run for up to 300 generations.
pe = neat.ParallelEvaluator(multiprocessing.cpu_count(), eval_genome)
winner = p.run(pe.evaluate, 300)
# Display the winning genome.
print('\nBest genome:\n{!s}'.format(winner))
# Show output of the most fit genome against training data.
print('\nOutput:')
winner_net = neat.nn.FeedForwardNetwork.create(winner, config)
for xi, xo in zip(xor_inputs, xor_outputs):
output = winner_net.activate(xi)
print("input {!r}, expected output {!r}, got {!r}".format(xi, xo, output))
node_names = {-1:'A', -2: 'B', 0:'A XOR B'}
visualize.draw_net(config, winner, True, node_names = node_names)
visualize.plot_stats(stats, ylog=False, view=True)
visualize.plot_species(stats, view=True)
示例13: run_secondary
# 需要导入模块: import neat [as 别名]
# 或者: from neat import StatisticsReporter [as 别名]
def run_secondary(addr, authkey, num_workers=1):
# Determine path to configuration file. This path manipulation is
# here so that the script will run successfully regardless of the
# current working directory.
local_dir = os.path.dirname(__file__)
config_path = os.path.join(local_dir, 'test_configuration2')
# Load 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)
# Run for the specified number of generations.
de = neat.DistributedEvaluator(
addr,
authkey=authkey,
eval_function=eval_genome_distributed,
mode=MODE_SECONDARY,
num_workers=num_workers,
)
try:
de.start(secondary_wait=3, exit_on_stop=True, reconnect=True)
except SystemExit:
pass
else:
raise Exception("DistributedEvaluator in secondary mode did not try to exit!")
示例14: test_serial
# 需要导入模块: import neat [as 别名]
# 或者: from neat import StatisticsReporter [as 别名]
def test_serial():
"""Test basic (dummy fitness function) non-parallel run."""
# 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.
p.run(eval_dummy_genomes_nn, 19)
stats.save()
# stats.save_genome_fitness(with_cross_validation=True)
assert len(stats.get_fitness_stdev())
stats.best_unique_genomes(5)
stats.best_genomes(5)
stats.best_genome()
p.remove_reporter(stats)
示例15: test_serial_random
# 需要导入模块: import neat [as 别名]
# 或者: from neat import StatisticsReporter [as 别名]
def test_serial_random():
"""Test basic (dummy fitness function) non-parallel run w/random activation, aggregation init."""
# Load configuration.
local_dir = os.path.dirname(__file__)
config_path = os.path.join(local_dir, 'test_configuration2')
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)
# 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(15, 1))
# Run for up to 45 generations.
p.run(eval_dummy_genomes_nn, 45)
stats.save()
# stats.save_genome_fitness(with_cross_validation=True)
stats.get_fitness_stdev()
stats.best_unique_genomes(5)
stats.best_genomes(5)
stats.best_genome()
p.remove_reporter(stats)