Skip to content

Commit

Permalink
Moved methods to subfolder
Browse files Browse the repository at this point in the history
Continued work on brain.js
  • Loading branch information
wagenaartje committed Mar 23, 2017
1 parent fa431c3 commit 0433b84
Show file tree
Hide file tree
Showing 22 changed files with 801 additions and 456 deletions.
667 changes: 432 additions & 235 deletions dist/gynaptic.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/gynaptic.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/examples/xor/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

<!-- Gynaptic -->
<script src="https://cdn.rawgit.com/wagenaartje/gynaptic/55b6d0d1/dist/gynaptic.js"></script>
<script src="https://cdn.rawgit.com/wagenaartje/gynaptic/cf8fbd71/dist/gynaptic.js"></script>

<!-- Custom -->
<link rel="stylesheet" href="../../css/main.css">
Expand Down
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<link rel="stylesheet" href="css/google.css">

<!-- Gynaptic -->
<script src="https://cdn.rawgit.com/wagenaartje/gynaptic/8a08f2e9/dist/gynaptic.js"></script>
<script src="https://cdn.rawgit.com/wagenaartje/gynaptic/cf8fbd71/dist/gynaptic.js"></script>

<!-- Custom -->
<link rel="stylesheet" href="css/main.css">
Expand Down
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.0",
"version": "1.0.1",
"description": "architecture-free neural network library with genetic algorithm implementations",
"main": "./src/gynaptic",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/architect.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
var Layer = require('./layer')
, Network = require('./network')
, Trainer = require('./trainer')
, methods = require('./methods');
, methods = require('./methods/methods.js');

/* Shorten var names */
var Mutate = methods.Mutate
Expand Down
75 changes: 74 additions & 1 deletion src/brain.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ if (module) module.exports = Brain;
/* Import */
var Neuron = require('./neuron')
, Layer = require('./layer')
, methods = require('./methods')
, methods = require('./methods/methods.js');

/* Shorten var names */
var Mutate = methods.Mutate
Expand Down Expand Up @@ -152,5 +152,78 @@ Brain.prototype = {
}
},

/**
* Mutates the brain
*/

mutate: function(method){
method = method || Mutate.MODIFY_RANDOM_WEIGHT;
switch(method){
case(Mutate.SWAP_WEIGHT):
break;
case(Mutate.MODIFY_RANDOM_WEIGHT):
break;
case(Mutate.MODIFY_CONNECTIONS):
break;
case(Mutate.MODIFY_NODES):
if(Math.random() >= 0.5){
// remove a node
} else {
// add a node
var random = Math.floor(Math.random() * 3);
switch(random){
case(0): // network
console.log('here');
// create a randomly sized network
var size = Math.floor(Math.random() * (Mutate.MODIFY_NODES.config.network.size[1] - Mutate.MODIFY_NODES.config.network.size[0]) + Mutate.MODIFY_NODES.config.network.size[0]);
var hiddenSize = Math.min(size-2, Math.floor(Math.random() * (Mutate.MODIFY_NODES.config.network.hidden[1] - Mutate.MODIFY_NODES.config.network.hidden[0]) + Mutate.MODIFY_NODES.config.network.hidden[0]));

var layers = '';

// x amount of size must be left for remaining layers and output
var inputLayerSize = Math.floor(Math.random() * (size-(hiddenSize)-1) + 1);
size -= inputLayerSize;
layers += inputLayerSize + ', ';

var hiddenLayerSizes = [];
for(var i = 0; i < hiddenSize; i++){
var hiddenLayerSize = Math.floor(Math.random() * (size-(hiddenSize - (i + 1) + 1)-1) + 1);
hiddenLayerSizes.push(hiddenLayerSize);
size -= hiddenLayerSize;
layers += hiddenLayerSize + ', ';
}

var outputLayerSize = size;
layers += outputLayerSize;

var node = eval('new Architect.Perceptron(' + layers + ')');

// must be inserted after input and before output
var insert = Math.floor(Math.random() * this.size[1] + this.size[0]);
this.nodes.splice(insert, 0, node);
this.size[1]++;

// now project it to another neurons ( should also be done with ratio, will be implemented later)
var minBound = Math.max(insert+1, this.size[0]);
var input = Math.floor(Math.random() * (this.size[0] + this.size[1] + this.size[2] - minBound) + minBound); // an input node can't connected to an output node, this creates BIAS (?)
this.nodes[insert].project(this.nodes[input]);

// now let it have an input connection
var output = Math.floor(Math.random() * insert);
this.nodes[output].project(this.nodes[insert]);
break;
case(1): // layer
break;
case(2): // neuron
break;
}
}
break;
case(Mutate.MUTATE_NODES):
break;
}

}


};
2 changes: 1 addition & 1 deletion src/evolution.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ if (module) module.exports = Evolution;
var Layer = require('./layer')
, Network = require('./network')
, Trainer = require('./trainer')
, methods = require('./methods');
, methods = require('./methods/methods.js');

/* Shorten var names */
var Mutate = methods.Mutate
Expand Down
16 changes: 8 additions & 8 deletions src/gynaptic.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
var Gynaptic = {
Neuron: require('./neuron'),
Evolution: require('./evolution'),
Trainer: require('./trainer'),
Methods: require('./methods'),
Layer: require('./layer'),
Network: require('./network'),
Architect: require('./architect'),
Brain: require('./brain')
Neuron : require('./neuron'),
Evolution : require('./evolution'),
Trainer : require('./trainer'),
Methods : require('./methods/methods.js'),
Layer : require('./layer'),
Network : require('./network'),
Architect : require('./architect'),
Brain : require('./brain')
};

// CommonJS & AMD
Expand Down
2 changes: 1 addition & 1 deletion src/layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ if (module) module.exports = Layer;
/* Import */
var Neuron = require('./neuron')
, Network = require('./network')
, methods = require('./methods')
, methods = require('./methods/methods.js');

/* Shorten var names */
var Mutate = methods.Mutate
Expand Down
201 changes: 0 additions & 201 deletions src/methods.js

This file was deleted.

12 changes: 12 additions & 0 deletions src/methods/connection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*******************************************************************************************
CONNECTIONS
*******************************************************************************************/

var Connection = {
ALL_TO_ALL : "ALL TO ALL",
ONE_TO_ONE : "ONE TO ONE",
ALL_TO_ELSE : "ALL TO ELSE"
};

/* Export */
if (module) module.exports = Connection;
Loading

0 comments on commit 0433b84

Please sign in to comment.