Skip to content

Commit e670390

Browse files
author
Lukas Molzberger
committed
fixes
1 parent 4434919 commit e670390

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

src/main/java/network/aika/neuron/relation/AncestorRelation.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ public void registerRequiredSlots(Neuron input) {
2626
}
2727

2828

29-
private static void collectNotAncestorOf(List<Activation> results, INeuron n, Activation linkedAct) {
30-
31-
}
32-
33-
3429
private static void collectCommonAncestor(Collection<Activation> results, INeuron n, Activation linkedAct, long v) {
3530
if(linkedAct.visited == v) return;
3631

@@ -111,15 +106,15 @@ private static void markAncestors(Activation act, long v) {
111106
}
112107

113108

114-
private static void markDescendant(Activation act, long v) {
109+
private static void markDescendants(Activation act, long v) {
115110
if(act.visited == v) return;
116111
act.visited = v;
117112

118113
act.markedAncDesc = v;
119114

120-
act.getInputLinks(false, false)
115+
act.getOutputLinks(false)
121116
.filter(l -> l.synapse.identity)
122-
.forEach(l -> markDescendant(l.input, v));
117+
.forEach(l -> markDescendants(l.input, v));
123118
}
124119

125120

@@ -258,8 +253,12 @@ public boolean test(Activation act, Activation linkedAct) {
258253

259254
@Override
260255
public Stream<Activation> getActivations(INeuron n, Activation linkedAct) {
261-
List<Activation> results = new ArrayList<>();
262-
return results.stream();
256+
long v = linkedAct.doc.visitedCounter++;
257+
markDescendants(linkedAct, v);
258+
259+
INeuron.ThreadState th = n.getThreadState(linkedAct.doc.threadId, false);
260+
return th.getActivations()
261+
.filter(act -> act.markedAncDesc != v);
263262
}
264263
}
265264

@@ -288,9 +287,12 @@ public boolean test(Activation act, Activation linkedAct) {
288287

289288
@Override
290289
public Stream<Activation> getActivations(INeuron n, Activation linkedAct) {
291-
List<Activation> results = new ArrayList<>();
292-
collectNotAncestorOf(results, n, linkedAct);
293-
return results.stream();
290+
long v = linkedAct.doc.visitedCounter++;
291+
markAncestors(linkedAct, v);
292+
293+
INeuron.ThreadState th = n.getThreadState(linkedAct.doc.threadId, false);
294+
return th.getActivations()
295+
.filter(act -> act.markedAncDesc != v);
294296
}
295297
}
296298
}

src/test/java/network/aika/network/AncestorRelationTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public void testAncestorRelation2() {
198198
Assert.assertTrue(nC.getActivations(doc, true).collect(Collectors.toList()).isEmpty());
199199
}
200200

201-
@Ignore
201+
202202
@Test
203203
public void testNotAncestorOfRelation() {
204204
Model m = new Model();
@@ -239,8 +239,8 @@ public void testNotAncestorOfRelation() {
239239
.setBias(-10.0)
240240
.setRecurrent(false),
241241
new Relation.Builder()
242-
.setFrom(1)
243-
.setTo(OUTPUT)
242+
.setFrom(0)
243+
.setTo(1)
244244
.setRelation(NOT_ANCESTOR_OF),
245245
new Relation.Builder()
246246
.setFrom(0)
@@ -256,6 +256,7 @@ public void testNotAncestorOfRelation() {
256256
Document doc = m.createDocument("aaaaaaaaaa", 0);
257257

258258
inA.addInput(doc, 0, 1);
259+
inB.addInput(doc, 0, 1);
259260

260261
Activation outC1 = outC.getActivation(doc, 0, 1, false);
261262

0 commit comments

Comments
 (0)