在PyBrain神经网络中创建自定义连接 [英] Creating custom connectivity in PyBrain neural networks

查看:110
本文介绍了在PyBrain神经网络中创建自定义连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to create an artificial neural network (in PyBrain) that follows the following 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.

推荐答案

解决方案是使用您选择的连接类型,但要使用 slicing 参数:inSliceFrominSliceTooutSliceFromoutSliceTo.我同意文档中应该提到这一点,到目前为止,仅在Connection类的注释中.

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()

这篇关于在PyBrain神经网络中创建自定义连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆