Reputation: 605
I am developing a multi Layered neural network for my study. But now I am in a fix where, a user should define the number of hidden layers he wants and the number of neurons in each layer. My inputs are of the matrix (x,8) and my actual output is of the matrix (x,2) where x is the number of rows in my sample data.
I usually define my weights as
Weights1 = 2 * np.random.random((Hidden_layer_len,X[0].shape[0])) - 1
Weights2 = 2 * np.random.random((T[0].shape[0],Hidden_layer_len)) - 1
W = [Weights1, Weights2]
where X is the input, T is the output from the sample datasheet and Hidden_layer_len is the length of the hidden layer, assuming there is one hidden layer between my input and output.
Now, my requirement is that, a user can provide the number of hidden layer he wants between the input and output and the user can also define the number of neurons (hidden_layer_len) of each layer.
assuming that there are n layers, how do i create my weights for the n layers and the number of neurons in each layer?
Upvotes: 1
Views: 1154
Reputation: 897
If you are feeling adventurous and need some computational power using GPU. I'd recommend Keras Deep Learning Library. I also started with PyBrain, but eventually I moved on to more updated libraries like Keras and Theano. Keras is very easy to learn and it is able to reproduce some state of the are results with very few lines of codes. There's a very active community behind Keras developing latest features whereas PyBrain is not under active development now.
Upvotes: 3
Reputation: 360
I would recommend using the Pybrain Module to easily create neural networks. Their documentation can be found here:
http://pybrain.org/docs/tutorial/netmodcon.html
The weight will be initialized randomly in the network creation as you are trying to do, and the amount of hidden neurons and hidden layers can be changed. A simple 2 hidden layer neural network with 10 hidden neurons per layer example:
from pybrain.structure import FeedForwardNetwork
n = FeedForwardNetwork()
from pybrain.structure import LinearLayer, SigmoidLayer
inLayer = LinearLayer(8)
hiddenLayer = SigmoidLayer(10)
hiddenLayer2 = SigmoidLayer(10)
outLayer = LinearLayer(2)
n.addInputModule(inLayer)
n.addModule(hiddenLayer)
n.addModule(hiddenLayer2)
n.addOutputModule(outLayer)
from pybrain.structure import FullConnection
in_to_hidden = FullConnection(inLayer, hiddenLayer1)
hidden_to_hidden = FullConnection(hiddenLayer1, hiddenLayer2)
hidden_to_out = FullConnection(hiddenLayer2, outLayer)
n.addConnection(in_to_hidden)
n.addConnection(hidden_to_hidden)
n.addConnection(hidden_to_out)
n.sortModules()
Upvotes: 3