-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathneuron.cpp
157 lines (142 loc) · 4.36 KB
/
neuron.cpp
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#include "neuron.h"
void Neuron::dendrite(bool input_pulse[13]){
this->voltage = 0;
for(int i=0;i<13;i++){
this->input_mem[i] = input_pulse[i];
this->input_mem[i] = this->input_mem[i] * this->synap[i].sensitive;
this->voltage += input_pulse[i];
}
if(this->voltage > this->Vth){
this->axon = 1;
}
else{
this->axon = 0;
}
}
void Neuron::regulatory(unsigned int regulate_signal[13]){
/*
regulate_signal[i] = [0, 1, 2, 3]
regulate_signal is the return signal via exitation or inhibition back from the output
can be understood as a homeostatic regulatory signal against excessive or inactive neurons
*/
/*
may be confuse here:
if the signal backward received is 01 or 00 but the axon in this neuron is 00 or 01
what does it mean?
it means that the in the lower layer, the neuron is activate/inactivate
and in this layer, the neuron is inactivate/activate
and then there have no connection between them yet
and more: the neuron is working fine and no need to be regulated
*/
for(int i=0;i<13;i++)
{
if(regulate_signal[i]==2){
this->inhibit_signal += 1;
}
else if(regulate_signal[i]==3){
this->stimulate_signal += 1;
}
}
if ((this->inhibit_signal > this->stimulate_signal) and (this->axon)){
this->inhibition();
}
else if ((this->inhibit_signal < this->stimulate_signal) and (this->axon==0)){
this->stimulation();
}
else{
this->consolidate();
}
this->inhibit_signal = 0;
this->stimulate_signal = 0;
}
void Neuron::consolidate(){
if (this->axon){
this->regulation = 1;
for(int i=0;i<13;i++){
if((this->input_mem[i]) and (this->synap[i].sensitive)<15){
this->synap[i].sensitive += 1;
}
else if((this->input_mem[i]==0) and (this->synap[i].sensitive)>0){
this->synap[i].sensitive -= 1;
}
}
}
else if (this->axon==0){
this->regulation = 0;
for(int i=0;i<13;i++){
if (this->synap[i].sensitive>0){
this->synap[i].sensitive -= 1;
}
}
}
}
void Neuron::stimulation(){
// occur when the neuron is inactivated and received a stimulation signal from lower layer
// increase the electropositivity
if(this->Vth > 0){
this->Vth -= 1;
}
if (this->voltage > this->Vth){
// the regulation=0 here may not necessary because the neuron is already activated
if (this->axon){
this->regulation = 1;
}
else if (this->axon==0){
this->regulation = 0;
}
}
else{ //increase the sensitivity of the synap
this->voltage = 0;
for(int i=0;i<13;i++){
if (this->synap[i].sensitive<15){
this->synap[i].sensitive += 1;
this->voltage += this->synap[i].sensitive*this->input_mem[i];
}
}
if (this->voltage > this->Vth){
if (this->axon){
this->regulation = 1;
}
else if (this->axon==0){
this->regulation = 0;
}
}
else{ // still can activate? -> stimulate the higher layer
this->regulation = 3;
}
}
}
void Neuron::inhibition(){
// occur when the neuron is activated and received a inhibition signal from lower layer
if(this->Vth < 127){
this->Vth += 1;
}
if (this->voltage < this->Vth){
if (this->axon){
this->regulation = 1;
}
else if (this->axon==0){
this->regulation = 0;
}
}
else{ //decrease the sensitivity of the synap
this->voltage = 0;
for(int i=0;i<13;i++){
if (this->synap[i].sensitive>0){
this->synap[i].sensitive -= 1;
this->voltage += this->synap[i].sensitive*this->input_mem[i];
}
}
if (this->voltage < this->Vth){
if (this->axon){
this->regulation = 1;
}
else if (this->axon==0){
this->regulation = 0;
}
}
else{ // inhibit the higher layer
this->regulation = 2;
}
}
}