summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mind/topology.js7
-rw-r--r--src/mind/topology.test.js25
2 files changed, 18 insertions, 14 deletions
diff --git a/src/mind/topology.js b/src/mind/topology.js
index 5d4d52c..8e59c54 100644
--- a/src/mind/topology.js
+++ b/src/mind/topology.js
@@ -116,13 +116,14 @@ function get_value(n, index, input, prev, cache) {
}
const adj = n.adjacency[index]; // get adjacency list
- const incident = incident_edges(n, adj); // get incident edges
+ const incident = incident_edges(n, adj); // get incident edges
const weight = incident.map(x => n.weight[x]); // edge weights
const sources = incident // get ancestor nodes
.map(x => edge_ends(n, x).source);
- const values = sources // get the value of each ancestor
- .map(x => x === index // if the ancestor is this node
+ // get the value of each ancestor
+ const values = sources
+ .map(x => x === index // if the ancestor is this node
? prev[x - n.input_count] // then the value is the previous value
: get_value(n, x, input, prev, cache)); // else recurse
diff --git a/src/mind/topology.test.js b/src/mind/topology.test.js
index b272040..9776132 100644
--- a/src/mind/topology.test.js
+++ b/src/mind/topology.test.js
@@ -175,17 +175,20 @@ test('arbitrary hidden neurons', () => {
.connect(1, 2, -1)
.connect(2, 3, 2)
- expect(n.compute([1], [0, 0])).toEqual([
- [ Math.tanh (
- 2*Math.tanh(
- -1*Math.tanh( 1 )
- )
- ) ],
- [
- Math.tanh( -Math.tanh(1) ),
- Math.tanh(1),
- ],
- ]);
+ const [output, state] = n.compute([1], [0, 0]);
+
+ expect(output).toEqual([
+ Math.tanh(
+ 2*Math.tanh(
+ -1*Math.tanh(1)
+ )
+ )
+ ]);
+
+ expect(state).toEqual([
+ Math.tanh(1),
+ Math.tanh( -Math.tanh(1) ),
+ ]);
});