Skip to content

Commit

Permalink
removed old examples updated XOR
Browse files Browse the repository at this point in the history
  • Loading branch information
aprowe committed Jan 24, 2016
1 parent 3ebadfd commit 6a4e4c9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 177 deletions.
67 changes: 19 additions & 48 deletions examples/XOR.js
Original file line number Diff line number Diff line change
@@ -1,59 +1,30 @@
/*
* This example trains a neural network to solve the XOR problem
*/
var evo = require('evo-js');

var evo = require('../evo.js');
var pool = evo.pool();

var pool = evo.pool({
n_genes: 10, // Number of genes of each object
size: 400, // Size of pool

cross_rate: 0.10,
mutate_rate: 0.7,
mutate_amount: 1.85,

ratios: {
top: 1.00,
cross: 0.33,
mutate: 2.00,
fresh: 0.20,
meld: 0.75,
random: 1.25,
}

});

pool.on ('spawn', function(genes){
pool.on('run', function(genes){
// Create a neural network
var net = evo.network('feedforward', genes, {
output_nodes: 1,
hidden_nodes: 2,
hidden_nodes: 2,
input_nodes: 2
});

return net;
});

// Show the average each generation
pool.on('breed', function(){
// console.log(this.average);
// Create a score based on the networks output
var score = 0;
score += net.calc([-1, -1]) > 0 ? 1 : 0;
score += net.calc([ 1, 1]) > 0 ? 1 : 0;
score += net.calc([ 1, -1]) < 0 ? 1 : 0;
score += net.calc([-1, 1]) < 0 ? 1 : 0;
return score;
});

pool.on('run', function(){
var net = this.spawn()

// Max score is 4 if it correctly classifies all points
net.score += net.calc([-1, -1]) > 0 ? 1 : 0;
net.score += net.calc([ 1, 1]) > 0 ? 1 : 0;
net.score += net.calc([ 1, -1]) < 0 ? 1 : 0;
net.score += net.calc([-1, 1]) < 0 ? 1 : 0;

this.report(net)
});

// Run 300 generations
// pool.run(300);


// Run until function returns true
pool.run(function(){
return this.average > 3.50
// Run until score is 3.5 or greater
pool.run({
score: 3.5
});

console.log('Took ' + pool.generation + " generations to reach a score of " + pool.average);
console.log("Took " + pool.generation + " generations to reach a score of " + pool.average);
53 changes: 0 additions & 53 deletions examples/letters.js

This file was deleted.

74 changes: 0 additions & 74 deletions examples/metapool.js

This file was deleted.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "evo-js",
"version": "0.2.1",
"description": "Genetic Algorithm Calculator with ANN",
"description": "Evolutionary Algorithm Tool wrapped with ANN",
"main": "evo.js",
"scripts": {
"test": "grunt test"
Expand Down Expand Up @@ -33,5 +33,6 @@
"grunt-contrib-uglify": "~0.5.0",
"grunt-contrib-watch": "^0.6.1",
"grunt-execute": "^0.2.2"
}
},
"tonicExampleFilename":"examples/XOR.js"
}

0 comments on commit 6a4e4c9

Please sign in to comment.