Esempio n. 1
0
    def connectTo(self, otherLayer):
        for i in range(otherLayer.getLayerSize()):
            neuron = otherLayer[i]
            BiasNeuron = Neuron(i, self.Id)
            BiasNeuron.createSynapse(otherLayer.Id, neuron)

            self.neurons.append(BiasNeuron)

            self.numberOfWeights += 1

        self.emit("bias-layer-connected")
Esempio n. 2
0
 def createLayer (self):
     if len (self) == 0:
         # Create the neurons
         for i in range (self.numberOfNeurons):
             self.neurons.append ( Neuron (
                     Id = i,
                     LayerId = self.Id,
                 )
             )
             
         # Create the bias layer
         if self.hasBiasLayer:
             self.biasLayer.connect ("bias-layer-connected", self.biasLayerConnected)
             self.biasLayer.connectTo (self)
         
         self.emit ("layer-created")
Esempio n. 3
0
    Notice, that the number of inputs for each neuron is calculated dynamically,
    and changed whenever a new synapse-connection is created.
"""

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

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

    n1 = Neuron(Id=1, LayerId=0)
    n2 = Neuron(Id=2, LayerId=0)
    n3 = Neuron(Id=3, LayerId=0)

    n4 = Neuron(Id=4, LayerId=1)
    n5 = Neuron(Id=5, LayerId=1)

    n6 = Neuron(Id=6, LayerId=2)
    n7 = Neuron(Id=7, LayerId=2)

    n8 = Neuron(Id=8, LayerId=3)

    # Create the synapses for input layer
    n1.createSynapse(1, n4)
    n1.createSynapse(1, n5)
    n2.createSynapse(1, n4)
Esempio n. 4
0
    connects with the hidden layer`s two neurons, which in turn, they
    connect with the output layer`s neuron.
"""

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

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

    n1 = Neuron(Id=1, LayerId=0, Name="Input")
    n1.setAutoNotify(True)

    n2 = Neuron(Id=2, LayerId=1)
    n3 = Neuron(Id=3, LayerId=1)
    n4 = Neuron(Id=4, LayerId=2, Name="Output")

    # Create the synapses
    n1.createSynapse(1, n2)
    n1.createSynapse(1, n3)
    n2.createSynapse(2, n4)
    n3.createSynapse(2, n4)

    print "*" * 40

    # Put the weights