Skip to content

Commit 548fea4

Browse files
author
Lukas Molzberger
committed
small refactoring
1 parent 86d0913 commit 548fea4

File tree

2 files changed

+15
-25
lines changed

2 files changed

+15
-25
lines changed

src/main/java/org/aika/Converter.java

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,13 @@ private boolean convert() {
149149
}
150150

151151

152+
public static final int DIRECT = 0;
153+
public static final int RECURRENT = 1;
154+
public static final int POSITIVE = 0;
155+
public static final int NEGATIVE = 1;
156+
152157
private void initInputNodesAndComputeWeightSums() {
153-
double negDirSumDelta = 0.0;
154-
double negRecSumDelta = 0.0;
155-
double posRecSumDelta = 0.0;
158+
double[][] sumDelta = new double[2][2];
156159
double maxRecurrentSumDelta = 0.0;
157160

158161
for (Synapse s : modifiedSynapses) {
@@ -171,35 +174,19 @@ private void initInputNodesAndComputeWeightSums() {
171174
neuron.provider.setModified();
172175
}
173176

174-
if (s.isNegative()) {
175-
if (!s.key.isRecurrent) {
176-
negDirSumDelta -= s.w;
177-
} else {
178-
negRecSumDelta -= s.w;
179-
}
180-
} else if (s.key.isRecurrent) {
181-
posRecSumDelta -= s.w;
182-
}
183-
184-
if (s.nw <= 0.0) {
185-
if (!s.key.isRecurrent) {
186-
negDirSumDelta += s.nw;
187-
} else {
188-
negRecSumDelta += s.nw;
189-
}
190-
} else if (s.key.isRecurrent) {
191-
posRecSumDelta += s.nw;
192-
}
177+
sumDelta[s.key.isRecurrent ? RECURRENT : DIRECT][s.isNegative() ? NEGATIVE : POSITIVE] -= s.w;
178+
sumDelta[s.key.isRecurrent ? RECURRENT : DIRECT][s.nw <= 0.0 ? NEGATIVE : POSITIVE] += s.nw;
193179

194180
s.w = s.nw;
195181

196182
in.lock.releaseWriteLock();
197183
}
198184

199185
neuron.maxRecurrentSum += maxRecurrentSumDelta;
200-
neuron.negDirSum += negDirSumDelta;
201-
neuron.negRecSum += negRecSumDelta;
202-
neuron.posRecSum += posRecSumDelta;
186+
neuron.posDirSum += sumDelta[DIRECT][POSITIVE];
187+
neuron.negDirSum += sumDelta[DIRECT][NEGATIVE];
188+
neuron.negRecSum += sumDelta[RECURRENT][NEGATIVE];
189+
neuron.posRecSum += sumDelta[RECURRENT][POSITIVE];
203190
}
204191

205192

src/main/java/org/aika/neuron/INeuron.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public class INeuron extends AbstractNode<Neuron> implements Comparable<INeuron>
6666
public String outputText;
6767

6868
public volatile double bias;
69+
public volatile double posDirSum;
6970
public volatile double negDirSum;
7071
public volatile double negRecSum;
7172
public volatile double posRecSum;
@@ -605,6 +606,7 @@ public void write(DataOutput out) throws IOException {
605606
}
606607

607608
out.writeDouble(bias);
609+
out.writeDouble(posDirSum);
608610
out.writeDouble(negDirSum);
609611
out.writeDouble(negRecSum);
610612
out.writeDouble(posRecSum);
@@ -641,6 +643,7 @@ public void readFields(DataInput in, Model m) throws IOException {
641643
}
642644

643645
bias = in.readDouble();
646+
posDirSum = in.readDouble();
644647
negDirSum = in.readDouble();
645648
negRecSum = in.readDouble();
646649
posRecSum = in.readDouble();

0 commit comments

Comments
 (0)