Ejemplo n.º 1
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
Ejemplo n.º 2
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
Ejemplo n.º 3
0
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

    input_layer.putInputs((1.0, 2.0, 3.0))
    input_layer.putWeights((0.3, 0.4, -0.11, -0.8, -0.25, 0.25))

    first_hidden.putWeights((1.0, 0.8, 0.7, 0.1))
    first_hidden.putBiasWeights((0.5, -0.5))
    first_hidden.biasLayer.putBiasInputs()

    second_hidden.putWeights((0.1, 0.2))
    second_hidden.putBiasWeights((0.5, -0.5))
Ejemplo n.º 4
0
 

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
    
    
    input_layer.putInputs   ( (1.0, 2.0, 3.0) )
    input_layer.putWeights  ( (0.3, 0.4, -0.11, -0.8, -0.25, 0.25) )
    
    first_hidden.putWeights ( (1.0, 0.8, 0.7, 0.1) )
    first_hidden.putBiasWeights ( (0.5, -0.5) )
    first_hidden.biasLayer.putBiasInputs ()
    
    second_hidden.putWeights( (0.1, 0.2) )