问题描述
我是pybrain的新手,在构建神经网络时遇到很多问题。 该文档对我来说不是很清楚,我在网络上找不到很多示例。
我想要一个输入,1个隐藏层,1个输出的神经网络。
x--->f1(x),f2(x),...,b---->g(z)
这应该是一个简单的例子。
隐藏层具有不同的功能和偏置单元。
对于此示例,我们可以考虑f1=f2=sigmoid
, g
是一个自定义函数。
到目前为止,这是我所做的,但是我完全不确定我在做什么。
而且我不知道如何在隐藏层上添加偏置单元。
class gLayer(NeuronLayer):
def _forwardImplementation(self, inbuf, outbuf):
outbuf[:]=g(inbuf)
def _backwardImplementation(self, outerr, inerr, outbuf, inbuf):
inerr[:]=derivative(g,inbuf)*outerr
print "build a network"
#Layer
inLayer=LinearLayer(1)
hLayer=SigmoidLayer(2)
outLayer=gLayer(1)
net=FeedForwardNetwork()
net.addInputModule(inLayer)
net.addModule(hLayer)
net.addOutputModule(outLayer)
#connection
in_to_hidden = FullConnection(inLayer, hLayer)
hidden_to_out = FullConnection(hLayer, outLayer)
net.addConnection(in_to_hidden)
net.addConnection(hidden_to_out)
net.sortModules()
1楼
您可以添加作为另一个隐藏层。
hBiasLayer=BiasUnit()
net.addModule(hBiasLayer)