Skip to content

Instantly share code, notes, and snippets.

Created October 13, 2014 08:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/52c2ce284706dd6aa0ac to your computer and use it in GitHub Desktop.
Save anonymous/52c2ce284706dd6aa0ac to your computer and use it in GitHub Desktop.
import math
class Neuron:
def __init__(self, network, ID, aE, threshhold = 0, isBias = 0):
self.network = network
self.weights = {}
self.successors = []
self.values = []
self.ID = ID
self.activationEquation = aE
if not isBias:
network.addSynapse(0, ID, -threshhold)
def __str__(self):
return 'Neuron(' + self.ID + ', Successors(' + str(self.successors) + ')'
def feed(self, successor):
self.successors.append(successor)
def poll(self, ancestor, weight):
self.weights[ancestor] = weight
def update(self, ID, net):
self.values.append(weights[ID] * net)
if len(self.weights) == len(self.values):
propagate()
def propagate(self):
net = 0
for value in self.values:
net += value
activate(net)
def activate(self, net):
push(self.activationEquation(net))
def push(self, net):
for successor in self.successors:
self.net.neurons[successor].update(ID, net)
values = []
class ActivationEquations:
def fermi(self, net):
return 1 / (1 + math.exp(-net * 25))
def binary(self, net):
if net > 0:
return 1
return 0
def one(self, net):
return 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment