def setSynapse(self, axon, dendrite, weight): axon_id = mutil.extractNeuronId(axon) dendrite_id = mutil.extractNeuronId(dendrite) #print 'setting synapse from', axon_id, 'to', dendrite_id, 'with weight', weight mutil.makeDictIfNot(self.synapses_by_dendrite, dendrite_id) mutil.makeDictIfNot(self.synapses_by_axon, axon_id) self.synapses_by_dendrite[dendrite_id][axon_id] = weight self.synapses_by_axon[axon_id][dendrite_id] = weight
def adjustWeights(self): new_weights = dict() for axon_id in sorted(self.neurons.keys(), reverse=False): mutil.makeDictIfNot(new_weights, axon_id) for dendrite_id in self.getAllSynapsesByAxon(axon_id): mutil.makeDictIfNot(new_weights[axon_id], dendrite_id) weight = self.weightAtSynapse(axon_id, dendrite_id) error = self.getErrorAt(dendrite_id) rate = self.learning_rate derivative = self.derivativeOutputAt(dendrite_id) output = self.outputAt(axon_id) new_weights[axon_id][dendrite_id] = weight + rate * error * derivative * output self.setSynapse(axon_id, dendrite_id, new_weights[axon_id][dendrite_id])
def adjustWeights(self): new_weights = dict() for axon_id in sorted(self.neurons.keys(), reverse=False): mutil.makeDictIfNot(new_weights, axon_id) for dendrite_id in self.getAllSynapsesByAxon(axon_id): mutil.makeDictIfNot(new_weights[axon_id], dendrite_id) weight = self.weightAtSynapse(axon_id, dendrite_id) error = self.getErrorAt(dendrite_id) rate = self.learning_rate derivative = self.derivativeOutputAt(dendrite_id) output = self.outputAt(axon_id) new_weights[axon_id][ dendrite_id] = weight + rate * error * derivative * output self.setSynapse(axon_id, dendrite_id, new_weights[axon_id][dendrite_id])