python - How to build a neural network with pybrain? -
i new pybrain , having lot of problem in building neural network. documentation not clear me , did not find lot of examples in web.
i neural network 1 input, 1 hidden layer, 1 output.
x--->f1(x),f2(x),...,b---->g(z)
it should simple example. hidden layer has different function , bias unit. example can consider f1=f2=sigmoid
, g
custom function.
this have done far not sure @ doing right.
and have no idea of how add bias unit on hidden layer.
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 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()
you add biasunit hidden layer.
hbiaslayer=biasunit() net.addmodule(hbiaslayer)
Comments
Post a Comment