如何解释 NEAT-Python 的输出

How to interpret NEAT-Python's output

我正在使用 NEAT 算法学习神经网络。为了理解结果,我尝试使用 Excel.

手动重现一些值的计算

运行 NEAT-Python 的异或演示我得到以下结果和对应的图形:

Fitness: 3.93262784315
Nodes:
        0 DefaultNodeGene(key=0, bias=-4.28711170619, response=1.0, activation=sigmoid, aggregation=sum)
        1197 DefaultNodeGene(key=1197, bias=-1.20497802851, response=1.0, activation=sigmoid, aggregation=sum)
Connections:
        DefaultConnectionGene(key=(-2, 0), weight=-1.83815166978, enabled=True)
        DefaultConnectionGene(key=(-2, 1197), weight=1.7368731859, enabled=True)
        DefaultConnectionGene(key=(-1, 0), weight=5.72212927441, enabled=True)
        DefaultConnectionGene(key=(-1, 1197), weight=-1.30171417401, enabled=True)
        DefaultConnectionGene(key=(1197, 0), weight=9.27762332932, enabled=True)

Output:
input (0.0, 0.0), expected output (0.0,), got [5.485892844789737e-10]
input (0.0, 1.0), expected output (1.0,), got [0.9999970321654681]
input (1.0, 0.0), expected output (1.0,), got [0.9992352946960754]
input (1.0, 1.0), expected output (0.0,), got [0.2595603437828634]

Graph of Neural Network

虽然我了解NN的基础知识,但我没有得到命令行的结果: 起初我以 (0, 0):

为例计算节点 1197 的值
-1.3 * 0 +1.7 * 0 -1.2 (bias)
= -1.2
sigmoid(-1.2) = 0.231475... (result of node 1197)

然后最后的结果:

5.7 * 0 +9.3 * 0.231475 (result node 1197) -1.8 * 0 -4.3 (bias)
=-2.147282...
sigmoid(-2.147282) = 0.104585...

这绝对不等于预期的 5.485892844789737e-10。 谁能找出我的计算错误?

给遇到同样情况的大家:我一行一行调试代码,发现sigmoid激活函数定义如下:

def sigmoid_activation(z):
    z = max(-60.0, min(60.0, 5.0 * z))
    return 1.0 / (1.0 + math.exp(-z))

我不完全确定这种“规范化”的目的,但是这个 5 的因素给我造成了困难。注释掉第一行后,一切都按预期进行。