-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split src into a src folder
- Loading branch information
Showing
16 changed files
with
624 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
module.exports = (grunt) -> | ||
grunt.loadNpmTasks('grunt-contrib-coffee'); | ||
grunt.loadNpmTasks('grunt-contrib-concat'); | ||
grunt.loadNpmTasks('grunt-contrib-uglify'); | ||
grunt.loadNpmTasks('grunt-contrib-watch'); | ||
|
||
grunt.initConfig | ||
watch: | ||
concat: | ||
tasks: ['concat'] | ||
files: ['src/*.coffee'] | ||
|
||
|
||
concat: | ||
dist: | ||
options: | ||
process: (src, filepath) -> | ||
if filepath != 'src/head.coffee' && filepath != 'src/tail.coffee' | ||
lines = [] | ||
src.split('\n').forEach (line) -> | ||
lines.push( (if line.length > 0 then ' ' else '') + line) | ||
src = lines.join('\n') | ||
src[src.length-1] = '\n'if src[src.length-1] != '\n' | ||
return src | ||
src: [ | ||
'src/head.coffee', | ||
'src/config.coffee', | ||
'src/util.coffee', | ||
'src/base.coffee', | ||
'src/pool.coffee', | ||
'src/network.coffee', | ||
'src/cppn.coffee', | ||
'src/feedforward.coffee', | ||
'src/tail.coffee' | ||
] | ||
dest: 'evo.coffee' | ||
|
||
coffee: | ||
compile: | ||
files: | ||
'evo.js': 'evo.coffee' | ||
|
||
uglify: | ||
evo: | ||
files: | ||
'evo.min.js': 'evo.js' | ||
|
||
|
||
grunt.registerTask 'default', ['concat', 'coffee', 'uglify'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
## | ||
# evo.js v0.1 2/1/2015 | ||
# evo.js v0.1.0 | ||
# A genetic algorithm calculator with ANN | ||
# Copyright (c) 2015 Alex Rowe <[email protected]> | ||
# Licensed MIT | ||
|
@@ -19,10 +19,8 @@ | |
root.evo = factory.call root | ||
|
||
)(window? ? window : this, -> | ||
|
||
## Main Evo Object | ||
evo = {} | ||
|
||
evo = {} | ||
## Default Configuration Object | ||
evo.config = | ||
pool: | ||
|
@@ -69,7 +67,9 @@ | |
output_nodes: 3 | ||
input_nodes: 2 | ||
|
||
## Utility Functions | ||
evo.util = | ||
|
||
random: (min = -1, max = 1)-> | ||
(Math.random() * (max - min)) + min | ||
|
||
|
@@ -129,6 +129,7 @@ | |
|
||
return destination | ||
|
||
## Base Class | ||
class Base | ||
config: {} | ||
|
||
|
@@ -140,6 +141,8 @@ | |
@config['on_'+name].call(this, args) if @config['on_' + name]? | ||
|
||
|
||
## Pool Class | ||
|
||
class Pool extends Base | ||
constructor: (@config)-> | ||
|
||
|
@@ -321,11 +324,23 @@ | |
config = evo.util.extend evo.config.pool, config | ||
return new Pool(config) | ||
|
||
## Network Class | ||
|
||
class Network | ||
constructor: (genes, @config)-> | ||
calc: (input)-> | ||
|
||
## Factory Function | ||
evo.network = (type, weights, config)-> | ||
config = evo.util.extend evo.config.network, config | ||
|
||
if type is 'feedforward' | ||
return new FeedForward(weights, config) | ||
else if type is 'cppn' | ||
return new Cppn(weights, config) | ||
|
||
## Compositional Pattern Producing Network | ||
|
||
class Cppn extends Network | ||
@node_fn: [ | ||
evo.util.gaussian | ||
|
@@ -390,7 +405,8 @@ | |
output[j] = evo.util.tanh output[j] | ||
|
||
return output | ||
|
||
|
||
## Classic Feed Forward Network | ||
|
||
class FeedForward extends Network | ||
|
||
|
@@ -427,14 +443,7 @@ | |
|
||
return output_weights | ||
|
||
evo.network = (type, weights, config)-> | ||
config = evo.util.extend evo.config.network, config | ||
|
||
if type is 'feedforward' | ||
return new FeedForward(weights, config) | ||
else if type is 'cppn' | ||
return new Cppn(weights, config) | ||
|
||
return evo | ||
return evo | ||
) | ||
|
Oops, something went wrong.