neural_network¶
neural_network allows you to create simple Neural Networks and to use genetic algorithm.
The code is open source, and available on github.
Usage¶
First you need to include modules:
from neural_network import *
To create a new neural network, you need to instantiate the Net class.
net = Net(2, 3, 2)
net will be a neural network with 3 layers. 2 neurons on its input layer, 3 neurons on its hidden layer and 2 neurons on its outputs layer. You can create as many layer you want.
Documentation¶
neuralNetwork¶
-
class
neural_network.Net(*topology)¶ Net class represent a neural network.
Parameters: topology (*int) –
Integers representing the number of neurons on each layer
Exemple: >>> net = Net(2, 1, 2)
-
feedForward(*inputs)¶ Calculate the outputs
Parameters: inputs (*float) –
neural network’s imputs
Returns: neural network’s outputs
Exemple: >>> net = Net(2, 2) >>> net.feedForward(0.5, 0.2) [0.37993674654431087, -0.4970740393560804]
-
setInputsRange(minValue, maxValue, inputs=None)¶ Allow you to define the inputs range.
Parameters: - minValue (float) – Minimum value for the inputs
- maxValue (float) – Maximum value for the inputs
- inputs (array) – Array of input’s index affected by setInputsRange
Exemple: >>> net = Net(2, 3) >>> net.setInputsRange(0, 100, [0]) # Changing input range just for the first input >>> net.feedForward([0.5, 50]) [-1.0, 0.9999999999997584, 0.9941092385245458]
-
setOutputsRange(minValue, maxValue, outputs=None)¶ Allow you to define the inputs range.
Parameters: - minValue (float) – Minimum value for the outputs
- maxValue (float) – Maximum value for the outputs
- outputs (array) – Array of ouput’s index affected by setOutputsRange
Exemple: >>> net = Net(2, 3) >>> net.setOutputsRange(0, 100) # Changing ouput range for all the outputs >>> net.feedForward([0.5, 0.2]) [39.4994636910904, 50.68911915764991, 59.771121155018555]
-
geneticForNet¶
-
class
neural_network.GeneticNet(nets)¶ Gentic algorithm class
Parameters: nets (array) – Array of neural networks
Exemple: >>> nets = [] >>> for i in range(10): ... nets.append(Net([2, 3, 3])) >>> alg = GeneticNet(nets)
-
setSelection(selectionStr)¶ Set the selection process
Parameters: inputs (string) – name of the selection process (‘rank’ or ‘wheel’)
Exemple: >>> net = Net(2, 2) >>> net.setSelection('rank')
-