Esempio n. 1
0
    def addHiddenLayer(self, NumberOfNeurons, AddBias=False, AddToStack=True):
        if not self.NetworkCreated:
            new_layer = NeuronLayer(Neurons=NumberOfNeurons, AddBias=AddBias)
            new_layer.connect("layer-created", self.layerCreated)
            new_layer.connect("layer-connected", self.layerConnected)
            new_layer.connect("layer-disconnected", self.layerDisconnected)
            new_layer.createLayer()

            if AddToStack:
                self._TempLayers.append(new_layer)
            else:
                return new_layer
Esempio n. 2
0
 def addHiddenLayer (self, NumberOfNeurons, AddBias=False, AddToStack=True):
     if not self.NetworkCreated:
         new_layer = NeuronLayer (Neurons = NumberOfNeurons, AddBias = AddBias)
         new_layer.connect ("layer-created", self.layerCreated)
         new_layer.connect ("layer-connected", self.layerConnected)
         new_layer.connect ("layer-disconnected", self.layerDisconnected)
         new_layer.createLayer ()
         
         if AddToStack:
             self._TempLayers.append (new_layer)
         else:
             return new_layer
Esempio n. 3
0
"""

"""

# batteries
import sys
sys.path.append("../../src/")
# spiral framework
from spiral.nn import globals
from spiral.nn.generic.layer import NeuronLayer
from spiral.helper import colored

if __name__ == "__main__":
    globals.runInDebug = True

    input_layer = NeuronLayer(Name="Input Layer", Neurons=3)
    input_layer.createLayer()
    first_hidden = NeuronLayer(Name="Hidden Layer #1", Neurons=2, AddBias=True)
    first_hidden.createLayer()
    second_hidden = NeuronLayer(Name="Hidden Layer #2",
                                Neurons=2,
                                AddBias=True)
    second_hidden.createLayer()
    output_layer = NeuronLayer(Name="Output Layer", Neurons=1, AddBias=True)
    output_layer.createLayer()

    print "*" * 100
    input_layer.connectTo(first_hidden)
    print "*" * 50
    first_hidden.connectTo(second_hidden)
    print "*" * 50
Esempio n. 4
0
 def __init__ (self, Neurons, AddBias=False, Name=None):
     NeuronLayer.__init__ (self, Neurons, AddBias=False, Name=Name)
     
     # Remove uneeded member variables
     del self.biasLayer, self.numberOfBiasWeights
Esempio n. 5
0
    def createNet(self):
        """ Create the neurons, the layers and the synapses. """

        if not self.NetworkCreated:
            # Create input layer
            input_layer = NeuronLayer(Neurons=self.NumberOfInputs)
            input_layer.createLayer()

            # Create the hidden layers
            hidden_layers = list()
            for i in range(self.NumberOfLayers):
                hidden_layer = NeuronLayer(
                    Neurons=self.NumberOfNeuronsPerLayer)
                hidden_layer.createLayer()
                hidden_layers.append(hidden_layer)

            # Create the output layer
            output_layer = NeuronLayer(Neurons=self.NumberOfOutputs)
            output_layer.createLayer()

            # Now, we must explicity declare the synapses!
            # We connect all neurons from input layer to the first hidden layer,
            # also we connect the input neuron to the output neuron!
            input_layer.connectTo(hidden_layers[0])
            input_layer.connectTo(output_layer)

            # We connect the neurons of the first hidden layer wih the neurons
            # of the second hidden layer.
            # Also, we connect the second neuron of this layer (the first hidden)
            # to the neuron of the output layer.
            hidden_layers[0].connectTo(hidden_layers[1])
            hidden_layers[0][1].createSynapse(output_layer.Id, output_layer[0])

            # We connect the neurons of the second hidden layer to the output.
            hidden_layers[1].connectTo(output_layer)

            self.addLayers((input_layer, hidden_layers[0], hidden_layers[1],
                            output_layer))

            self.NetworkCreated = True
Esempio n. 6
0
    def __init__(self, Neurons, AddBias=False, Name=None):
        NeuronLayer.__init__(self, Neurons, AddBias=False, Name=Name)

        # Remove uneeded member variables
        del self.biasLayer, self.numberOfBiasWeights
Esempio n. 7
0
 def createNet (self):
     """ Create the neurons, the layers and the synapses. """
     
     if not self.NetworkCreated:
         # Create input layer
         input_layer = NeuronLayer (Neurons = self.NumberOfInputs)
         input_layer.createLayer ()
         
         # Create the hidden layers
         hidden_layers = list ()
         for i in range (self.NumberOfLayers):
             hidden_layer = NeuronLayer (Neurons = self.NumberOfNeuronsPerLayer)
             hidden_layer.createLayer ()
             hidden_layers.append (hidden_layer)
         
         # Create the output layer
         output_layer = NeuronLayer (Neurons = self.NumberOfOutputs)
         output_layer.createLayer ()
         
         # Now, we must explicity declare the synapses!
         # We connect all neurons from input layer to the first hidden layer,
         # also we connect the input neuron to the output neuron! 
         input_layer.connectTo (hidden_layers[0])
         input_layer.connectTo (output_layer)
         
         # We connect the neurons of the first hidden layer wih the neurons
         # of the second hidden layer.
         # Also, we connect the second neuron of this layer (the first hidden)
         # to the neuron of the output layer.
         hidden_layers[0].connectTo (hidden_layers[1])
         hidden_layers[0][1].createSynapse (output_layer.Id, output_layer[0])
         
         # We connect the neurons of the second hidden layer to the output.
         hidden_layers[1].connectTo (output_layer)
         
         
         self.addLayers ( (input_layer, hidden_layers[0], hidden_layers[1], output_layer) )
         
         self.NetworkCreated = True
Esempio n. 8
0

# batteries
import sys
sys.path.append ("../../src/")
# spiral framework
from spiral.nn import globals
from spiral.nn.generic.layer import NeuronLayer
from spiral.helper import colored

 

if __name__ == "__main__":
    globals.runInDebug = True
    
    input_layer  = NeuronLayer (Name="Input Layer"    , Neurons=3)
    input_layer.createLayer ()
    first_hidden = NeuronLayer (Name="Hidden Layer #1", Neurons=2, AddBias=True)
    first_hidden.createLayer ()
    second_hidden= NeuronLayer (Name="Hidden Layer #2", Neurons=2, AddBias=True)
    second_hidden.createLayer ()
    output_layer = NeuronLayer (Name="Output Layer"   , Neurons=1, AddBias=True)
    output_layer.createLayer ()
    
    print "*" * 100
    input_layer.connectTo (first_hidden)
    print "*" * 50
    first_hidden.connectTo (second_hidden)
    print "*" * 50
    second_hidden.connectTo (output_layer)
    print "*" * 50