【问题标题】:Creating custom connectivity in PyBrain neural networks在 PyBrain 神经网络中创建自定义连接
【发布时间】:2011-08-07 05:59:50
【问题描述】:

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

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

【问题讨论】:

    标签: python neural-network pybrain


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

      这是您的案例的示例代码:

      #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,除了我习惯在教程中使用它,然后深入检查它的代码在教程中的作用。原来这是个好主意? :) 阅读代码,而不是文档 - 无论如何,python 都有文档字符串! :)
      • 嗨,只是好奇。假设我们要创建一个级联前馈神经网络 (mathworks.com/help/nnet/ref/cascadeforwardnet.html),那么我们只需要在任意 2 层之间创建连接?
      猜你喜欢
      • 2018-03-26
      • 1970-01-01
      • 1970-01-01
      • 2012-12-19
      • 2019-01-01
      • 2016-10-19
      • 2016-01-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多