I've been working on my code since yesterday and maybe I'm just tired but I'm stuck at a Name error and I can't understand why. What I'm trying to do is make a general neuran class and then a class for each type of neuron instantiated with an appropriate method for neuron type indicator. I'm not very fluent with classes and inheritance, maybe there's a cleaner and more Pythonic way to do it? But first why the error?:
class _Neuron(number, function, forwards_to=[] ):
def __init__(self, number, function, forwards_to):
self.number = number
self.function = function
self.forwards_to = forwards_to
self.current_state = 0 #neurons may have any numeric state representing the sum of inputs from other neurons
self.output = 0
#whenever ready call to use up current state to calculate function output and restet the current state
def fire(self):
self.output = function(self.current_state)
self.current_state = 0
#receices numeric values of outputs of other neurons and adds them to the sum of received signals
def receive_signal(self, input_signal):
self.current_state+=input_signal
#adds a forward connection
def add_connection(self, neuron_number):
if neuron_number not in self.forwards_to:
self.forwards_to.append(neuron_number)
#add multiple forward paths
def add_connections(self, **neuron_numbers):
for neuron_number in neuron_numbers:
self.add_connection(neuron_number)
#remove a neuron connection
def remove_connection(self, neuron_number):
if neuron_number in self.forwards_to:
self.forwars_to.remove(neuron_number)
#remove multiple forward paths
def remove_connections(self, **neuron_numbers):
for neuron_number in neuron_numbers:
self.remove_connection(neuron_number)
def _make_deep(self):
self.type = "deep"
def _make_input(self):
self.type = "input"
def _make_output(self):
self.type = "output"
def get_number(self):
return self.number
def get_type(self):
return self.type
def get_connections(self):
return self.forwards_to
def get_current_state(self):
return self.current_state
def get_output(self):
return self.output
#classes for declaring specific neuron types
#input neuron
class InputNeuron(_Neuron):
def __init__(self, number, function, forwars_to=[]):
super().__init__(number, function, forwars_to=[])
self._make_input()
#output neuron
class OutputNeuron(_Neuron):
def __init__(self, number, function, forwars_to=[]):
super().__init__(number, function, forwars_to=[])
self._make_output()
#deep neuron
class DeepNeuron(_Neuron):
def __init__(self, number, function, forwars_to=[]):
super().__init__(number, function, forwars_to=[])
self._make_deep()
#tests
f = lambda x: 1/x
n1 = _Neuron(number=1, function=f)
n1._make_input()
n1.add_connections(1,2,3,4,5)
n1.receive_signal(100)
print(n1.get_type())
print(n1.get_number())
print(n1.get_connections())
print(n1.get_current_state())
print(n1.get_output())
n1.fire()
print(n1.get_connections())
print(n1.get_current_state())
print(n1.get_output())