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")
def __init__ (self, Id, LayerId): Neuron.__init__ (self, Id, LayerId) # Input value self.input = None # The associated feature map. self.featureMap = list () # The number of inputs also define the length of the feature map. self.numberOfInputs = 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")
def __init__(self, Id, LayerId): Neuron.__init__(self, Id, LayerId) # Input value self.input = None # The associated feature map. self.featureMap = list() # The number of inputs also define the length of the feature map. self.numberOfInputs = 0
def neuronInputsUpdated(self, object, property): """ Pass the input value to all synapses except the input bidisynapses. """ if self.numberOfSynapses > 0: Neuron.neuronInputsUpdated(self, object, property) for layer in self.outputBidiSynapses.values(): for neuron, bidisynapse in layer.iteritems(): bidisynapse.putInput(self.input) for layer in self.inputBidiSynapses.values(): for neuron, inputSynapse in layer.iteritems(): inputSynapse.putInput(self.input)
def neuronInputsUpdated (self, object, property): """ Pass the input value to all synapses except the input bidisynapses. """ if self.numberOfSynapses > 0: Neuron.neuronInputsUpdated (self, object, property) for layer in self.outputBidiSynapses.values (): for neuron, bidisynapse in layer.iteritems (): bidisynapse.putInput (self.input) for layer in self.inputBidiSynapses.values (): for neuron, inputSynapse in layer.iteritems (): inputSynapse.putInput (self.input)
def __init__(self, Id, LayerId, Name=None): Neuron.__init__(self, Id, LayerId, Name) # Bidirectional Synapses self.inputBidiSynapses = dict() self.outputBidiSynapses = dict() # Total number of bidirectional synapses self.numberOfBidiSynapses = 0 self.numberOfInputBidiSynapses = 0 self.numberOfOutputBidiSynapses = 0 # The current number of number of synapses. # that have "fired". self.numberOfBidiSynapsesFired = 0 self.numberOfInputBidiSynapsesFired = 0 self.numberOfOutputBidiSynapsesFired = 0 # The current bidi synapses that have # successfuly fired (an in "input"), so # that we release the lock ;) self.indexOfFiredBidiSynapses = list()
def __init__ (self, Id, LayerId, Name=None): Neuron.__init__ (self, Id, LayerId, Name) # Bidirectional Synapses self.inputBidiSynapses = dict () self.outputBidiSynapses= dict () # Total number of bidirectional synapses self.numberOfBidiSynapses = 0 self.numberOfInputBidiSynapses = 0 self.numberOfOutputBidiSynapses= 0 # The current number of number of synapses. # that have "fired". self.numberOfBidiSynapsesFired = 0 self.numberOfInputBidiSynapsesFired = 0 self.numberOfOutputBidiSynapsesFired= 0 # The current bidi synapses that have # successfuly fired (an in "input"), so # that we release the lock ;) self.indexOfFiredBidiSynapses = list ()
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")
# 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
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)
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
# 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, Name="Input") n2 = Neuron (Id=2, LayerId=1) n3 = Neuron (Id=3, LayerId=2, Name="Output") # Create the synapses n1.createSynapse (1, n2) n1.createSynapse (1, n3) n2.createSynapse (2, n3) # Put the weights n1.putWeights ((0.5, 3.0)) n2.putWeights ((-.75,)) # Insert the inputs n1.putInput (1.0)
Input layer connects with the first hidden layer and the output layer as well. The "network" is really simple since it is composed only of three neurons. """ # 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, Name="Input") n2 = Neuron(Id=2, LayerId=1) n3 = Neuron(Id=3, LayerId=2, Name="Output") # Create the synapses n1.createSynapse(1, n2) n1.createSynapse(1, n3) n2.createSynapse(2, n3) # Put the weights n1.putWeights((0.5, 3.0)) n2.putWeights((-.75, )) # Insert the inputs n1.putInput(1.0)