本文整理汇总了Python中neat.DefaultGenome方法的典型用法代码示例。如果您正苦于以下问题:Python neat.DefaultGenome方法的具体用法?Python neat.DefaultGenome怎么用?Python neat.DefaultGenome使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类neat
的用法示例。
在下文中一共展示了neat.DefaultGenome方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_fs_neat_no_hidden
# 需要导入模块: import neat [as 别名]
# 或者: from neat import DefaultGenome [as 别名]
def test_fs_neat_no_hidden(self):
"""
fs_neat with no hidden nodes
(equivalent to fs_neat_hidden and fs_neat_nohidden with no hidden nodes).
"""
gid = 42
config = self.config.genome_config
config.initial_connection = 'fs_neat'
config.num_hidden = 0
g = neat.DefaultGenome(gid)
self.assertEqual(gid, g.key)
g.configure_new(config)
print(g)
self.assertEqual(set(g.nodes), {0})
self.assertEqual(len(g.connections), 1)
示例2: test_fs_neat_hidden_old
# 需要导入模块: import neat [as 别名]
# 或者: from neat import DefaultGenome [as 别名]
def test_fs_neat_hidden_old(self):
"""
fs_neat (without hidden/nohidden specification) with hidden;
should output warning about doc/code conflict.
"""
gid = 42
config = self.config.genome_config
config.initial_connection = 'fs_neat'
config.num_hidden = 2
g = neat.DefaultGenome(gid)
self.assertEqual(gid, g.key)
print("\nThis should output a warning:", file=sys.stderr)
g.configure_new(config) # TODO: Test for emitted warning
print(g)
self.assertEqual(set(g.nodes), {0, 1, 2})
self.assertEqual(len(g.connections), 1)
示例3: test_fully_connected_no_hidden
# 需要导入模块: import neat [as 别名]
# 或者: from neat import DefaultGenome [as 别名]
def test_fully_connected_no_hidden(self):
"""
full with no hidden nodes
(equivalent to full_nodirect and full_direct with no hidden nodes)
"""
gid = 42
config = self.config.genome_config
config.initial_connection = 'full'
config.num_hidden = 0
g = neat.DefaultGenome(gid)
self.assertEqual(gid, g.key)
g.configure_new(config)
print(g)
self.assertEqual(set(g.nodes), {0})
self.assertEqual(len(g.connections), 2)
# Check that each input is connected to the output node
for i in config.input_keys:
assert ((i, 0) in g.connections)
示例4: test_partially_connected_hidden_nodirect_old
# 需要导入模块: import neat [as 别名]
# 或者: from neat import DefaultGenome [as 别名]
def test_partially_connected_hidden_nodirect_old(self):
"""
partial (no specification re direct/nodirect) with hidden nodes;
should output warning re docs/code conflict.
"""
gid = 42
config = self.config2.genome_config
config.initial_connection = 'partial'
config.connection_fraction = 0.5
config.num_hidden = 2
g = neat.DefaultGenome(gid)
self.assertEqual(gid, g.key)
print("\nThis should output a warning:", file=sys.stderr)
g.configure_new(config) # TODO: Test for emitted warning
print(g)
self.assertEqual(set(g.nodes), {0, 1, 2})
self.assertLess(len(g.connections), 6)
示例5: test_partially_connected_hidden_direct
# 需要导入模块: import neat [as 别名]
# 或者: from neat import DefaultGenome [as 别名]
def test_partially_connected_hidden_direct(self):
"""
partial with (potential) direct input-output connections
(and also, potentially, via hidden hodes).
"""
gid = 42
config = self.config.genome_config
config.initial_connection = 'partial_direct'
config.connection_fraction = 0.5
config.num_hidden = 2
g = neat.DefaultGenome(gid)
self.assertEqual(gid, g.key)
g.configure_new(config)
print(g)
self.assertEqual(set(g.nodes), {0, 1, 2})
self.assertLess(len(g.connections), 8)
示例6: main
# 需要导入模块: import neat [as 别名]
# 或者: from neat import DefaultGenome [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: setUp
# 需要导入模块: import neat [as 别名]
# 或者: from neat import DefaultGenome [as 别名]
def setUp(self):
"""
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_configuration')
self.config = neat.Config(neat.DefaultGenome, neat.DefaultReproduction,
neat.DefaultSpeciesSet, neat.DefaultStagnation,
config_path)
config2_path = os.path.join(local_dir, 'test_configuration2')
self.config2 = neat.Config(neat.DefaultGenome, neat.DefaultReproduction,
neat.DefaultSpeciesSet, neat.DefaultStagnation,
config2_path)
示例8: test_unconnected_no_hidden
# 需要导入模块: import neat [as 别名]
# 或者: from neat import DefaultGenome [as 别名]
def test_unconnected_no_hidden(self):
"""Unconnected network with only input and output nodes."""
gid = 42
config = self.config.genome_config
config.initial_connection = 'unconnected'
config.num_hidden = 0
g = neat.DefaultGenome(gid)
self.assertEqual(gid, g.key)
g.configure_new(self.config.genome_config)
print(g)
self.assertEqual(set(g.nodes), {0})
assert (not g.connections)
示例9: test_unconnected_hidden
# 需要导入模块: import neat [as 别名]
# 或者: from neat import DefaultGenome [as 别名]
def test_unconnected_hidden(self):
"""Unconnected network with hidden nodes."""
gid = 42
config = self.config.genome_config
config.initial_connection = 'unconnected'
config.num_hidden = 2
g = neat.DefaultGenome(gid)
self.assertEqual(gid, g.key)
g.configure_new(self.config.genome_config)
print(g)
self.assertEqual(set(g.nodes), {0, 1, 2})
assert (not g.connections)
示例10: test_fs_neat_hidden
# 需要导入模块: import neat [as 别名]
# 或者: from neat import DefaultGenome [as 别名]
def test_fs_neat_hidden(self):
"""fs_neat with connecting hidden nodes."""
gid = 42
config = self.config.genome_config
config.initial_connection = 'fs_neat_hidden'
config.num_hidden = 2
g = neat.DefaultGenome(gid)
self.assertEqual(gid, g.key)
g.configure_new(config)
print(g)
self.assertEqual(set(g.nodes), {0, 1, 2})
self.assertEqual(len(g.connections), 3)
示例11: test_fully_connected_hidden_nodirect_old
# 需要导入模块: import neat [as 别名]
# 或者: from neat import DefaultGenome [as 别名]
def test_fully_connected_hidden_nodirect_old(self):
"""
full (no specification re direct/nodirect) with hidden nodes;
should output warning re docs/code conflict.
"""
gid = 42
config = self.config.genome_config
config.initial_connection = 'full'
config.num_hidden = 2
g = neat.DefaultGenome(gid)
self.assertEqual(gid, g.key)
print("\nThis should output a warning:", file=sys.stderr)
g.configure_new(config) # TODO: Test for emitted warning
print(g)
self.assertEqual(set(g.nodes), {0, 1, 2})
self.assertEqual(len(g.connections), 6)
# Check that each input is connected to each hidden node.
for i in config.input_keys:
for h in (1, 2):
assert ((i, h) in g.connections)
# Check that each hidden node is connected to the output.
for h in (1, 2):
assert ((h, 0) in g.connections)
# Check that inputs are not directly connected to the output
for i in config.input_keys:
assert ((i, 0) not in g.connections)
示例12: test_fully_connected_hidden_nodirect
# 需要导入模块: import neat [as 别名]
# 或者: from neat import DefaultGenome [as 别名]
def test_fully_connected_hidden_nodirect(self):
"""full with no direct input-output connections, only via hidden nodes."""
gid = 42
config = self.config.genome_config
config.initial_connection = 'full_nodirect'
config.num_hidden = 2
g = neat.DefaultGenome(gid)
self.assertEqual(gid, g.key)
g.configure_new(config)
print(g)
self.assertEqual(set(g.nodes), {0, 1, 2})
self.assertEqual(len(g.connections), 6)
# Check that each input is connected to each hidden node.
for i in config.input_keys:
for h in (1, 2):
assert ((i, h) in g.connections)
# Check that each hidden node is connected to the output.
for h in (1, 2):
assert ((h, 0) in g.connections)
# Check that inputs are not directly connected to the output
for i in config.input_keys:
assert ((i, 0) not in g.connections)
示例13: test_fully_connected_hidden_direct
# 需要导入模块: import neat [as 别名]
# 或者: from neat import DefaultGenome [as 别名]
def test_fully_connected_hidden_direct(self):
"""full with direct input-output connections (and also via hidden hodes)."""
gid = 42
config = self.config.genome_config
config.initial_connection = 'full_direct'
config.num_hidden = 2
g = neat.DefaultGenome(gid)
self.assertEqual(gid, g.key)
g.configure_new(config)
print(g)
self.assertEqual(set(g.nodes), {0, 1, 2})
self.assertEqual(len(g.connections), 8)
# Check that each input is connected to each hidden node.
for i in config.input_keys:
for h in (1, 2):
assert ((i, h) in g.connections)
# Check that each hidden node is connected to the output.
for h in (1, 2):
assert ((h, 0) in g.connections)
# Check that inputs are directly connected to the output
for i in config.input_keys:
assert ((i, 0) in g.connections)
示例14: test_partially_connected_hidden_nodirect
# 需要导入模块: import neat [as 别名]
# 或者: from neat import DefaultGenome [as 别名]
def test_partially_connected_hidden_nodirect(self):
"""partial with no direct input-output connections, only via hidden nodes."""
gid = 42
config = self.config.genome_config
config.initial_connection = 'partial_nodirect'
config.connection_fraction = 0.5
config.num_hidden = 2
g = neat.DefaultGenome(gid)
self.assertEqual(gid, g.key)
g.configure_new(config)
print(g)
self.assertEqual(set(g.nodes), {0, 1, 2})
self.assertLess(len(g.connections), 6)
示例15: main
# 需要导入模块: import neat [as 别名]
# 或者: from neat import DefaultGenome [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'))
with open('winner.pkl', 'rb') as f:
winner = pickle.load(f)
print('\nBest genome:\n{!s}'.format(winner))
print('\nOutput:')
winner_net = neat.nn.FeedForwardNetwork.create(winner, config)
print('Score:', dino_api.play_game(GetCommand(winner_net)))