-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNeuron.py
More file actions
65 lines (49 loc) · 1.51 KB
/
Neuron.py
File metadata and controls
65 lines (49 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from NeuroMath import f_sigmoid
import math
'''
Neuron Class:
This is inheritable class for Input/Hidden/Output Neuron classes.
comp_input():
Calculate neuron input
act():
Activation function for calculating output of neuron (sigmoid function)
'''
class Neuron:
def __init__(self, n_type):
self.type = n_type
self.output = 0
self.syn_list_out = []
def comp_input(self):
sum = 0
for syn in self.syn_list_in:
sum += syn.weight * syn.n_in.output
self.input = sum
def act(self):
self.output = 1/(1+ math.exp(-(self.input)))
class InputNeuron(Neuron):
def __init__(self, n_type):
Neuron.__init__(self,n_type)
self.syn_list_out = []
class HiddenNeuron(Neuron):
def __init__(self, n_type):
Neuron.__init__(self,n_type)
self.syn_list_in = []
self.syn_list_in = []
self.input = 0
def compute_delta(self):
sum = 0
for syn in self.syn_list_out:
sum += syn.weight * syn.n_out.delta
self.delta = f_sigmoid(self.output) * sum
class OutputNeuron(Neuron):
def __init__(self, n_type):
Neuron.__init__(self,n_type)
self.syn_list_in = []
self.input = 0
def compute_delta(self, out_ideal):
self.delta = (out_ideal - self.output) * f_sigmoid(self.output)
class BiasNeuron(Neuron):
def __init__(self, n_type):
Neuron.__init__(self,n_type)
self.output = 1
self.syn_list_out = []