已实现的PyBrain是开源的,我的源代码位于我的Python目录中。我打开了C:\ Python27 \ Lib \ site-packages \ pybrain \ tools \ shortcuts.py文件。在这个文件里我找到了buildNetwork函数,看看它是如何添加BiasUnit的。相关的代码是在这里:
...
n = Network()
# linear input layer
n.addInputModule(LinearLayer(layers[0], name='in'))
# output layer of type 'outclass'
n.addOutputModule(opt['outclass'](layers[-1], name='out'))
if opt['bias']:
# add bias module and connection to out module, if desired
n.addModule(BiasUnit(name='bias'))
if opt['outputbias']:
n.addConnection(FullConnection(n['bias'], n['out']))
# arbitrary number of hidden layers of type 'hiddenclass'
for i, num in enumerate(layers[1:-1]):
layername = 'hidden%i' % i
n.addModule(opt['hiddenclass'](num, name=layername))
if opt['bias']:
# also connect all the layers with the bias
n.addConnection(FullConnection(n['bias'], n[layername]))
# connections between hidden layers
...
基本上看起来它创建单个BiasUnit并将其连接到每个隐藏层和任选到输出层为好。
尽管我爱蟒蛇,但我已经转向使用基于C的[fanntool](http://code.google.com/p/fanntool/),它将PyBrain从性能。 – User 2012-12-20 16:05:34