|
18 | 18 |
|
19 | 19 | import network.aika.Document; |
20 | 20 | import network.aika.neuron.INeuron; |
| 21 | +import network.aika.neuron.INeuron.SynapseSummary; |
21 | 22 | import network.aika.neuron.Synapse; |
22 | 23 | import network.aika.neuron.relation.Relation; |
23 | 24 |
|
@@ -69,82 +70,77 @@ private boolean convert() { |
69 | 70 |
|
70 | 71 | initSlotFlags(); |
71 | 72 |
|
72 | | - INeuron.SynapseSummary ss = neuron.getSynapseSummary(); |
| 73 | + SynapseSummary ss = neuron.getSynapseSummary(); |
73 | 74 |
|
74 | 75 | if(ss.getBiasSum() + ss.getPosDirSum() + ss.getPosRecSum() <= 0.0) { |
75 | 76 | outputNode.removeParents(threadId); |
76 | 77 | return false; |
77 | 78 | } |
78 | 79 |
|
79 | | - List<Synapse> candidates = prepareCandidates(); |
| 80 | + if(ss.getNumDisjunctiveSynapses() == 0) { |
| 81 | + convertConjunction(); |
| 82 | + } else { |
| 83 | + convertDisjunction(); |
| 84 | + } |
80 | 85 |
|
81 | | - NodeContext nodeContext = null; |
82 | | - boolean noFurtherRefinement = false; |
83 | | - TreeSet<Synapse> reqSyns = new TreeSet<>(Synapse.INPUT_SYNAPSE_COMP); |
84 | | - double sum = 0.0; |
| 86 | + return true; |
| 87 | + } |
85 | 88 |
|
86 | | - if(ss.getNumDisjunctiveSynapses() == 0) { |
87 | | - double remainingSum = ss.getPosDirSum(); |
88 | | - int i = 0; |
89 | | - for (Synapse s : candidates) { |
90 | | - double v = s.getMaxInputValue(); |
91 | | - final boolean isOptionalInput = sum + remainingSum - v + ss.getPosRecSum() + ss.getPosPassiveSum() + ss.getBiasSum() > 0.0; |
92 | | - final boolean maxAndNodesReached = i >= MAX_AND_NODE_SIZE; |
93 | | - if (isOptionalInput || maxAndNodesReached) { |
94 | | - break; |
95 | | - } |
96 | 89 |
|
| 90 | + private void convertConjunction() { |
| 91 | + SynapseSummary ss = neuron.getSynapseSummary(); |
| 92 | + |
| 93 | + outputNode.removeParents(threadId); |
| 94 | + |
| 95 | + List<Synapse> candidates = prepareCandidates(); |
| 96 | + double sum = 0.0; |
| 97 | + NodeContext nodeContext = null; |
| 98 | + double remainingSum = ss.getPosDirSum(); |
| 99 | + int i = 0; |
| 100 | + for (Synapse s : candidates) { |
| 101 | + double v = s.getMaxInputValue(); |
| 102 | + final boolean isOptionalInput = sum + remainingSum - v + ss.getPosRecSum() + ss.getPosPassiveSum() + ss.getBiasSum() > 0.0; |
| 103 | + |
| 104 | + if (!isOptionalInput) { |
97 | 105 | remainingSum -= v; |
98 | | - reqSyns.add(s); |
99 | 106 |
|
100 | 107 | NodeContext nlNodeContext = expandNode(nodeContext, s); |
101 | | - if(nlNodeContext == null) { |
| 108 | + if (nlNodeContext == null) { |
102 | 109 | break; |
103 | 110 | } |
104 | 111 | nodeContext = nlNodeContext; |
105 | | - |
106 | | - i++; |
107 | | - |
108 | 112 | sum += v; |
109 | | - |
110 | | - final boolean sumOfSynapseWeightsAboveThreshold = sum + ss.getPosRecSum() + ss.getPosPassiveSum() + ss.getBiasSum() > 0.0; |
111 | | - if (sumOfSynapseWeightsAboveThreshold) { |
112 | | - noFurtherRefinement = true; |
| 113 | + i++; |
| 114 | + } else { |
| 115 | + boolean belowThreshold = sum + v + remainingSum + ss.getPosRecSum() + ss.getPosPassiveSum() + ss.getBiasSum() <= 0.0; |
| 116 | + if (belowThreshold) { |
113 | 117 | break; |
114 | 118 | } |
115 | | - } |
116 | | - |
117 | | - outputNode.removeParents(threadId); |
118 | 119 |
|
119 | | - if (noFurtherRefinement || (i > 0 && (i == MAX_AND_NODE_SIZE || i == candidates.size()))) { |
120 | | - outputNode.addInput(nodeContext.getSynapseIds(), threadId, nodeContext.node, true); |
121 | | - } else { |
122 | | - for (Synapse s : candidates) { |
123 | | - double v = s.getMaxInputValue(); |
124 | | - boolean belowThreshold = sum + v + remainingSum + ss.getPosRecSum() + ss.getPosPassiveSum() + ss.getBiasSum() <= 0.0; |
125 | | - if (belowThreshold) { |
126 | | - break; |
127 | | - } |
128 | | - |
129 | | - if (!reqSyns.contains(s)) { |
130 | | - NodeContext nlNodeContext = expandNode(nodeContext, s); |
131 | | - if(nlNodeContext != null) { |
132 | | - outputNode.addInput(nlNodeContext.getSynapseIds(), threadId, nlNodeContext.node, true); |
133 | | - remainingSum -= v; |
134 | | - } |
135 | | - } |
| 120 | + NodeContext nlNodeContext = expandNode(nodeContext, s); |
| 121 | + if (nlNodeContext != null) { |
| 122 | + outputNode.addInput(nlNodeContext.getSynapseIds(), threadId, nlNodeContext.node, true); |
| 123 | + remainingSum -= v; |
136 | 124 | } |
137 | 125 | } |
138 | | - } else { |
139 | | - for (Synapse s : modifiedSynapses) { |
140 | | - if (s.isDisjunction() && !s.isRecurrent()) { |
141 | | - NodeContext nlNodeContext = expandNode(nodeContext, s); |
142 | | - outputNode.addInput(nlNodeContext.getSynapseIds(), threadId, nlNodeContext.node, false); |
143 | | - } |
| 126 | + |
| 127 | + final boolean sumOfSynapseWeightsAboveThreshold = sum + ss.getPosRecSum() + ss.getPosPassiveSum() + ss.getBiasSum() > 0.0; |
| 128 | + final boolean maxAndNodesReached = i >= MAX_AND_NODE_SIZE; |
| 129 | + if (sumOfSynapseWeightsAboveThreshold || maxAndNodesReached || i == candidates.size()) { |
| 130 | + outputNode.addInput(nodeContext.getSynapseIds(), threadId, nodeContext.node, true); |
| 131 | + return; |
144 | 132 | } |
145 | 133 | } |
| 134 | + } |
146 | 135 |
|
147 | | - return true; |
| 136 | + |
| 137 | + private void convertDisjunction() { |
| 138 | + for (Synapse s : modifiedSynapses) { |
| 139 | + if (s.isDisjunction() && !s.isRecurrent()) { |
| 140 | + NodeContext nlNodeContext = expandNode(null, s); |
| 141 | + outputNode.addInput(nlNodeContext.getSynapseIds(), threadId, nlNodeContext.node, false); |
| 142 | + } |
| 143 | + } |
148 | 144 | } |
149 | 145 |
|
150 | 146 |
|
|
0 commit comments