Pybrain 导出网络

Pybrain exporting a network

看到 this answer 后,我在导出网络时遇到了一些问题。这里是网络生成代码:

net = buildNetwork(2, 1, 1, bias=False)
sol = net.activate([2,3])
print("solution", sol)

for mod in net.modules:
    for conn in net.connections[mod]:
        print("connection:",conn)
        for cc in range(len(conn.params)):
            print(conn.whichBuffers(cc), conn.params[cc])

输出:

solution [ 0.12654066]
connection: <FullConnection 'FullConnection-3': 'hidden0' -> 'out'>
(0, 0) 1.02869832075
connection: <FullConnection 'FullConnection-4': 'in' -> 'hidden0'>
(0, 0) 0.410307885215
(1, 0) -0.928280457049

踢出来的解不应该等于

(0.410307885215*2-0.928280457049*3)*1.02869832075

这是 -2.0206,而不是 0.12654066

好吧,我忘了激活函数。默认激活函数是 sigmoid 函数,在 python 中你可以用

轻松实现
from scipy.special import expit
expit((0.410307885215*2-0.928280457049*3))*1.02869832075 = 0.1265406616438563

我的下一个问题是如何添加偏差。在 运行 sigmoid 函数之前添加偏差。所以如果你正在做:

net = buildNetwork(2, 1, 1, bias=True)

然后它基本上构建:

expit(weight_in1*input1+weight_in2*input2+hidden_bias)*hidden_weight+bias_out

希望这对和我有同样问题的人有意义。