如何在整洁的Python中重置最大生成数?

2024-05-14 20:30:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我目前正在开发一款整洁的Python AI,它可以学习玩蛇和飞鸟。我能够找到文档,但我似乎不知道如何更改最大生成值

我当前导入程序的niat.txt配置文件如下所示:

 [NEAT]
fitness_criterion     = max
fitness_threshold     = 10000
pop_size              = 100
reset_on_extinction   = False

[DefaultGenome]
# node activation options
activation_default      = tanh
activation_mutate_rate  = 0.1
activation_options      = tanh

# node aggregation options
aggregation_default     = sum
aggregation_mutate_rate = 0.0
aggregation_options     = sum

# node bias options
bias_init_mean          = 0.0
bias_init_stdev         = 1.0
bias_max_value          = 30.0
bias_min_value          = -30.0
bias_mutate_power       = 0.5
bias_mutate_rate        = 0.7
bias_replace_rate       = 0.1

# genome compatibility options
compatibility_disjoint_coefficient = 1.0
compatibility_weight_coefficient   = 0.5

# connection add/remove rates
conn_add_prob           = 0.5
conn_delete_prob        = 0.5

# connection enable options
enabled_default         = True
enabled_mutate_rate     = 0.01

feed_forward            = True
initial_connection      = full_direct

# node add/remove rates
node_add_prob           = 0.2
node_delete_prob        = 0.2

# network parameters
num_hidden              = 1
num_inputs              = 3
num_outputs             = 1

# node response options
response_init_mean      = 1.0
response_init_stdev     = 0.0
response_max_value      = 30.0
response_min_value      = -30.0
response_mutate_power   = 0.0
response_mutate_rate    = 0.0
response_replace_rate   = 0.0

# connection weight options
weight_init_mean        = 0.0
weight_init_stdev       = 1.0
weight_max_value        = 30
weight_min_value        = -30
weight_mutate_power     = 0.5
weight_mutate_rate      = 0.8
weight_replace_rate     = 0.1

[DefaultSpeciesSet]
compatibility_threshold = 3.0

[DefaultStagnation]
species_fitness_func = max
max_stagnation       = 20
species_elitism      = 2

[DefaultReproduction]
elitism            = 2
survival_threshold = 0.2

是否有任何新的部分,我可以添加到这个现有的代码块,允许我输入的最大生成数


Tags: addnoderateinitvalueresponseconnectionactivation
1条回答
网友
1楼 · 发布于 2024-05-14 20:30:49

根据问题中的有用信息:

我似乎不知道如何更改最大生成值。”

这可以通过定义p objects run函数的max_代来实现

# Run for up to 300 generations.
winner = p.run(eval_genomes, 300)

这在这里的XOR工作示例中进行了概述

https://github.com/CodeReclaimers/neat-python/blob/c2b79c88667a1798bfe33c00dd8e251ef8be41fa/examples/xor/evolve-feedforward.py#L40

如果我们再深入一点https://neat-python.readthedocs.io/en/latest/xor_example.html上显示的示例,我们可以看到一个关于如何定义它的清晰解释

我们设置了一个基本配置(在您提供的配置文件中定义)

# Load configuration.
config = neat.Config(neat.DefaultGenome, neat.DefaultReproduction,
                     neat.DefaultSpeciesSet, neat.DefaultStagnation,
                     config_file)

创建我们的p对象

# 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)

添加检查点。

这将每5代保存一个文件。您将能够在名为“neat-checkpoint-X”的脚本所在的同一目录中找到作为pickle保存的检查点

p.add_reporter(neat.Checkpointer(5))

最终将我们的评估运行300代

# Run for up to 300 generations.
winner = p.run(eval_genomes, 300)

相关问题 更多 >

    热门问题