lib/rubyneat/dsl.rb in rubyneat-0.3.5.alpha.6 vs lib/rubyneat/dsl.rb in rubyneat-0.4.0.alpha.3
- old
+ new
@@ -1,6 +1,6 @@
-require 'rubyneat/rubyneat'
+require_relative 'rubyneat'
=begin rdoc
= RubyNEAT DSL
DSL is a domain-specific language for RubyNEAT to allow you to configure the NEAT engine
for various evolutionary projects.
@@ -40,42 +40,43 @@
# Query function is called with the sequence (time evolution) number,
# and returns an array or hash of parameters that will be given
# to the input nodes. In the case of hash, the keys in the hash
# shall correspond to the names given to the input neurons.
def query(&block)
- NEAT::controller.query_func = block
+ NEAT::controller.query_func_add &block
end
def recurrence(&block)
- NEAT::controller.recurrence_func = block
+ NEAT::controller.recurrence_func_set &block
end
# fitness function calls the block with 2 vectors or two hashes, input and output
# vectors of the critter being evaluated for fitness, as well as a sequence
# number that can be used to index what the actual output should be.
# |vin, vout, seq|
def fitness(&block)
- NEAT::controller.fitness_func = block
+ NEAT::controller.fitness_func_set &block
end
# Fitness ordering -- given 2 fitness numbers,
# use the <=> to compare them (or the equivalent, following
# the +1, 0, -1 that is in the sense of <=>)
def compare(&block)
- NEAT::controller.compare_func = block
+ NEAT::controller.compare_func_set &block
end
# Calculation to add the cost to the fitness, resulting in a fitness
# that incorporates the cost for sorting purposes.
def cost(&block)
- NEAT::controller.cost_func = block
+ NEAT::controller.cost_func_set &block
end
# Stop the progression once the fitness criteria is reached
- # for the most fit critter
+ # for the most fit critter. We allow more than one stop
+ # function here.
def stop_on_fitness(&block)
- NEAT::controller.stop_on_fit_func = block
+ NEAT::controller.stop_on_fit_func_add &block
end
# Helper function to
# Condition boolean vectors to be +1 if true, -1 if false (0 if sigmoid)
def condition_boolean_vector(vec, sig = :tanh)
@@ -99,16 +100,16 @@
block.(NEAT::controller)
end
# Report on evaluations
def report(&block)
- NEAT::controller.report_hook = block
+ NEAT::controller.report_add &block
end
# Run the engine. The block is called on each generation.
def run_engine(&block)
- NEAT::controller.end_run_func = block
+ NEAT::controller.end_run_add &block
NEAT::controller.run
end
# This is used to handle the details of our DSL.
def method_missing(m, *args, &block)
@@ -123,8 +124,8 @@
end
end
end
end
-# FIXME: This needs to better specified for cases in which there may be multiple
-# Controllers.
+# FIXME: This needs to better specified for cases in which
+# FIXME: there may be multiple Controllers.
require 'rubyneat/default_neat'