Skip to content

Commit dd1a94b

Browse files
fixes
1 parent da2575e commit dd1a94b

File tree

4 files changed

+52
-8
lines changed

4 files changed

+52
-8
lines changed

src/main/java/network/aika/Model.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import network.aika.lattice.InputNode;
2121
import network.aika.lattice.Node;
2222
import network.aika.neuron.INeuron;
23+
import network.aika.neuron.INeuron.Type;
2324
import network.aika.neuron.Neuron;
2425
import network.aika.Provider.SuspensionMode;
2526
import network.aika.neuron.activation.Linker;
@@ -159,7 +160,13 @@ public Neuron createNeuron(String label) {
159160

160161

161162
public Neuron createNeuron(String label, String outputText) {
162-
INeuron n = new INeuron(this, label, outputText);
163+
INeuron n = new INeuron(this, label, outputText, null, ActivationFunction.RECTIFIED_HYPERBOLIC_TANGENT);
164+
return n.getProvider();
165+
}
166+
167+
168+
public Neuron createNeuron(String label, String outputText, Type type, ActivationFunction actF) {
169+
INeuron n = new INeuron(this, label, outputText, type, actF);
163170
return n.getProvider();
164171
}
165172

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public class INeuron extends AbstractNode<Neuron> implements Comparable<INeuron>
6363

6464

6565
public enum Type {
66+
INPUT,
6667
EXCITATORY,
6768
INHIBITORY
6869
}
@@ -80,7 +81,7 @@ public enum Type {
8081

8182
private Writable extension;
8283

83-
ActivationFunction activationFunction = ActivationFunction.RECTIFIED_HYPERBOLIC_TANGENT;
84+
ActivationFunction activationFunction;
8485

8586

8687
private volatile int synapseIdCounter = 0;
@@ -175,6 +176,11 @@ public Collection<Synapse> getPassiveInputSynapses() {
175176
}
176177

177178

179+
public void addRequiredSlot(int slot) {
180+
slotRequired.add(slot);
181+
}
182+
183+
178184
public ActivationFunction getActivationFunction() {
179185
return activationFunction;
180186
}
@@ -347,8 +353,11 @@ private INeuron() {
347353
}
348354

349355

350-
public INeuron(Model m, String label, String outputText) {
356+
public INeuron(Model m, String label, String outputText, Type type, ActivationFunction actF) {
351357
this.label = label;
358+
this.type = type;
359+
this.activationFunction = actF;
360+
352361
setOutputText(outputText);
353362

354363
if(m.getNeuronExtensionFactory() != null) {
@@ -741,6 +750,11 @@ public void updateBiasDelta(double biasDelta) {
741750
}
742751

743752

753+
public double getBias() {
754+
return bias;
755+
}
756+
757+
744758
public double getNewBias() {
745759
return bias + biasDelta;
746760
}

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

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import network.aika.neuron.INeuron.Type;
2626

2727
import java.util.*;
28+
import java.util.function.Predicate;
2829
import java.util.stream.Stream;
2930

3031
/**
@@ -292,30 +293,47 @@ public Activation getActivation(Document doc, int begin, int end, boolean onlyFi
292293
}
293294

294295

295-
public void addInMemoryInputSynapse(Synapse s) {
296+
public Synapse selectInputSynapse(Neuron inputNeuron, Predicate<Synapse> filter) {
297+
lock.acquireWriteLock();
298+
Synapse synapse = inMemoryInputSynapses.subMap(
299+
new Synapse(inputNeuron, this, Integer.MIN_VALUE), true,
300+
new Synapse(inputNeuron, this, Integer.MAX_VALUE), true
301+
)
302+
.keySet()
303+
.stream()
304+
.filter(filter)
305+
.findAny()
306+
.orElse(null);
307+
308+
lock.releaseWriteLock();
309+
return synapse;
310+
}
311+
312+
313+
void addInMemoryInputSynapse(Synapse s) {
296314
lock.acquireWriteLock();
297315
inMemoryInputSynapses.put(s, s);
298316
inputSynapsesById.put(s.getId(), s);
299317
lock.releaseWriteLock();
300318
}
301319

302320

303-
public void removeInMemoryInputSynapse(Synapse s) {
321+
void removeInMemoryInputSynapse(Synapse s) {
304322
lock.acquireWriteLock();
305323
inMemoryInputSynapses.remove(s);
306324
inputSynapsesById.remove(s.getId());
307325
lock.releaseWriteLock();
308326
}
309327

310328

311-
public void addInMemoryOutputSynapse(Synapse s) {
329+
void addInMemoryOutputSynapse(Synapse s) {
312330
lock.acquireWriteLock();
313331
inMemoryOutputSynapses.put(s, s);
314332
lock.releaseWriteLock();
315333
}
316334

317335

318-
public void removeInMemoryOutputSynapse(Synapse s) {
336+
void removeInMemoryOutputSynapse(Synapse s) {
319337
lock.acquireWriteLock();
320338
inMemoryOutputSynapses.remove(s);
321339
lock.releaseWriteLock();
@@ -345,6 +363,11 @@ public Collection<Synapse> getInMemoryInputSynapses() {
345363
}
346364

347365

366+
public Collection<Synapse> getInMemoryOutputSynapses() {
367+
return inMemoryOutputSynapses.values();
368+
}
369+
370+
348371
private static Collection<Synapse.Builder> getSynapseBuilders(Collection<Builder> builders) {
349372
ArrayList<Synapse.Builder> result = new ArrayList<>();
350373
for(Builder b: builders) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public Stream<Activation> getActivations(INeuron n, Activation linkedAct) {
107107

108108
@Override
109109
public void registerRequiredSlots(Neuron input) {
110-
input.get().slotRequired.add(fromSlot);
110+
input.get().addRequiredSlot(fromSlot);
111111
}
112112

113113

0 commit comments

Comments
 (0)