Skip to content

Commit

Permalink
checkRelations
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasMolzberger committed Dec 1, 2018
1 parent ff8703c commit 14d9a28
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
10 changes: 8 additions & 2 deletions src/main/java/network/aika/neuron/activation/Linker.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,19 @@ protected void link(Synapse s, Activation iAct, Activation oAct) {

private boolean checkRelations(Synapse s, Activation iAct, Activation oAct) {
for(Map.Entry<Integer, Relation> me: s.relations.entrySet()) {
Integer relSynId = me.getKey();
Relation rel = me.getValue();
if(me.getKey() == Synapse.OUTPUT) {
if(relSynId == Synapse.OUTPUT) {
if (!rel.test(iAct, oAct)) {
return false;
}
} else {
Synapse relSyn = oAct.getNeuron().getSynapseById(relSynId);
if(relSyn!= null && oAct.getInputLinksBySynapse(false, relSyn)
.anyMatch(l -> !rel.test(iAct, l.input))) {
return false;
}
}
// TODO: other relations
}

return true;
Expand Down
15 changes: 12 additions & 3 deletions src/test/java/network/aika/network/PositionRelationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -273,15 +273,24 @@ public void testOptionalRelation() {
new Relation.Builder()
.setFrom(0)
.setTo(1)
.setRelation(new MultiRelation(new Equals(END, BEGIN, true, true), new LessThan(BEGIN, BEGIN, false, false, false, Integer.MAX_VALUE))),
.setRelation(new MultiRelation(
new Equals(END, BEGIN, true, true),
new LessThan(BEGIN, BEGIN, false, false, false, Integer.MAX_VALUE)
)),
new Relation.Builder()
.setFrom(1)
.setTo(1)
.setRelation(new MultiRelation(new Equals(END, BEGIN, true, true), new LessThan(BEGIN, BEGIN, false, false, false, Integer.MAX_VALUE))),
.setRelation(new MultiRelation(
new Equals(END, BEGIN, true, true),
new LessThan(BEGIN, BEGIN, false, false, false, Integer.MAX_VALUE)
)),
new Relation.Builder()
.setFrom(1)
.setTo(2)
.setRelation(new MultiRelation(new Equals(END, BEGIN, true, true), new LessThan(BEGIN, BEGIN, false, false, false, Integer.MAX_VALUE))),
.setRelation(new MultiRelation(
new Equals(END, BEGIN, true, true),
new LessThan(BEGIN, BEGIN, false, false, false, Integer.MAX_VALUE)
)),
new Relation.Builder()
.setFrom(0)
.setTo(OUTPUT)
Expand Down

0 comments on commit 14d9a28

Please sign in to comment.