Creating custom connectivity in PyBrain neural networks

前端 未结 2 776
终归单人心
终归单人心 2021-01-31 18:12

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

\"layout\"

Ho

2条回答
  •  执笔经年
    2021-01-31 18:43

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

提交回复
热议问题