Skip to content

Commit afb9703

Browse files
author
Lukas Molzberger
committed
read and write for model labels
1 parent f8ef687 commit afb9703

File tree

2 files changed

+58
-39
lines changed

2 files changed

+58
-39
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,13 @@ public void delete(Set<String> modelLabels) {
746746
});
747747

748748
inputNode.delete(modelLabels);
749+
750+
Provider on = getOutputNode();
751+
if(on != null && !on.get().getModelLabels().isEmpty()) {
752+
on.get().getModelLabels().forEach(ml ->
753+
log.warn("Dependend model: " + ml)
754+
);
755+
}
749756
}
750757

751758
public void setBias(double b) {

src/test/java/network/aika/network/SuspensionTest.java

Lines changed: 51 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -119,17 +119,7 @@ public void testSuspendAndNeuron() {
119119

120120
// Reactivate
121121

122-
Document doc = new Document(m, "Bla");
123-
124-
inA = m.lookupNeuron(idA);
125-
inA.addInput(doc, 0, 1);
126-
127-
inB = m.lookupNeuron(idB);
128-
inB.addInput(doc, 1, 2);
129-
130-
doc.process();
131-
132-
System.out.println(doc.activationsToString());
122+
Document doc = processTestDocument(m, idA, idB);
133123

134124
Assert.assertFalse(outD.getActivations(doc, true).collect(Collectors.toList()).isEmpty());
135125
}
@@ -246,33 +236,7 @@ public void testSuspendAndNeuronWithDeletion() {
246236
int idA = inA.getId();
247237
int idB = inB.getId();
248238

249-
Neuron nC = Neuron.init(m.createNeuron("C", EXCITATORY),
250-
5.0,
251-
new Synapse.Builder()
252-
.setSynapseId(0)
253-
.setNeuron(inA)
254-
.setWeight(10.0)
255-
.setRecurrent(false),
256-
new Synapse.Builder()
257-
.setSynapseId(1)
258-
.setNeuron(inB)
259-
.setWeight(10.0)
260-
.setRecurrent(false),
261-
new Relation.Builder()
262-
.setFrom(0)
263-
.setTo(1)
264-
.setRelation(END_TO_BEGIN_EQUALS),
265-
new Relation.Builder()
266-
.setFrom(0)
267-
.setTo(OUTPUT)
268-
.setRelation(BEGIN_EQUALS),
269-
new Relation.Builder()
270-
.setFrom(1)
271-
.setTo(OUTPUT)
272-
.setRelation(END_EQUALS)
273-
);
274-
275-
nC.get().addModelLabel("TestModel");
239+
Neuron nC = initNeuronC(m, inA, inB);
276240

277241
Neuron outD = Neuron.init(m.createNeuron("D", EXCITATORY),
278242
6.0,
@@ -298,6 +262,24 @@ public void testSuspendAndNeuronWithDeletion() {
298262

299263
// Reactivate
300264

265+
Document doc = processTestDocument(m, idA, idB);
266+
267+
Assert.assertTrue(outD.getActivations(doc, true).collect(Collectors.toList()).isEmpty());
268+
269+
Neuron nCNew = initNeuronC(m, inA, inB);
270+
271+
Assert.assertNotEquals(nC.getId(), nCNew.getId());
272+
273+
doc.clearActivations();
274+
275+
doc = processTestDocument(m, idA, idB);
276+
277+
Assert.assertFalse(nCNew.getActivations(doc, true).collect(Collectors.toList()).isEmpty());
278+
}
279+
280+
public Document processTestDocument(Model m, int idA, int idB) {
281+
Neuron inA;
282+
Neuron inB;
301283
Document doc = new Document(m, "Bla");
302284

303285
inA = m.lookupNeuron(idA);
@@ -309,7 +291,37 @@ public void testSuspendAndNeuronWithDeletion() {
309291
doc.process();
310292

311293
System.out.println(doc.activationsToString());
294+
return doc;
295+
}
312296

313-
Assert.assertFalse(outD.getActivations(doc, true).collect(Collectors.toList()).isEmpty());
297+
public Neuron initNeuronC(Model m, Neuron inA, Neuron inB) {
298+
Neuron nC = Neuron.init(m.createNeuron("C", EXCITATORY),
299+
5.0,
300+
new Synapse.Builder()
301+
.setSynapseId(0)
302+
.setNeuron(inA)
303+
.setWeight(10.0)
304+
.setRecurrent(false),
305+
new Synapse.Builder()
306+
.setSynapseId(1)
307+
.setNeuron(inB)
308+
.setWeight(10.0)
309+
.setRecurrent(false),
310+
new Builder()
311+
.setFrom(0)
312+
.setTo(1)
313+
.setRelation(END_TO_BEGIN_EQUALS),
314+
new Builder()
315+
.setFrom(0)
316+
.setTo(OUTPUT)
317+
.setRelation(BEGIN_EQUALS),
318+
new Builder()
319+
.setFrom(1)
320+
.setTo(OUTPUT)
321+
.setRelation(END_EQUALS)
322+
);
323+
324+
nC.get().addModelLabel("TestModel");
325+
return nC;
314326
}
315327
}

0 commit comments

Comments
 (0)