Skip to content

Commit

Permalink
Introduced Grunt and Package.json
Browse files Browse the repository at this point in the history
Split src into a src folder
  • Loading branch information
aprowe committed Mar 4, 2015
1 parent 0de8367 commit c8f1243
Show file tree
Hide file tree
Showing 16 changed files with 624 additions and 87 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
49 changes: 49 additions & 0 deletions Gruntfile.coffee
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']
35 changes: 22 additions & 13 deletions evo.coffee
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
Expand All @@ -19,10 +19,8 @@
root.evo = factory.call root

)(window? ? window : this, ->

## Main Evo Object
evo = {}

evo = {}
## Default Configuration Object
evo.config =
pool:
Expand Down Expand Up @@ -69,7 +67,9 @@
output_nodes: 3
input_nodes: 2

## Utility Functions
evo.util =

random: (min = -1, max = 1)->
(Math.random() * (max - min)) + min

Expand Down Expand Up @@ -129,6 +129,7 @@

return destination

## Base Class
class Base
config: {}

Expand All @@ -140,6 +141,8 @@
@config['on_'+name].call(this, args) if @config['on_' + name]?


## Pool Class

class Pool extends Base
constructor: (@config)->

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -390,7 +405,8 @@
output[j] = evo.util.tanh output[j]

return output


## Classic Feed Forward Network

class FeedForward extends Network

Expand Down Expand Up @@ -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
)

Loading

0 comments on commit c8f1243

Please sign in to comment.