Skip to content

Commit

Permalink
Added output function to CPPN
Browse files Browse the repository at this point in the history
  • Loading branch information
aprowe committed Nov 15, 2016
1 parent c5e7136 commit 2186122
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 35 deletions.
27 changes: 15 additions & 12 deletions evo.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,18 @@ root = if window? then window else this

class Network
constructor: (@weights, @config)->
if typeof @config.output_fn == 'function'
@output_fn = @config.output_fn

else if @config.output_fn == 'linear'
@output_fn = evo.util.linear

else if @config.output_fn == 'step'
@output_fn = evo.util.step

else
@output_fn = evo.util.tanh

calc: (input)->

## Compositional Pattern Producing Network
Expand Down Expand Up @@ -553,6 +565,7 @@ root = if window? then window else this


@weights = copy[..]
super @weights, @config

calc: (input)->
# input.push 0 while input.length < @config.input
Expand Down Expand Up @@ -591,7 +604,7 @@ root = if window? then window else this
# fn = @node_fn[@config.hidden_layers-1][i]
output[j] += hidden_weights[@config.hidden_layers-1][i] * copy.pop()

output[j] = evo.util.tanh output[j]
output[j] = @output_fn output[j]

return output

Expand All @@ -600,17 +613,7 @@ root = if window? then window else this
class FeedForward extends Network

constructor: (@weights, @config) ->
if typeof @config.output_fn == 'function'
@output_fn = @config.output_fn

else if @config.output_fn == 'linear'
@output_fn = evo.util.linear

else if @config.output_fn == 'step'
@output_fn = evo.util.step

else
@output_fn = evo.util.tanh
super @weights, @config

calc: (input)->
if input.length != @config.input_nodes
Expand Down
22 changes: 12 additions & 10 deletions evo.js
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,15 @@
function Network(weights, config1) {
this.weights = weights;
this.config = config1;
if (typeof this.config.output_fn === 'function') {
this.output_fn = this.config.output_fn;
} else if (this.config.output_fn === 'linear') {
this.output_fn = evo.util.linear;
} else if (this.config.output_fn === 'step') {
this.output_fn = evo.util.step;
} else {
this.output_fn = evo.util.tanh;
}
}

Network.prototype.calc = function(input) {};
Expand Down Expand Up @@ -554,6 +563,7 @@
}
}
this.weights = copy.slice(0);
Cppn.__super__.constructor.call(this, this.weights, this.config);
}

Cppn.prototype.calc = function(input) {
Expand Down Expand Up @@ -590,7 +600,7 @@
for (i = v = 0, ref7 = this.config.hidden_nodes - 1; 0 <= ref7 ? v <= ref7 : v >= ref7; i = 0 <= ref7 ? ++v : --v) {
output[j] += hidden_weights[this.config.hidden_layers - 1][i] * copy.pop();
}
output[j] = evo.util.tanh(output[j]);
output[j] = this.output_fn(output[j]);
}
return output;
};
Expand All @@ -604,15 +614,7 @@
function FeedForward(weights, config1) {
this.weights = weights;
this.config = config1;
if (typeof this.config.output_fn === 'function') {
this.output_fn = this.config.output_fn;
} else if (this.config.output_fn === 'linear') {
this.output_fn = evo.util.linear;
} else if (this.config.output_fn === 'step') {
this.output_fn = evo.util.step;
} else {
this.output_fn = evo.util.tanh;
}
FeedForward.__super__.constructor.call(this, this.weights, this.config);
}

FeedForward.prototype.calc = function(input) {
Expand Down
2 changes: 1 addition & 1 deletion evo.min.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/cppn.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Cppn extends Network


@weights = copy[..]
super @weights, @config

calc: (input)->
# input.push 0 while input.length < @config.input
Expand Down Expand Up @@ -61,6 +62,6 @@ class Cppn extends Network
# fn = @node_fn[@config.hidden_layers-1][i]
output[j] += hidden_weights[@config.hidden_layers-1][i] * copy.pop()

output[j] = evo.util.tanh output[j]
output[j] = @output_fn output[j]

return output
12 changes: 1 addition & 11 deletions src/feedforward.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,7 @@
class FeedForward extends Network

constructor: (@weights, @config) ->
if typeof @config.output_fn == 'function'
@output_fn = @config.output_fn

else if @config.output_fn == 'linear'
@output_fn = evo.util.linear

else if @config.output_fn == 'step'
@output_fn = evo.util.step

else
@output_fn = evo.util.tanh
super @weights, @config

calc: (input)->
if input.length != @config.input_nodes
Expand Down
12 changes: 12 additions & 0 deletions src/network.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,16 @@

class Network
constructor: (@weights, @config)->
if typeof @config.output_fn == 'function'
@output_fn = @config.output_fn

else if @config.output_fn == 'linear'
@output_fn = evo.util.linear

else if @config.output_fn == 'step'
@output_fn = evo.util.step

else
@output_fn = evo.util.tanh

calc: (input)->

0 comments on commit 2186122

Please sign in to comment.