class NEAT::Controller
Controller for all operations of RubyNEAT¶ ↑
This object contains all the specifications and details for evolving and evaluation of the RubyNEAT system. It is a type of "World", if you will, for the entire enterprise. Your application shall only have one Controller.
Attributes
Compare function for fitness Cost function for integrating in the cost to the fitness scalar.
Compare function for fitness Cost function for integrating in the cost to the fitness scalar.
End run function to call at the end of each generational run Also #report_hook to dump reports for the user, etc.
Fitness function that Critters shall be rated on.
Current generation count
global innovation number
Logger object for all of RubyNEAT
Class map of named input and output neurons (each critter will have instantiations of these) name: InputNeuralClass (usually InputNeuron)
Class map of named input and output neurons (each critter will have instantiations of these) name: InputNeuralClass (usually InputNeuron)
catalog of neurons classes to use { weight => nclass, … }
Parameters for evolution (NeatParameters)
population object and class specification
population object and class specification
population object and class specification
Query function that Critters shall call.
Recurrence function that Critters will yield to.
End run function to call at the end of each generational run Also #report_hook to dump reports for the user, etc.
current sequence number being evaluated
Compare function for fitness Cost function for integrating in the cost to the fitness scalar.
Global verbosity level:
1 - normal (the default) 2 - really verbose 3 - maximally verbose
Use in conjunction with log.debug
Public Class Methods
-
#neural_inputs – array of input classes
-
#neural_outputs – array of output classes
-
parameters – NeatParameters object, or a path to a YAML file to create this.
# File lib/rubyneat/rubyneat.rb, line 334 def initialize(neural_inputs: nil, neural_outputs: nil, neural_hidden: nil, parameters: NeatSettings.new, &block) super(self) @verbosity = 1 @glob_innov_num = 0 @gaussian = Distribution::Normal.rng @population_history = [] @evolver = Evolver.new self @expressor = Expressor.new self @neuron_catalog = Neuron::neuron_types.clone @neural_inputs = neural_inputs @neural_outputs = neural_outputs @neural_hidden = neural_hidden # Default classes for population and operators, etc. @population_class = NEAT::Population @evaluator_class = NEAT::Evaluator @expressor_class = NEAT::Expressor @evolver_class = NEAT::Evolver # Handle the parameters parameter. :-) @parms = unless parameters.kind_of? String parameters else # load it from a file open(parameters, 'r') { |fd| YAML::load fd.read } end block.(self) unless block.nil? end
Public Instance Methods
# File lib/rubyneat/rubyneat.rb, line 368 def gaussian ; @gaussian.() ; end
# File lib/rubyneat/rubyneat.rb, line 367 def new_innovation ; @glob_innov_num += 1; end
Run this evolution.
# File lib/rubyneat/rubyneat.rb, line 371 def run pre_run_initialize (1..@parms.max_generations).each do |gen_number| @generation_num = gen_number @population_history << unless @population.nil? @population else @population = @population_class.new(self) end @population_history.shift unless @population_history.size <= @parms.max_population_history @population.mutate! @population.express! ## Evaluate population @evaluator.ready_for_evaluation @population (@parms.start_sequence_at .. @parms.end_sequence_at).each do |snum| @seq_num = snum @population.evaluate! end @population.analyze! @population.speciate! $log.debug @population.dump_s unless @verbosity < 3 new_pop = @population.evolve ## Report hook for evaluation @report_hook.(@population.report) unless @report_hook.nil? ## Exit if fitness criteria is reached #FIXME handle this exit condition better!!!!! exit if @stop_on_fit_func.(@population.report[:fitness], self) unless @stop_on_fit_func.nil? ## Evolve population @population = new_pop ## Finish up this run @end_run_func.(self) unless @end_run_func.nil? end end