示例#1
0
def buildMinimalLSTMNetwork():
    N = RecurrentNetwork('simpleLstmNet')
    i = LinearLayer(4, name='i')
    h = LSTMLayer(1, peepholes=True, name='lstm')
    o = LinearLayer(1, name='o')
    N.addInputModule(i)
    N.addModule(h)
    N.addOutputModule(o)
    N.addConnection(IdentityConnection(i, h))
    N.addConnection(IdentityConnection(h, o))
    N.sortModules()
    return N
示例#2
0
def buildMinimalMDLSTMNetwork():
    N = RecurrentNetwork('simpleMdLstmNet')
    i = LinearLayer(4, name='i')
    h = MDLSTMLayer(1, peepholes=True, name='mdlstm')
    o = LinearLayer(1, name='o')
    N.addInputModule(i)
    N.addModule(h)
    N.addOutputModule(o)
    N.addConnection(IdentityConnection(i, h, outSliceTo=4))
    N.addRecurrentConnection(
        IdentityConnection(h, h, outSliceFrom=4, inSliceFrom=1))
    N.addConnection(IdentityConnection(h, o, inSliceTo=1))
    N.sortModules()
    return N
示例#3
0
def buildNonGravityNet(recurrent = False):
    if recurrent:
        net = RecurrentNetwork()
    else:
        net = FeedForwardNetwork()
    l1 = LinearLayer(2)
    l2 = LinearLayer(3)
    s1 = SigmoidLayer(2)
    l3 = LinearLayer(1)
    net.addInputModule(l1)
    net.addModule(l2)
    net.addModule(s1)
    net.addOutputModule(l3)
    net.addConnection(IdentityConnection(l1, l2, outSliceFrom = 1))
    net.addConnection(IdentityConnection(l1, l2, outSliceTo = 2))
    net.addConnection(IdentityConnection(l2, l3, inSliceFrom = 2))
    net.addConnection(IdentityConnection(l2, l3, inSliceTo = 1))
    net.addConnection(IdentityConnection(l1, s1))
    net.addConnection(IdentityConnection(l2, s1, inSliceFrom = 1))
    net.addConnection(IdentityConnection(s1, l3, inSliceFrom = 1))
    if recurrent:
        net.addRecurrentConnection(IdentityConnection(s1, l1))
        net.addRecurrentConnection(IdentityConnection(l2, l2, inSliceFrom = 1, outSliceTo = 2))
    net.sortModules()
    return net
#!/usr/bin/python

from pybrain3.structure import TanhLayer

from pybrain3.structure import FeedForwardNetwork, LinearLayer, SigmoidLayer, FullConnection, RecurrentNetwork
from pybrain3.structure.modules.biasunit import BiasUnit

# network = FeedForwardNetwork()
network = RecurrentNetwork()

inLayer = LinearLayer(35)
# hiddenLayer = SigmoidLayer(5)
hiddenLayer = TanhLayer(5)
outLayer = LinearLayer(1)
bias = BiasUnit()

network.addInputModule(inLayer)
network.addModule(bias)
network.addModule(hiddenLayer)
network.addOutputModule(outLayer)

in_to_hidden = FullConnection(inLayer, hiddenLayer)
bias_to_hidden = FullConnection(bias, hiddenLayer)
hidden_to_out = FullConnection(hiddenLayer, outLayer)

network.addConnection(in_to_hidden)
network.addConnection(bias_to_hidden)
network.addConnection(hidden_to_out)

network.sortModules()
示例#5
0
def buildMixedNestedNetwork():
    """ build a nested network with the inner one being a ffn and the outer one being recurrent. """
    N = RecurrentNetwork('outer')
    a = LinearLayer(1, name='a')
    b = LinearLayer(2, name='b')
    c = buildNetwork(2, 3, 1)
    c.name = 'inner'
    N.addInputModule(a)
    N.addModule(c)
    N.addOutputModule(b)
    N.addConnection(FullConnection(a, b))
    N.addConnection(FullConnection(b, c))
    N.addRecurrentConnection(FullConnection(c, c))
    N.sortModules()
    return N