Skip to content

Commit dee5038

Browse files
author
Lukas Molzberger
committed
final state should never be null
1 parent b1421a5 commit dee5038

File tree

3 files changed

+9
-14
lines changed

3 files changed

+9
-14
lines changed

src/main/java/org/aika/corpus/Document.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -389,11 +389,10 @@ public String neuronActivationsToString(boolean withWeights, boolean withTextSni
389389
}
390390

391391
if (act.isFinalActivation()) {
392-
if(act.finalState != null) {
393-
sb.append(" - FV:" + Utils.round(act.finalState.value));
394-
sb.append(" FW:" + Utils.round(act.finalState.weight.w));
395-
sb.append(" FN:" + Utils.round(act.finalState.weight.n));
396-
}
392+
sb.append(" - FV:" + Utils.round(act.finalState.value));
393+
sb.append(" FW:" + Utils.round(act.finalState.weight.w));
394+
sb.append(" FN:" + Utils.round(act.finalState.weight.n));
395+
397396
if(act.targetValue != null) {
398397
sb.append(" - TV:" + Utils.round(act.targetValue));
399398
}
@@ -652,12 +651,7 @@ public int compare(Activation act1, Activation act2) {
652651
Activation.State fs1 = act1.finalState;
653652
Activation.State fs2 = act2.finalState;
654653

655-
int r = 0;
656-
if(fs2 == null && fs1 != null) return -1;
657-
if(fs2 != null && fs1 == null) return 1;
658-
if(fs2 != null && fs1 != null) {
659-
r = Integer.compare(fs2.fired, fs1.fired);
660-
}
654+
int r = Integer.compare(fs2.fired, fs1.fired);
661655
if(r != 0) return r;
662656
return act1.key.compareTo(act2.key);
663657
}

src/main/java/org/aika/corpus/InterprNode.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,8 @@ void storeFinalWeight(long v) {
518518
visitedStoreFinalWeight = v;
519519

520520
for(Activation act: getNeuronActivations()) {
521-
act.finalState = act.rounds.getLast();
521+
Activation.State fs = act.rounds.getLast();
522+
act.finalState = fs != null ? fs : Activation.State.ZERO;
522523
}
523524

524525
for(InterprNode cn: children) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public final class Activation extends NodeActivation<OrNode> {
3535
public double lowerBound;
3636

3737
public Rounds rounds = new Rounds();
38-
public State finalState;
38+
public State finalState = State.ZERO;
3939
public double maxActValue = 0.0;
4040

4141
public boolean ubQueued = false;
@@ -97,7 +97,7 @@ public List<SynapseActivation> getFinalOutputActivations() {
9797

9898

9999
public boolean isFinalActivation() {
100-
return (finalState != null && finalState.value > 0.0) || (targetValue != null && targetValue > 0.0);
100+
return finalState.value > 0.0 || (targetValue != null && targetValue > 0.0);
101101
}
102102

103103

0 commit comments

Comments
 (0)