Skip to content

Commit 4a617c6

Browse files
author
Lukas Molzberger
committed
activationsToString refactoring
1 parent 6ca4cbc commit 4a617c6

18 files changed

+83
-107
lines changed

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ public class Document implements Comparable<Document> {
5858
private final String content;
5959

6060
public long visitedCounter = 1;
61-
public int interpretationIdCounter = 1;
6261
public int activationIdCounter = 0;
6362
public int searchNodeIdCounter = 0;
6463
public int searchStepCounter = 0;
@@ -324,11 +323,11 @@ public String generateOutputText() {
324323

325324

326325
public String activationsToString() {
327-
return activationsToString(false, false);
326+
return activationsToString(true, false, false);
328327
}
329328

330329

331-
public String activationsToString(boolean withTextSnippet, boolean withLogic) {
330+
public String activationsToString(boolean finalOnly, boolean withTextSnippet, boolean withLogic) {
332331
Set<Activation> acts = new TreeSet<>(ACTIVATIONS_OUTPUT_COMPARATOR);
333332

334333
for (INeuron n : activatedNeurons) {
@@ -339,15 +338,22 @@ public String activationsToString(boolean withTextSnippet, boolean withLogic) {
339338
StringBuilder sb = new StringBuilder();
340339

341340
sb.append("Activation ID -");
342-
sb.append(" Input Decision | Current Decision | Final Decision -");
341+
if(finalOnly) {
342+
sb.append(" Final Decision -");
343+
} else {
344+
sb.append(" Decision -");
345+
}
343346
sb.append(" Range" + (withTextSnippet ? " | Text Snippet" : ""));
344347
sb.append(" -");
345348
sb.append(" Neuron Label -");
346349
sb.append((withLogic ? " Logic Layer -" : ""));
347350
sb.append(" Relational ID (Word Pos.) -");
348351
sb.append(" Upper Bound -");
349-
sb.append(" Simulation Rounds [Round | Value | Weight | Norm] -");
350-
sb.append(" Final Value | Final Weight | Final Norm -");
352+
if(finalOnly) {
353+
sb.append(" Final Value | Final Weight | Final Norm -");
354+
} else {
355+
sb.append(" Simulation Rounds [Round | Value | Weight | Norm] -");
356+
}
351357
sb.append(" Input Value |");
352358
sb.append(" Target Value");
353359
sb.append("\n");
@@ -358,7 +364,7 @@ public String activationsToString(boolean withTextSnippet, boolean withLogic) {
358364
continue;
359365
}
360366

361-
sb.append(act.toString(withTextSnippet, withLogic));
367+
sb.append(act.toString(finalOnly, withTextSnippet, withLogic));
362368
sb.append("\n");
363369
}
364370

@@ -413,7 +419,7 @@ public void processChanges() {
413419
if(log.isDebugEnabled()) {
414420
log.debug("QueueId:" + th.queueId);
415421
log.debug(n.toString() + "\n");
416-
log.debug("\n" + activationsToString( true, true));
422+
log.debug("\n" + activationsToString( false, true, true));
417423
}
418424
}
419425
}
@@ -454,8 +460,6 @@ public boolean process() {
454460

455461

456462
public class ValueQueue {
457-
458-
459463
public final ArrayList<TreeSet<Activation>> queue = new ArrayList<>();
460464

461465
public void propagateActivationValue(int round, Activation act) {
@@ -551,5 +555,4 @@ public void dumpOscillatingActivations() {
551555
log.error("");
552556
});
553557
}
554-
555558
}

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

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public Weight process(SearchNode sn, int round, long v) {
152152
if (propagate) {
153153
if(round > Document.MAX_ROUND) {
154154
log.error("Error: Maximum number of rounds reached. The network might be oscillating.");
155-
log.info(doc.activationsToString(true, true));
155+
log.info(doc.activationsToString(false, true, true));
156156

157157
doc.dumpOscillatingActivations();
158158
throw new RuntimeException("Maximum number of rounds reached. The network might be oscillating.");
@@ -594,13 +594,12 @@ public String toString() {
594594
}
595595

596596

597-
public String toString(boolean withTextSnippet, boolean withLogic) {
597+
598+
public String toString(boolean finalOnly, boolean withTextSnippet, boolean withLogic) {
598599
StringBuilder sb = new StringBuilder();
599600
sb.append(id + " - ");
600601

601-
sb.append("ID:" + inputDecision + " ");
602-
sb.append("D:" + decision + " ");
603-
sb.append("FD:" + finalDecision + " - ");
602+
sb.append((finalOnly ? finalDecision : decision) + " - ");
604603

605604
sb.append(key.range);
606605

@@ -624,14 +623,16 @@ public String toString(boolean withTextSnippet, boolean withLogic) {
624623
sb.append(Utils.round(upperBound));
625624

626625
sb.append(" - ");
627-
for (Map.Entry<Integer, State> me : rounds.rounds.entrySet()) {
628-
State s = me.getValue();
629-
sb.append("[R: " + me.getKey() + " " + s + "]");
630-
}
631-
632-
if (isFinalActivation()) {
633-
State fs = getFinalState();
634-
sb.append(" - Final: " + fs);
626+
if(finalOnly) {
627+
if (isFinalActivation()) {
628+
State fs = getFinalState();
629+
sb.append(fs);
630+
}
631+
} else {
632+
for (Map.Entry<Integer, State> me : rounds.rounds.entrySet()) {
633+
State s = me.getValue();
634+
sb.append("[R: " + me.getKey() + " " + s + "]");
635+
}
635636
}
636637

637638
if (inputValue != null) {

src/test/java/org/aika/network/EntityResolutionTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,16 @@ public void testSimpleERExample() {
8585

8686
wJaguar.addInput(doc, 0, 6);
8787

88-
System.out.println(doc.activationsToString(false, true));
88+
System.out.println(doc.activationsToString(false, false, true));
8989

9090
wPuma.addInput(doc, 7, 11);
9191

92-
System.out.println(doc.activationsToString(false, true));
92+
System.out.println(doc.activationsToString(false, false, true));
9393

9494
System.out.println("Process");
9595
doc.process();
9696

97-
System.out.println(doc.activationsToString(false, true));
97+
System.out.println(doc.activationsToString(true, false, true));
9898

9999

100100
Assert.assertNotNull(eJaguar.get().getFirstActivation(doc));
@@ -285,16 +285,16 @@ public void testERExampleWithCategories() {
285285

286286
wJaguar.addInput(doc, 0, 6);
287287

288-
System.out.println(doc.activationsToString(false, true));
288+
System.out.println(doc.activationsToString(false, false, true));
289289

290290
wPuma.addInput(doc, 7, 11);
291291

292-
System.out.println(doc.activationsToString(false, true));
292+
System.out.println(doc.activationsToString(false, false, true));
293293

294294
System.out.println("Process");
295295
doc.process();
296296

297-
System.out.println(doc.activationsToString(false, true));
297+
System.out.println(doc.activationsToString(true, false, true));
298298

299299

300300
Assert.assertNotNull(eJaguar.get().getFirstActivation(doc));

src/test/java/org/aika/network/GenerateTextTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,12 @@ public void testTwoWords() {
155155
inA.addInput(doc, 0, 3);
156156
inB.addInput(doc, 0, 3);
157157

158-
System.out.println(doc.activationsToString(true, true));
158+
System.out.println(doc.activationsToString(false, true, true));
159159

160160
// Search for the best interpretation.
161161
doc.process();
162162

163-
System.out.println(doc.activationsToString(true, true));
163+
System.out.println(doc.activationsToString(true, true, true));
164164

165165
System.out.println();
166166

src/test/java/org/aika/network/InterpretationSearchTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ public void testBackwardReferencingSynapses() {
303303

304304
doc.process();
305305

306-
System.out.println(doc.activationsToString(true, true));
306+
System.out.println(doc.activationsToString(true, true, true));
307307

308308
Assert.assertFalse(nD.getFinalActivations(doc).isEmpty());
309309
}
@@ -384,7 +384,7 @@ public void testReversePositiveFeedbackSynapse() {
384384

385385
// doc.process();
386386

387-
System.out.println(doc.activationsToString(true, true));
387+
System.out.println(doc.activationsToString(true, true, true));
388388

389389

390390
// Complete the model
@@ -452,7 +452,7 @@ public void testReversePositiveFeedbackSynapse() {
452452
doc.propagate();
453453
doc.process();
454454

455-
System.out.println(doc.activationsToString(true, true));
455+
System.out.println(doc.activationsToString(true, true, true));
456456

457457
Assert.assertFalse(nD.getFinalActivations(doc).isEmpty());
458458

src/test/java/org/aika/network/MutualExclusionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public void testMutualExclusion() {
178178
// Computes the selected option
179179
doc.process();
180180

181-
System.out.println(doc.activationsToString(false, true));
181+
System.out.println(doc.activationsToString(true, false, true));
182182

183183
Assert.assertTrue(pA.getFinalActivations(doc).isEmpty());
184184
Assert.assertFalse(pB.getFinalActivations(doc).isEmpty());

src/test/java/org/aika/network/NamedEntityRecognitionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ public void testNamedEntityRecognitionWithoutCounterNeuron() {
233233
// Search for the best interpretation of this text.
234234
doc.process();
235235

236-
System.out.println(doc.activationsToString(false, true));
236+
System.out.println(doc.activationsToString(true, false, true));
237237
System.out.println();
238238

239239
System.out.println("Activations of the Surname Category:");

src/test/java/org/aika/network/NegationTest.java

Lines changed: 27 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -76,22 +76,16 @@ public void testTwoNegativeInputs1() {
7676

7777
inA.addInput(doc, 0, 11, 0);
7878

79-
System.out.println(doc.activationsToString(false, true));
79+
System.out.println(doc.activationsToString(false, false, true));
8080
Assert.assertNotNull(Selector.get(doc, abcN.get(), null, new Range(0, 11), Relation.EQUALS));
8181

82-
inB.addInput(doc,
83-
new Activation.Builder()
84-
.setRange(2, 7)
85-
);
82+
inB.addInput(doc, 2, 7);
8683

87-
System.out.println(doc.activationsToString(false, true));
84+
System.out.println(doc.activationsToString(false, false, true));
8885

89-
inC.addInput(doc,
90-
new Activation.Builder()
91-
.setRange(4, 9)
92-
);
86+
inC.addInput(doc, 4, 9);
9387

94-
System.out.println(doc.activationsToString(false, true));
88+
System.out.println(doc.activationsToString(false, false, true));
9589

9690
Assert.assertNotNull(Selector.get(doc, abcN.get(), null, new Range(0, 11), Relation.EQUALS));
9791
}
@@ -143,21 +137,15 @@ public void testTwoNegativeInputs2() {
143137

144138
inA.addInput(doc, 0, 11);
145139

146-
System.out.println(doc.activationsToString(false, true));
140+
System.out.println(doc.activationsToString(false, false, true));
147141

148-
inB.addInput(doc,
149-
new Activation.Builder()
150-
.setRange(2, 7)
151-
);
142+
inB.addInput(doc, 2, 7);
152143

153-
System.out.println(doc.activationsToString(false, true));
144+
System.out.println(doc.activationsToString(false, false, true));
154145

155-
inC.addInput(doc,
156-
new Activation.Builder()
157-
.setRange(4, 9)
158-
);
146+
inC.addInput(doc, 4, 9);
159147

160-
System.out.println(doc.activationsToString(false, true));
148+
System.out.println(doc.activationsToString(false, false, true));
161149

162150
// Assert.assertNull(Activation.get(t, outN.node, 0, new Range(0, 11), Range.Relation.EQUALS, null, null, null));
163151
}
@@ -206,11 +194,11 @@ public void testSimpleNegation1() {
206194

207195
inS.addInput(doc, 3, 8);
208196

209-
System.out.println(doc.activationsToString(false, true));
197+
System.out.println(doc.activationsToString(false, false, true));
210198

211199
inA.addInput(doc, 0, 11);
212200

213-
System.out.println(doc.activationsToString(false, true));
201+
System.out.println(doc.activationsToString(false, false, true));
214202

215203
Assert.assertNotNull(Selector.get(doc, outN.get(), null, new Range(0, 11), Relation.EQUALS));
216204

@@ -259,16 +247,13 @@ public void testSimpleNegation2() {
259247

260248
Document doc = m.createDocument("aaaaaaaaaaa", 0);
261249

262-
inS.addInput(doc,
263-
new Activation.Builder()
264-
.setRange(3, 8)
265-
);
250+
inS.addInput(doc, 3, 8);
266251

267-
System.out.println(doc.activationsToString(false, true));
252+
System.out.println(doc.activationsToString(false, false, true));
268253

269254
inA.addInput(doc, 0, 11);
270255

271-
System.out.println(doc.activationsToString(false, true));
256+
System.out.println(doc.activationsToString(false, false, true));
272257

273258
Assert.assertNotNull(Selector.get(doc, outN.get(), null, new Range(0, 11), Relation.EQUALS));
274259

@@ -319,14 +304,11 @@ public void testSimpleNegation3() {
319304

320305
inA.addInput(doc, 0, 11);
321306

322-
System.out.println(doc.activationsToString(false, true));
307+
System.out.println(doc.activationsToString(false, false, true));
323308

324-
inS.addInput(doc,
325-
new Activation.Builder()
326-
.setRange(3, 8)
327-
);
309+
inS.addInput(doc, 3, 8);
328310

329-
System.out.println(doc.activationsToString(false, true));
311+
System.out.println(doc.activationsToString(false, false, true));
330312

331313
Assert.assertNotNull(Selector.get(doc, outN.get(), null, new Range(0, 11), Relation.EQUALS));
332314

@@ -409,11 +391,11 @@ public void testNegation1() {
409391
Document doc = m.createDocument("aaaaaaaaaa", 0);
410392

411393
inA.addInput(doc, 0, 6, 0);
412-
System.out.println(doc.activationsToString(false, true));
394+
System.out.println(doc.activationsToString(false, false, true));
413395

414396
inB.addInput(doc, 0, 6, 0);
415397

416-
System.out.println(doc.activationsToString(false, true));
398+
System.out.println(doc.activationsToString(false, false, true));
417399

418400
Assert.assertNotNull(Selector.get(doc, inS.get(), null, new Range(0, 6), Relation.EQUALS));
419401
Assert.assertEquals(2, Selector.get(doc, inS.get(), null, new Range(0, 6), Relation.EQUALS).neuronInputs.size());
@@ -425,11 +407,11 @@ public void testNegation1() {
425407
Document doc = m.createDocument("aaaaaaaaaa", 0);
426408

427409
inA.addInput(doc, 0, 6);
428-
System.out.println(doc.activationsToString(false, true));
410+
System.out.println(doc.activationsToString(false, false, true));
429411

430412
inB.addInput(doc, 3, 9);
431413

432-
System.out.println(doc.activationsToString(false, true));
414+
System.out.println(doc.activationsToString(false, false, true));
433415

434416
// Assert.assertNotNull(Selector.get(t, inS.node, 0, new Range(0, 6), EQUALS, EQUALS, null, null, null));
435417
Assert.assertNotNull(Selector.get(doc, inS.get(), null, new Range(0, 9), Relation.EQUALS));
@@ -595,19 +577,19 @@ public void testNegation2() {
595577

596578
inA.addInput(doc, 0, 6);
597579

598-
System.out.println(doc.activationsToString(false, true));
580+
System.out.println(doc.activationsToString(false, false, true));
599581

600582
inB.addInput(doc, 0, 6);
601583

602-
System.out.println(doc.activationsToString(false, true));
584+
System.out.println(doc.activationsToString(false, false, true));
603585

604586
inC.addInput(doc, 0, 6);
605587

606-
System.out.println(doc.activationsToString(false, true));
588+
System.out.println(doc.activationsToString(false, false, true));
607589

608590
doc.process();
609591

610-
System.out.println(doc.activationsToString( false, true));
592+
System.out.println(doc.activationsToString( true, false, true));
611593
}
612594

613595

@@ -712,7 +694,7 @@ public void testOptions() {
712694
inB.addInput(doc, 0, 1, 0);
713695
inG.addInput(doc, 0, 1, 0);
714696

715-
System.out.println(doc.activationsToString(false, true));
697+
System.out.println(doc.activationsToString(false, false, true));
716698

717699
Assert.assertNotNull(pC.get().getFirstActivation(doc));
718700
Assert.assertNotNull(pD.get().getFirstActivation(doc));

0 commit comments

Comments
 (0)