Skip to content

Commit

Permalink
MODIFY_CONNECTIONS improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
wagenaartje committed Mar 26, 2017
1 parent f9bc9a5 commit fbb5eaf
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 20 deletions.
14 changes: 5 additions & 9 deletions dist/gynaptic.js
Original file line number Diff line number Diff line change
Expand Up @@ -4026,20 +4026,16 @@ Brain.prototype = {
case(Mutation.MODIFY_CONNECTIONS):
if(Math.random() >= 0.5){ // remove a connection
// select two random nodes, check if they are connected, then break the connection
// this can be improved by just liking at the projected conns of the selected node and removing that connection...
var node1Index;
var node2Index;
var connected = false;

while(connected == false){
var node1Index = Math.floor(Math.random() * (this.size[1] + this.size[0])); // can't be an output neuron
if(Mutation.MODIFY_CONNECTIONS.config.memory){ // memory connections are allowed
var node2Index = node1Index;
while(node1 == node2){
node2Index = Math.floor(Math.random() * (this.size[0] + this.size[1] + this.size[2]));
}
} else {
var minBound = Math.max(node1Index+1, this.size[0]);
var node2Index = Math.floor(Math.random() * (this.size[0] + this.size[1] + this.size[2] - minBound) + minBound);
node1Index = Math.floor(Math.random() * (this.size[1] + this.size[0])); // can't be an output neuron
node2Index = node1Index;
while(node1 == node2){
node2Index = Math.floor(Math.random() * (this.size[0] + this.size[1] + this.size[2]));
}

var node1 = this.nodes[node1Index];
Expand Down
2 changes: 1 addition & 1 deletion dist/gynaptic.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": "gynaptic",
"version": "1.0.3",
"version": "1.0.4",
"description": "architecture-free neural network library with genetic algorithm implementations",
"main": "./src/gynaptic",
"scripts": {
Expand Down
14 changes: 5 additions & 9 deletions src/brain.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,20 +213,16 @@ Brain.prototype = {
case(Mutation.MODIFY_CONNECTIONS):
if(Math.random() >= 0.5){ // remove a connection
// select two random nodes, check if they are connected, then break the connection
// this can be improved by just liking at the projected conns of the selected node and removing that connection...
var node1Index;
var node2Index;
var connected = false;

while(connected == false){
var node1Index = Math.floor(Math.random() * (this.size[1] + this.size[0])); // can't be an output neuron
if(Mutation.MODIFY_CONNECTIONS.config.memory){ // memory connections are allowed
var node2Index = node1Index;
while(node1 == node2){
node2Index = Math.floor(Math.random() * (this.size[0] + this.size[1] + this.size[2]));
}
} else {
var minBound = Math.max(node1Index+1, this.size[0]);
var node2Index = Math.floor(Math.random() * (this.size[0] + this.size[1] + this.size[2] - minBound) + minBound);
node1Index = Math.floor(Math.random() * (this.size[1] + this.size[0])); // can't be an output neuron
node2Index = node1Index;
while(node1 == node2){
node2Index = Math.floor(Math.random() * (this.size[0] + this.size[1] + this.size[2]));
}

var node1 = this.nodes[node1Index];
Expand Down

0 comments on commit fbb5eaf

Please sign in to comment.