1

我想用 (1,Nh,1,1) 训练一个神经网络(一个输入,第一个隐藏层中的 Nh 个神经元,第二个隐藏层中的 1 个神经元和 1 个输出)。

在第二个隐藏层中,我想使用自定义函数。

有什么简单的方法可以做到这一点吗?我正在使用pybrain。

谢谢!

4

1 回答 1

1

您将需要使用自定义的 Forward 和 Backward 逻辑来实现从 NeuronLayer 派生的自己的层。就像是:

from pybrain.structure.modules.neuronlayer import NeuronLayer

class CustomLayer(NeuronLayer):
"""Layer implementing the custom function."""

def _forwardImplementation(self, inbuf, outbuf):
    outbuf[:] = custom_func_fwd(inbuf)

def _backwardImplementation(self, outerr, inerr, outbuf, inbuf):
    inerr[:] = custom_func_bkwd(outbuf,outerr)
于 2014-03-09T05:43:02.670 回答