Created
December 6, 2012 04:02
-
-
Save Uiuran/4221683 to your computer and use it in GitHub Desktop.
Logistic Neuron class
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
""" NeuronLogistic class to logistic neurons with logit input """ | |
# Field input receives a dictionaire where key = number of the input unit, | |
# element = length 2 list with signal and synaptic weights respectively | |
import numpy as np | |
class NeuronLogistic: | |
def __init__(self,presynaptics): | |
if type(presynaptics) != dict: | |
self.input = {}; | |
self.output = 0; | |
else: | |
self.input = presynaptics; | |
self.output = 0; | |
self.isSynapse(); | |
def receiveNetInput(self,presynaptics): | |
l = list() | |
if type(presynaptics) != dict: | |
self.input = {}; | |
else: | |
self.input = presynaptics; | |
for k in self.input.iterkeys(): | |
if (type(k) != int) and (type(k) != str): | |
l.append(k); | |
for i in l: | |
self.input.pop(i); | |
self.isSynapse(); | |
def receiveInput(self,neuron,synapse): | |
if (type(neuron) != int) and (type(neuron) != str): | |
print('The first argument must be integer, neuron index, or string b for bias'); | |
else: | |
self.input[neuron] = synapse; | |
self.isSynapse(); | |
def processLogit(self): | |
self.logit = 0; | |
for v in self.input.itervalues(): | |
self.logit += v[0]*v[1]; | |
def processOutput(self): | |
try: | |
self.output = 1/(1+np.exp(-self.logit)); | |
except NameError: | |
print('Neuron never calculated any logit, try processLogit before processOutput'); | |
def isSynapse(self): | |
l = list(); | |
for k,v in self.input.iteritems(): | |
if type(v) != list: | |
l.append(k); | |
elif len(v) != 2: | |
l.append(k); | |
else: | |
if type(v[0]) != float: | |
v[0] = 0.0; | |
if type(v[1]) != float: | |
v[1] = 0.0; | |
for i in l: | |
self.input.pop(i); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment