-
-
Save anonymous/52c2ce284706dd6aa0ac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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