我目前正在为我的课程实施一个程序分类器。 我的讲师让我使用" Evolving ANN"算法。 所以我找到了一个名为NEAT(扩展拓扑的神经演化)的软件包。 我有10个输入和7个输出,然后我只是修改其文档中的源代码。
def eval_fitness(genomes):
for g in genomes:
net = nn.create_feed_forward_phenotype(g)
mse = 0
for inputs, expected in zip(alldata, label):
output = net.serial_activate(inputs)
output = np.clip(output, -1, 1)
mse += (output - expected) ** 2
g.fitness = 1 - (mse/44000) #44000 is the number of samples
print(g.fitness)
我也更改了配置文件,因此该程序有10个输入和7个输出。 但是当我尝试运行代码时,它会给我错误
Traceback (most recent call last):
File "/home/ilhammaziz/PycharmProjects/tuproSC2/eANN.py", line 40, in <module>
pop.run(eval_fitness, 10)
File "/home/ilhammaziz/.local/lib/python3.5/site-packages/neat/population.py", line 190, in run
best = max(population)
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
&#13;
我该怎么办? 感谢