如何解决Python NEAT中的“No such activate function: 'sum'”错误?

问题描述 投票:0回答:1

我正在使用 NEAT 创建一个简单的游戏 AI。然而,我发现了一个问题,游戏窗口在从第0代过渡到第1代时只会打开和关闭,而实际上它一直重复第0代,所以我要求gpt修改它。当我运行修改后的代码时,我收到以下消息:

eunwoocho@Eunwoos-MacBook-Pro python % /usr/local/bin/python3 "/Users/eunwoocho/Documents/Python/import pygame.py"
pygame 2.5.2 (SDL 2.28.3, Python 3.12.2)
Hello from the pygame community. https://www.pygame.org/contribute.html

****** Running generation 0 ******

Population's average fitness: 4.55500 stdev: 8.71705
Best fitness: 68.00000 - size: (10, 36) - species 69 - id 69
Average adjusted fitness: 0.067
Mean genetic distance 3.545, standard deviation 0.244
Population of 402 members in 200 species:
ID age size fitness adj fit stag
==== === ==== ======= ======= ====
1 0 2 1.0 0.015 0
.....omit....
200 0 2 0.0 0.000 0
Total extinctions: 0
Generation time: 2.484 sec

****** Running generation 1 ******

Traceback (most recent call last):
File "/Users/eunwoocho/Documents/Python/import pygame.py", line 129, in <module>
run(config_path, 50)
File "/Users/eunwoocho/Documents/Python/import pygame.py", line 121, in run
winner = p.run(lambda genomes, config: main(genomes, config, p.generation, target_generations), target_generations)
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/neat/population.py", line 89, in run
fitness_function(list(iteritems(self.population)), self.config)
File "/Users/eunwoocho/Documents/Python/import pygame.py", line 121, in <lambda>
winner = p.run(lambda genomes, config: main(genomes, config, p.generation, target_generations), target_generations)
File "/Users/eunwoocho/Documents/Python/import pygame.py", line 57, in main
net = neat.nn.FeedForwardNetwork.create(g, config)
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/neat/nn/feed_forward.py", line 51, in create
activation_function = config.genome_config.activation_defs.get(ng.activation)
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/neat/activations.py", line 128, in get
raise InvalidActivationFunction("No such activation function: {0!r}".format(name))
neat.activations.InvalidActivationFunction: No such activation function: 'sum'

游戏确实从第 0 代转移到第 1 代,但出现错误消息

"No such activation function: 'sum'"

发生了。但是,我从未在 config-feedfoword 或游戏代码中使用过“sum”,所以我想知道为什么会发生此错误。

这是GPT和config-feedforward.txt文件修改的代码:

https://drive.google.com/drive/folders/1zgzum4HR72b0eOUTvjY7tlB3v8xk0_O5?usp=drive_link

为了解决这个问题,我检查了是否有任何包含 sum 的代码,并按照 GPT 的建议,即activation_default项是问题所在,我将其从activation_default = relu更改为sigmoid,但仍然出现“sum”错误。真正令人沮丧的是我根本没有使用过“总和”这个词。请帮助这个受苦的年轻开发者。

python function error-handling artificial-intelligence neat
1个回答
0
投票

除了 sum 之外,你还可以使用 sigmoid、relu 或其他不同的方法来暴力破解,请查看 NEAT 的官方文档

© www.soinside.com 2019 - 2024. All rights reserved.