lib/rubyneat/evaluator.rb in rubyneat-0.3.5.alpha.6 vs lib/rubyneat/evaluator.rb in rubyneat-0.4.0.alpha.3
- old
+ new
@@ -1,6 +1,6 @@
-require 'rubyneat/rubyneat'
+require_relative 'rubyneat'
module NEAT
#= Evaluator evaluates phenotype of critter for fitness, novelty, etc.
# We can have a chain of these evaluators whose outputs are summed, etc.
class Evaluator < Operator
@@ -20,14 +20,18 @@
# Returns [vin, vout], where vin is the input vector,
# and vout in the output vector from the critter.
# FIXME: this should not really have to deal with an error.
# FIXME: the error should be handled upstream from here.
def evaluate!(critter)
- vin = @controller.query_func.(@controller.seq_num)
+ vin = @controller.query_func_hook(@controller.seq_num)
@crit_hist[critter] = {} unless @crit_hist.member? critter
begin
- vout = critter.phenotype.stimulate *vin, &@controller.recurrence_func
+ vout = unless @controller.recurrence_func_none?
+ critter.phenotype.stimulate *vin, &@controller.recurrence_func_hook_itself
+ else
+ critter.phenotype.stimulate *vin
+ end
log.debug "Critter #{critter.name}: vin=#{vin}. vout=#{vout}"
@crit_hist[critter][@controller.seq_num] = [vin, vout]
rescue Exception => e
log.error "Exception #{e} on code:\n#{critter.phenotype.code}"
@crit_hist[critter][@controller.seq_num] = [vin, :error]
@@ -36,13 +40,13 @@
# Analyze the evaluation and compute a fitness for the given critter.
# Note that if cost_func is set, we call that to integrate the cost to
# the fitness average fitness calculated for the fitness vector.
def analyze_for_fitness!(critter)
- fitvec = @crit_hist[critter].map{|seq, vio| @controller.fitness_func.(vio[0], vio[1], seq) }
+ fitvec = @crit_hist[critter].map{|seq, vio| @controller.fitness_func_hook(vio[0], vio[1], seq) }
# Average the fitness vector to get a scalar fitness.
- critter.fitness = unless @controller.cost_func.nil?
- @controller.cost_func.(fitvec, critter.genotype.fitness_cost)
+ critter.fitness = unless @controller.cost_func_none?
+ @controller.cost_func_hook(fitvec, critter.genotype.fitness_cost)
else
fitvec.reduce {|a,r| a+r} / fitvec.size.to_f + critter.genotype.fitness_cost
end
log.debug "Fitness Vector: #{fitvec}, fitness of #{critter.fitness} assigned to #{critter}"
end