-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCANTNeuronFastSlowBind.java
executable file
·142 lines (124 loc) · 5.21 KB
/
CANTNeuronFastSlowBind.java
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
//This neuron has fast and slow bind synapses.
//The fast bind synapses will just increase or decrease by the
//learning rate, but also loose weight each time they don't fire.
public class CANTNeuronFastSlowBind extends CANTNeuron {
private double fastBindWeightChange = 0.004;
int fastBindStart = -1; //The first fastBind synapse is here and all others
//at the offset specified by this var.
public CANTNeuronFastSlowBind(int neuronID, CANTNet net) {
super(neuronID, net);
}
public CANTNeuronFastSlowBind(int neuronID,CANTNet net,double weightChange) {
super(neuronID, net);
fastBindWeightChange = weightChange;
}
public CANTNeuronFastSlowBind(int neuronID, CANTNet net, int synapses) {
super(neuronID, net, synapses);
}
public CANTNeuronFastSlowBind(int neuronID, CANTNet net, int synapses,
double weightChange) {
super(neuronID, net, synapses);
fastBindWeightChange = weightChange;
}
public void addFastBindConnection(CANTNeuron toNeuron) {
if (fastBindStart == -1) fastBindStart = getCurrentSynapses();
addConnection(toNeuron,0.02);
}
//this is just learn4 from CANTNeuron modified to work on just
//the slowbind synapses.
public void slowLearn(){
double totalConnectionStrength;
double modification;
double fromCompensatoryStrengthModifier,fromCompensatoryWeakModifier;
totalConnectionStrength = getTotalConnectionStrength();
fromCompensatoryWeakModifier =
getWeakCompensatoryModifier(totalConnectionStrength);
fromCompensatoryStrengthModifier =
getStrengthCompensatoryModifier(totalConnectionStrength);
//System.out.println("mods "+totalConnectionStrength+" "+fromCompensatoryWeakModifier+" "+fromCompensatoryStrengthModifier);
//Just go up through the slow bind synapses which are first.
int lastSlowBindSynapse = getCurrentSynapses();
if (fastBindStart != -1) lastSlowBindSynapse = fastBindStart;
//Test each Synapse from the active neuron
for (int synap=0; synap < lastSlowBindSynapse; synap++) {
double connectionStrength = synapses[synap].getWeight();
CANTNeuron toNeuron = synapses[synap].getTo();
//If both Neurons were active,
if (toNeuron.getFired()) {
if (!isInhibitory){
modification = getIncreaseBase(connectionStrength);
modification *= fromCompensatoryStrengthModifier;
connectionStrength = connectionStrength+modification;
synapses[synap].setWeight(connectionStrength);
//System.out.println("Inc Exc "+this.getId()+" "+toNeuron.getId()+" "+synapses[synap].getWeight()+" "+modification);
}
else{//decrease inhibition
modification =getDecreaseBase(connectionStrength);
modification *= fromCompensatoryWeakModifier;
connectionStrength = connectionStrength-modification;
synapses[synap].setWeight(connectionStrength);
//System.out.println("dec Inh "+this.getId()+" "+toNeuron.getId()+" "+synapses[synap].getWeight()+" "+modification);
}
} //end of to neuron active
//if to Neuron is inactive
else {
if (!isInhibitory){
modification =getDecreaseBase(connectionStrength);
modification *= fromCompensatoryWeakModifier;
connectionStrength = connectionStrength-modification;
synapses[synap].setWeight(connectionStrength);
//System.out.println("dec Exc "+this.getId()+" "+toNeuron.getId()+" "+synapses[synap].getWeight()+" "+modification);
}
else {
modification = getIncreaseBase(connectionStrength);
modification *= fromCompensatoryStrengthModifier;
connectionStrength = (connectionStrength)-modification;
synapses[synap].setWeight(connectionStrength);
//System.out.println("Inc Inh"+this.getId()+" "+toNeuron.getId()+" "+synapses[synap].getWeight()+" "+modification);
}
} // end of to Neuron inactive
}
}
public void learn() {
fastLearn();
if( !getFired()) return;
slowLearn();
}
public void fastLearn() {
double weight = 0.0;
if (fastBindStart == -1) return;
if (getFired() && (!getInhibitory())) {
for (int synapseIndex=fastBindStart;synapseIndex<getCurrentSynapses();
synapseIndex++)
{
CANTNeuron toNeuron = synapses[synapseIndex].getTo();
if (toNeuron.getFired())
{
weight = synapses[synapseIndex].getWeight();
weight += parentNet.getLearningRate();
if (weight > 1.0) weight = 1.0;
synapses[synapseIndex].setWeight(weight);
}
}
}
//here's where the weight slowly fades
else { //not fired
for (int synapseIndex=fastBindStart;synapseIndex<getCurrentSynapses();
synapseIndex++)
{
weight = synapses[synapseIndex].getWeight();
if (isInhibitory())
{
weight += fastBindWeightChange;
if (weight > 0) weight = -.001;
}
else
{
weight -= fastBindWeightChange;
if (weight < 0) weight = .001;
}
synapses[synapseIndex].setWeight(weight);
}
}
}
}