Class: NEAT::Controller
Overview
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.
Defined Under Namespace
Classes: NeatSettings
Instance Attribute Summary (collapse)
-
- (Object) compare_func
Compare function for fitness Cost function for integrating in the cost to the fitness scalar.
-
- (Object) cost_func
Compare function for fitness Cost function for integrating in the cost to the fitness scalar.
-
- (Object) end_run_func
End run function to call at the end of each generational run Also report_hook to dump reports for the user, etc.
-
- (Object) evaluator
Returns the value of attribute evaluator.
-
- (Object) evaluator_class
Returns the value of attribute evaluator_class.
-
- (Object) evolver
Returns the value of attribute evolver.
-
- (Object) evolver_class
Returns the value of attribute evolver_class.
-
- (Object) expressor
Returns the value of attribute expressor.
-
- (Object) expressor_class
Returns the value of attribute expressor_class.
-
- (Object) fitness_func
Fitness function that Critters shall be rated on.
-
- (Object) generation_num
readonly
Current generation count.
-
- (Object) glob_innov_num
readonly
global innovation number.
-
- (Object) log
readonly
Logger object for all of RubyNEAT.
-
- (Object) neural_hidden
Class map of named input and output neurons (each critter will have instantiations of these) name: InputNeuralClass (usually InputNeuron).
-
- (Object) neural_inputs
Class map of named input and output neurons (each critter will have instantiations of these) name: InputNeuralClass (usually InputNeuron).
-
- (Object) neural_outputs
Class map of named input and output neurons (each critter will have instantiations of these) name: InputNeuralClass (usually InputNeuron).
-
- (Object) neuron_catalog
catalog of neurons classes to use { weight => nclass, … }.
-
- (Object) parms
Parameters for evolution (NeatParameters).
-
- (Object) population
readonly
population object and class specification.
-
- (Object) population_class
readonly
population object and class specification.
-
- (Object) population_history
readonly
population object and class specification.
-
- (Object) query_func
Query function that Critters shall call.
-
- (Object) recurrence_func
Recurrence function that Critters will yield to.
-
- (Object) report_hook
End run function to call at the end of each generational run Also report_hook to dump reports for the user, etc.
-
- (Object) seq_num
readonly
current sequence number being evaluated.
-
- (Object) stop_on_fit_func
Compare function for fitness Cost function for integrating in the cost to the fitness scalar.
-
- (Object) verbosity
Global verbosity level: 1 - normal (the default) 2 - really verbose 3 - maximally verbose Use in conjunction with log.debug.
Attributes inherited from NeatOb
Instance Method Summary (collapse)
- - (Object) gaussian
-
- (Controller) initialize(neural_inputs: nil, neural_outputs: nil, neural_hidden: nil, parameters: NeatSettings.new, &block)
constructor
-
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.
-
- - (Object) new_innovation
-
- (Object) run
Run this evolution.
Methods inherited from NeatOb
Constructor Details
- (Controller) initialize(neural_inputs: nil, neural_outputs: nil, neural_hidden: nil, parameters: NeatSettings.new, &block)
-
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.
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 |
# 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 |
Instance Attribute Details
- (Object) compare_func
Compare function for fitness Cost function for integrating in the cost to the fitness scalar.
197 198 199 |
# File 'lib/rubyneat/rubyneat.rb', line 197 def compare_func @compare_func end |
- (Object) cost_func
Compare function for fitness Cost function for integrating in the cost to the fitness scalar.
197 198 199 |
# File 'lib/rubyneat/rubyneat.rb', line 197 def cost_func @cost_func end |
- (Object) end_run_func
End run function to call at the end of each generational run Also report_hook to dump reports for the user, etc.
201 202 203 |
# File 'lib/rubyneat/rubyneat.rb', line 201 def end_run_func @end_run_func end |
- (Object) evaluator
Returns the value of attribute evaluator
176 177 178 |
# File 'lib/rubyneat/rubyneat.rb', line 176 def evaluator @evaluator end |
- (Object) evaluator_class
Returns the value of attribute evaluator_class
176 177 178 |
# File 'lib/rubyneat/rubyneat.rb', line 176 def evaluator_class @evaluator_class end |
- (Object) evolver
Returns the value of attribute evolver
177 178 179 |
# File 'lib/rubyneat/rubyneat.rb', line 177 def evolver @evolver end |
- (Object) evolver_class
Returns the value of attribute evolver_class
177 178 179 |
# File 'lib/rubyneat/rubyneat.rb', line 177 def evolver_class @evolver_class end |
- (Object) expressor
Returns the value of attribute expressor
175 176 177 |
# File 'lib/rubyneat/rubyneat.rb', line 175 def expressor @expressor end |
- (Object) expressor_class
Returns the value of attribute expressor_class
175 176 177 |
# File 'lib/rubyneat/rubyneat.rb', line 175 def expressor_class @expressor_class end |
- (Object) fitness_func
Fitness function that Critters shall be rated on.
190 191 192 |
# File 'lib/rubyneat/rubyneat.rb', line 190 def fitness_func @fitness_func end |
- (Object) generation_num (readonly)
Current generation count
160 161 162 |
# File 'lib/rubyneat/rubyneat.rb', line 160 def generation_num @generation_num end |
- (Object) glob_innov_num (readonly)
global innovation number
154 155 156 |
# File 'lib/rubyneat/rubyneat.rb', line 154 def glob_innov_num @glob_innov_num end |
- (Object) log (readonly)
Logger object for all of RubyNEAT
204 205 206 |
# File 'lib/rubyneat/rubyneat.rb', line 204 def log @log end |
- (Object) neural_hidden
Class map of named input and output neurons (each critter will have instantiations of these) name: InputNeuralClass (usually InputNeuron)
167 168 169 |
# File 'lib/rubyneat/rubyneat.rb', line 167 def neural_hidden @neural_hidden end |
- (Object) neural_inputs
Class map of named input and output neurons (each critter will have instantiations of these) name: InputNeuralClass (usually InputNeuron)
167 168 169 |
# File 'lib/rubyneat/rubyneat.rb', line 167 def neural_inputs @neural_inputs end |
- (Object) neural_outputs
Class map of named input and output neurons (each critter will have instantiations of these) name: InputNeuralClass (usually InputNeuron)
167 168 169 |
# File 'lib/rubyneat/rubyneat.rb', line 167 def neural_outputs @neural_outputs end |
- (Object) neuron_catalog
catalog of neurons classes to use { weight => nclass, … }
163 164 165 |
# File 'lib/rubyneat/rubyneat.rb', line 163 def neuron_catalog @neuron_catalog end |
- (Object) parms
Parameters for evolution (NeatParameters)
170 171 172 |
# File 'lib/rubyneat/rubyneat.rb', line 170 def parms @parms end |
- (Object) population (readonly)
population object and class specification
173 174 175 |
# File 'lib/rubyneat/rubyneat.rb', line 173 def population @population end |
- (Object) population_class (readonly)
population object and class specification
173 174 175 |
# File 'lib/rubyneat/rubyneat.rb', line 173 def population_class @population_class end |
- (Object) population_history (readonly)
population object and class specification
173 174 175 |
# File 'lib/rubyneat/rubyneat.rb', line 173 def population_history @population_history end |
- (Object) query_func
Query function that Critters shall call.
187 188 189 |
# File 'lib/rubyneat/rubyneat.rb', line 187 def query_func @query_func end |
- (Object) recurrence_func
Recurrence function that Critters will yield to.
193 194 195 |
# File 'lib/rubyneat/rubyneat.rb', line 193 def recurrence_func @recurrence_func end |
- (Object) report_hook
End run function to call at the end of each generational run Also report_hook to dump reports for the user, etc.
201 202 203 |
# File 'lib/rubyneat/rubyneat.rb', line 201 def report_hook @report_hook end |
- (Object) seq_num (readonly)
current sequence number being evaluated
157 158 159 |
# File 'lib/rubyneat/rubyneat.rb', line 157 def seq_num @seq_num end |
- (Object) stop_on_fit_func
Compare function for fitness Cost function for integrating in the cost to the fitness scalar.
197 198 199 |
# File 'lib/rubyneat/rubyneat.rb', line 197 def stop_on_fit_func @stop_on_fit_func end |
- (Object) verbosity
Global verbosity level: 1 - normal (the default) 2 - really verbose 3 - maximally verbose Use in conjunction with log.debug
184 185 186 |
# File 'lib/rubyneat/rubyneat.rb', line 184 def verbosity @verbosity end |
Instance Method Details
- (Object) gaussian
368 |
# File 'lib/rubyneat/rubyneat.rb', line 368 def gaussian ; @gaussian.() ; end |
- (Object) new_innovation
367 |
# File 'lib/rubyneat/rubyneat.rb', line 367 def new_innovation ; @glob_innov_num += 1; end |
- (Object) run
Run this evolution.
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 |
# 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 |