meta_warrior
meta_warrior

Reputation: 409

cascade-forward neural network

I understand that we can create a feed forward neural network in pybrain.

example of feed forward neural network

However, can we also create a cascade forward neural network in pybrain?

example of cascade forward neural network

Upvotes: 0

Views: 1572

Answers (1)

kostas
kostas

Reputation: 2019

If i understand correctly you want to connect your input layer to both hidden layer and directly to the output layer.

What if you simply create an additional FullConnection from input layer to output layer?

from pybrain.structure import FeedForwardNetwork
n = FeedForwardNetwork()
from pybrain.structure import LinearLayer, SigmoidLayer
inLayer = LinearLayer(2)
hiddenLayer = SigmoidLayer(3)
outLayer = SigmoidLayer(1)

n.addInputModule(inLayer)
n.addModule(hiddenLayer)
n.addOutputModule(outLayer)

from pybrain.structure import FullConnection
in_to_hidden = FullConnection(inLayer, hiddenLayer)
hidden_to_out = FullConnection(hiddenLayer, outLayer)
in_to_out = FullConnection(inLayer, outLayer)

n.addConnection(in_to_hidden)
n.addConnection(hidden_to_out)
n.addConnection(in_to_out)

n.sortModules()

print n

This seems to be working.

Upvotes: 3

Related Questions