Class: NEAT::Evaluator
Overview
Evaluator evaluates phenotype of critter for fitness, novelty, etc.
We can have a chain of these evaluators whose outputs are summed, etc.
Instance Attribute Summary
Attributes inherited from NeatOb
Instance Method Summary (collapse)
-
- (Object) analyze_for_fitness!(critter)
Analyze the evaluation and compute a fitness for the given critter.
-
- (Object) evaluate!(critter)
Evaluate one step of a sequence of evaluations.
-
- (Object) ready_for_evaluation(pop)
This is call prior to any sequence evaluation.
Methods inherited from NeatOb
#initialize, #log, log, #to_s
Constructor Details
This class inherits a constructor from NEAT::NeatOb
Instance Method Details
- (Object) analyze_for_fitness!(critter)
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.
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rubyneat/evaluator.rb', line 40 def analyze_for_fitness!(critter) fitvec = @crit_hist[critter].map{|seq, vio| @controller.fitness_func.(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) 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 |
- (Object) evaluate!(critter)
Evaluate one step of a sequence of evaluations. For time series and realtime ongoing evaluations, everything is.
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.
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rubyneat/evaluator.rb', line 24 def evaluate!(critter) vin = @controller.query_func.(@controller.seq_num) @crit_hist[critter] = {} unless @crit_hist.member? critter begin vout = critter.phenotype.stimulate *vin, &@controller.recurrence_func 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] end end |
- (Object) ready_for_evaluation(pop)
This is call prior to any sequence evaluation. Here, we clean up persistent tracking information, etc.
10 11 12 13 |
# File 'lib/rubyneat/evaluator.rb', line 10 def ready_for_evaluation(pop) @crit_hist = {} pop.initialize_for_recurrence! end |