@@ -97,24 +97,29 @@ private void convertConjunction() {
9797 NodeContext nodeContext = null ;
9898 double remainingSum = ss .getPosDirSum ();
9999 int i = 0 ;
100+ boolean optionalInputMode = false ;
101+
100102 for (Synapse s : candidates ) {
101103 double v = s .getMaxInputValue ();
102- final boolean isOptionalInput = sum + remainingSum - v + ss .getPosRecSum () + ss .getPosPassiveSum () + ss .getBiasSum () > 0.0 ;
104+ if (sum + remainingSum - v + ss .getPosRecSum () + ss .getPosPassiveSum () + ss .getBiasSum () > 0.0 ) {
105+ optionalInputMode = true ;
106+ }
103107
104- if (!isOptionalInput ) {
105- remainingSum -= v ;
108+ if (!optionalInputMode ) {
106109
107110 NodeContext nlNodeContext = expandNode (nodeContext , s );
108111 if (nlNodeContext == null ) {
109- break ;
112+ return ;
110113 }
111114 nodeContext = nlNodeContext ;
115+
116+ remainingSum -= v ;
112117 sum += v ;
113118 i ++;
114119 } else {
115120 boolean belowThreshold = sum + v + remainingSum + ss .getPosRecSum () + ss .getPosPassiveSum () + ss .getBiasSum () <= 0.0 ;
116121 if (belowThreshold ) {
117- break ;
122+ return ;
118123 }
119124
120125 NodeContext nlNodeContext = expandNode (nodeContext , s );
@@ -126,11 +131,14 @@ private void convertConjunction() {
126131
127132 final boolean sumOfSynapseWeightsAboveThreshold = sum + ss .getPosRecSum () + ss .getPosPassiveSum () + ss .getBiasSum () > 0.0 ;
128133 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 ;
134+ if (sumOfSynapseWeightsAboveThreshold || maxAndNodesReached ) {
135+ break ;
132136 }
133137 }
138+
139+ if (nodeContext != null && !optionalInputMode ) {
140+ outputNode .addInput (nodeContext .getSynapseIds (), threadId , nodeContext .node , true );
141+ }
134142 }
135143
136144
0 commit comments