在 PyBrain 神经网络中创建自定义连接

发布于 2024-11-02 07:45:45 字数 195 浏览 3 评论 0原文

我想创建一个遵循以下布局的人工神经网络(在 PyBrain 中):

layout

但是,我找不到正确的实现这一目标的方法。我在文档中看到的唯一选项是创建完全连接层的方式,这不是我想要的:我希望一些输入节点连接到第二个隐藏层而不是第一个隐藏层。

I want to create an artificial neural network (in PyBrain) that follows the following layout:

layout

However, I cannot find the proper way to achieve this. The only option that I see in the documentation is the way to create fully connected layers, which is not what I want: I want some of my input nodes to be connected to the second hidden layer and not to the first one.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

雨巷深深 2024-11-09 07:45:45

解决方案是使用您选择的连接类型,但带有切片参数:inSliceFrominSliceTooutSliceFrom和outSliceTo。我同意文档应该提到这一点,到目前为止它只在 Connection 类的注释中。

以下是您的案例的示例代码:

#create network and modules
net = FeedForwardNetwork()
inp = LinearLayer(9)
h1 = SigmoidLayer(2)
h2 = TanhLayer(2)
outp = LinearLayer(1)
# add modules
net.addOutputModule(outp)
net.addInputModule(inp)
net.addModule(h1)
net.addModule(h2)
# create connections
net.addConnection(FullConnection(inp, h1, inSliceTo=6))
net.addConnection(FullConnection(inp, h2, inSliceFrom=6))
net.addConnection(FullConnection(h1, h2))
net.addConnection(FullConnection(h2, outp))
# finish up
net.sortModules()

The solution is to use the connection type of your choice, but with slicing parameters: inSliceFrom, inSliceTo, outSliceFrom and outSliceTo. I agree the documentation should mention this, so far it's only in the Connection class' comments.

Here is example code for your case:

#create network and modules
net = FeedForwardNetwork()
inp = LinearLayer(9)
h1 = SigmoidLayer(2)
h2 = TanhLayer(2)
outp = LinearLayer(1)
# add modules
net.addOutputModule(outp)
net.addInputModule(inp)
net.addModule(h1)
net.addModule(h2)
# create connections
net.addConnection(FullConnection(inp, h1, inSliceTo=6))
net.addConnection(FullConnection(inp, h2, inSliceFrom=6))
net.addConnection(FullConnection(h1, h2))
net.addConnection(FullConnection(h2, outp))
# finish up
net.sortModules()
花间憩 2024-11-09 07:45:45

schaul 建议的另一种方法是使用多个输入层。

#create network
net = FeedForwardNetwork()

# create and add modules
input_1 = LinearLayer(6)
net.addInputModule(input_1)
input_2 = LinearLayer(3)
net.addInputModule(input_2)
h1 = SigmoidLayer(2)
net.addModule(h1)
h2 = SigmoidLayer(2)
net.addModule(h2)
outp = SigmoidLayer(1)
net.addOutputModule(outp)

# create connections
net.addConnection(FullConnection(input_1, h1))
net.addConnection(FullConnection(input_2, h2))
net.addConnection(FullConnection(h1, h2))
net.addConnection(FullConnection(h2, outp))

net.sortModules()

An alternative way to the one suggested by schaul is to use multiple input layers.

#create network
net = FeedForwardNetwork()

# create and add modules
input_1 = LinearLayer(6)
net.addInputModule(input_1)
input_2 = LinearLayer(3)
net.addInputModule(input_2)
h1 = SigmoidLayer(2)
net.addModule(h1)
h2 = SigmoidLayer(2)
net.addModule(h2)
outp = SigmoidLayer(1)
net.addOutputModule(outp)

# create connections
net.addConnection(FullConnection(input_1, h1))
net.addConnection(FullConnection(input_2, h2))
net.addConnection(FullConnection(h1, h2))
net.addConnection(FullConnection(h2, outp))

net.sortModules()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文