Skip to content

Commit

Permalink
Changed pool to population
Browse files Browse the repository at this point in the history
put API in separate file
  • Loading branch information
aprowe committed Oct 3, 2016
1 parent b4f9d53 commit 8c51f53
Show file tree
Hide file tree
Showing 14 changed files with 251 additions and 246 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
.DS_STORE
1 change: 1 addition & 0 deletions Gruntfile.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ module.exports = (grunt)->
return src
src: [
'src/head.coffee',
'src/api.coffee',
'src/config.coffee',
'src/util.coffee',
'src/base.coffee',
Expand Down
36 changes: 19 additions & 17 deletions evo.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,25 @@ root = if window? then window else this

evo = {}


evo.population = (config)->
config = evo.util.extend evo.config.pool, config
return new Pool(config)

## Factory Function
evo.network = (type, genes, config)->
config = evo.util.extend evo.config.network, config

if type is 'feedforward'
return new FeedForward(genes, config)
else if type is 'cppn'
return new Cppn(genes, config)


## Configuration function to set defaults
evo.configure = (config)->
evo.config = evo.util.extend evo.config, config

## Default Configuration Object
evo.config =
pool:
Expand Down Expand Up @@ -104,10 +123,6 @@ root = if window? then window else this

input_nodes: 2

## Configuration function to set defaults
evo.configure = (config)->
evo.config = evo.util.extend evo.config, config

## Utility Functions
evo.util =

Expand Down Expand Up @@ -223,9 +238,6 @@ root = if window? then window else this
@config['on_'+name].call(this, args) if @config['on_' + name]?

## Pool Class
evo.pool = (config)->
config = evo.util.extend evo.config.pool, config
return new Pool(config)

class Pool extends Base
constructor: (@config)->
Expand Down Expand Up @@ -516,16 +528,6 @@ root = if window? then window else this
constructor: (@weights, @config)->
calc: (input)->

## Factory Function
evo.network = (type, genes, config)->
config = evo.util.extend evo.config.network, config

if type is 'feedforward'
return new FeedForward(genes, config)
else if type is 'cppn'
return new Cppn(genes, config)


## Compositional Pattern Producing Network

class Cppn extends Network
Expand Down
30 changes: 15 additions & 15 deletions evo.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,21 @@
})(function() {
var Base, Cppn, FeedForward, Network, Pool, evo;
evo = {};
evo.population = function(config) {
config = evo.util.extend(evo.config.pool, config);
return new Pool(config);
};
evo.network = function(type, genes, config) {
config = evo.util.extend(evo.config.network, config);
if (type === 'feedforward') {
return new FeedForward(genes, config);
} else if (type === 'cppn') {
return new Cppn(genes, config);
}
};
evo.configure = function(config) {
return evo.config = evo.util.extend(evo.config, config);
};
evo.config = {
pool: {
genes: 200,
Expand Down Expand Up @@ -60,9 +75,6 @@
input_nodes: 2
}
};
evo.configure = function(config) {
return evo.config = evo.util.extend(evo.config, config);
};
evo.util = {
random: function(min, max) {
if (min == null) {
Expand Down Expand Up @@ -234,10 +246,6 @@
return Base;

})();
evo.pool = function(config) {
config = evo.util.extend(evo.config.pool, config);
return new Pool(config);
};
Pool = (function(superClass) {
extend(Pool, superClass);

Expand Down Expand Up @@ -519,14 +527,6 @@
return Network;

})();
evo.network = function(type, genes, config) {
config = evo.util.extend(evo.config.network, config);
if (type === 'feedforward') {
return new FeedForward(genes, config);
} else if (type === 'cppn') {
return new Cppn(genes, config);
}
};
Cppn = (function(superClass) {
extend(Cppn, superClass);

Expand Down
2 changes: 1 addition & 1 deletion evo.min.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions examples/XOR.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
*/
var evo = require('evo-js');

var pool = evo.pool();
var population= evo.population();

pool.on('run', function(genes){
population.on('run', function(genes){
// Create a neural network
var net = evo.network('feedforward', genes, {
output_nodes: 1,
Expand All @@ -23,8 +23,8 @@ pool.on('run', function(genes){
});

// Run until score is 3.5 or greater
pool.run({
population.run({
score: 3.5
});

console.log("Took " + pool.generation + " generations to reach a score of " + pool.average);
console.log("Took " + population.generation + " generations to reach a score of " + population.average);
4 changes: 2 additions & 2 deletions specs/lineFitTest.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ describe "Line fitting test", ->
dist += Math.pow((poly(p.x) - p.y), 2)
return -dist;

pool = evo.pool({mutate_amount:10.0})
pool.on 'run', (genes)->
population = evo.population({mutate_amount:10.0})
population.on 'run', (genes)->
return evalGenes(genes)
Loading

0 comments on commit 8c51f53

Please sign in to comment.