Skip to content

Commit

Permalink
Fixed #14
Browse files Browse the repository at this point in the history
  • Loading branch information
wagenaartje committed May 10, 2017
1 parent 34a731a commit a64a36f
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 21 deletions.
21 changes: 15 additions & 6 deletions dist/neataptic.js
Original file line number Diff line number Diff line change
Expand Up @@ -2004,17 +2004,26 @@ var Architect = {
}
}

// Calculate input and output size
for(var node in nodes){
if(nodes[node].connections.out.length + nodes[node].connections.gated.length == 0){
nodes[node].type = 'output';
// Determine input and output nodes
var inputs = [];
var outputs = [];
for(var i = nodes.length - 1; i >= 0; i--){
if(nodes[i].connections.out.length + nodes[i].connections.gated.length == 0){
nodes[i].type = 'output';
network.output++;
} else if(!nodes[node].connections.in.length){
nodes[node].type = 'input';
outputs.push(nodes[i]);
nodes.splice(i, 1);
} else if(!nodes[i].connections.in.length){
nodes[i].type = 'input';
network.input++;
inputs.push(nodes[i]);
nodes.splice(i, 1);
}
}

// Input nodes are always first, output nodes are always last
nodes = inputs.concat(nodes).concat(outputs);

if(network.input == 0 || network.output == 0){
throw new Error('Given nodes have no clear input/output node!');
}
Expand Down
2 changes: 1 addition & 1 deletion dist/neataptic.min.js

Large diffs are not rendered by default.

21 changes: 15 additions & 6 deletions docs/cdn/neataptic.js
Original file line number Diff line number Diff line change
Expand Up @@ -2004,17 +2004,26 @@ var Architect = {
}
}

// Calculate input and output size
for(var node in nodes){
if(nodes[node].connections.out.length + nodes[node].connections.gated.length == 0){
nodes[node].type = 'output';
// Determine input and output nodes
var inputs = [];
var outputs = [];
for(var i = nodes.length - 1; i >= 0; i--){
if(nodes[i].connections.out.length + nodes[i].connections.gated.length == 0){
nodes[i].type = 'output';
network.output++;
} else if(!nodes[node].connections.in.length){
nodes[node].type = 'input';
outputs.push(nodes[i]);
nodes.splice(i, 1);
} else if(!nodes[i].connections.in.length){
nodes[i].type = 'input';
network.input++;
inputs.push(nodes[i]);
nodes.splice(i, 1);
}
}

// Input nodes are always first, output nodes are always last
nodes = inputs.concat(nodes).concat(outputs);

if(network.input == 0 || network.output == 0){
throw new Error('Given nodes have no clear input/output node!');
}
Expand Down
2 changes: 1 addition & 1 deletion docs/cdn/neataptic.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "neataptic",
"version": "1.1.1",
"version": "1.1.2",
"description": "Architecture-free neural network library with genetic algorithm implementations",
"main": "./src/neataptic",
"scripts": {
Expand Down
21 changes: 15 additions & 6 deletions src/architect.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,26 @@ var Architect = {
}
}

// Calculate input and output size
for(var node in nodes){
if(nodes[node].connections.out.length + nodes[node].connections.gated.length == 0){
nodes[node].type = 'output';
// Determine input and output nodes
var inputs = [];
var outputs = [];
for(var i = nodes.length - 1; i >= 0; i--){
if(nodes[i].connections.out.length + nodes[i].connections.gated.length == 0){
nodes[i].type = 'output';
network.output++;
} else if(!nodes[node].connections.in.length){
nodes[node].type = 'input';
outputs.push(nodes[i]);
nodes.splice(i, 1);
} else if(!nodes[i].connections.in.length){
nodes[i].type = 'input';
network.input++;
inputs.push(nodes[i]);
nodes.splice(i, 1);
}
}

// Input nodes are always first, output nodes are always last
nodes = inputs.concat(nodes).concat(outputs);

if(network.input == 0 || network.output == 0){
throw new Error('Given nodes have no clear input/output node!');
}
Expand Down

0 comments on commit a64a36f

Please sign in to comment.