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.
FIXME: The function hooks really should be able to take more FIXME: than one hook! we don’t need that functionality right FIXME: now. Also, the Controller ‘god’ object itself will need FIXME: to undergo some refactorization so that we can have many FIXME: of them for HyperNEAT, co-evolution, etc.
FIXME: An alternative approach would be to have demigod objects FIXME: where the controller would lord it over them all. Attention FIXME: must also be given to Rubinius and JRuby so that we can FIXME: run under multiple cores.
Defined Under Namespace
Classes: NeatSettings
Instance Attribute Summary collapse
-
#evaluator ⇒ Object
Returns the value of attribute evaluator.
-
#evaluator_class ⇒ Object
Returns the value of attribute evaluator_class.
-
#evolver ⇒ Object
Returns the value of attribute evolver.
-
#evolver_class ⇒ Object
Returns the value of attribute evolver_class.
-
#expressor ⇒ Object
Returns the value of attribute expressor.
-
#expressor_class ⇒ Object
Returns the value of attribute expressor_class.
-
#generation_num ⇒ Object
readonly
Current generation count.
-
#log ⇒ Object
readonly
Logger object for all of RubyNEAT.
-
#neural_hidden ⇒ Object
Class map of named input and output neurons (each critter will have instantiations of these) name: InputNeuralClass (usually InputNeuron).
-
#neural_inputs ⇒ Object
Class map of named input and output neurons (each critter will have instantiations of these) name: InputNeuralClass (usually InputNeuron).
-
#neural_outputs ⇒ Object
Class map of named input and output neurons (each critter will have instantiations of these) name: InputNeuralClass (usually InputNeuron).
-
#neuron_catalog ⇒ Object
catalog of neurons classes to use { weight => nclass, … }.
-
#parms ⇒ Object
Parameters for evolution (NeatParameters).
-
#population ⇒ Object
readonly
population object and class specification.
-
#population_class ⇒ Object
readonly
population object and class specification.
-
#population_history ⇒ Object
readonly
population object and class specification.
-
#seq_num ⇒ Object
readonly
current sequence number being evaluated.
Attributes inherited from NeatOb
Instance Method Summary collapse
- #gaussian ⇒ Object
-
#initialize(neural_inputs: nil, neural_outputs: nil, neural_hidden: nil, parameters: NeatSettings.new, &block) ⇒ Controller
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.
-
- #new_innovation ⇒ Object
-
#run ⇒ Object
Run this evolution.
Methods inherited from NeatOb
Constructor Details
#initialize(neural_inputs: nil, neural_outputs: nil, neural_hidden: nil, parameters: NeatSettings.new, &block) ⇒ Controller
-
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.
498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 |
# File 'lib/rubyneat/rubyneat.rb', line 498 def initialize(neural_inputs: nil, neural_outputs: nil, neural_hidden: nil, parameters: NeatSettings.new, &block) super(self) @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
#evaluator ⇒ Object
Returns the value of attribute evaluator.
337 338 339 |
# File 'lib/rubyneat/rubyneat.rb', line 337 def evaluator @evaluator end |
#evaluator_class ⇒ Object
Returns the value of attribute evaluator_class.
337 338 339 |
# File 'lib/rubyneat/rubyneat.rb', line 337 def evaluator_class @evaluator_class end |
#evolver ⇒ Object
Returns the value of attribute evolver.
338 339 340 |
# File 'lib/rubyneat/rubyneat.rb', line 338 def evolver @evolver end |
#evolver_class ⇒ Object
Returns the value of attribute evolver_class.
338 339 340 |
# File 'lib/rubyneat/rubyneat.rb', line 338 def evolver_class @evolver_class end |
#expressor ⇒ Object
Returns the value of attribute expressor.
336 337 338 |
# File 'lib/rubyneat/rubyneat.rb', line 336 def expressor @expressor end |
#expressor_class ⇒ Object
Returns the value of attribute expressor_class.
336 337 338 |
# File 'lib/rubyneat/rubyneat.rb', line 336 def expressor_class @expressor_class end |
#generation_num ⇒ Object (readonly)
Current generation count
321 322 323 |
# File 'lib/rubyneat/rubyneat.rb', line 321 def generation_num @generation_num end |
#log ⇒ Object (readonly)
Logger object for all of RubyNEAT
371 372 373 |
# File 'lib/rubyneat/rubyneat.rb', line 371 def log @log end |
#neural_hidden ⇒ Object
Class map of named input and output neurons (each critter will have instantiations of these) name: InputNeuralClass (usually InputNeuron)
328 329 330 |
# File 'lib/rubyneat/rubyneat.rb', line 328 def neural_hidden @neural_hidden end |
#neural_inputs ⇒ Object
Class map of named input and output neurons (each critter will have instantiations of these) name: InputNeuralClass (usually InputNeuron)
328 329 330 |
# File 'lib/rubyneat/rubyneat.rb', line 328 def neural_inputs @neural_inputs end |
#neural_outputs ⇒ Object
Class map of named input and output neurons (each critter will have instantiations of these) name: InputNeuralClass (usually InputNeuron)
328 329 330 |
# File 'lib/rubyneat/rubyneat.rb', line 328 def neural_outputs @neural_outputs end |
#neuron_catalog ⇒ Object
catalog of neurons classes to use { weight => nclass, … }
324 325 326 |
# File 'lib/rubyneat/rubyneat.rb', line 324 def neuron_catalog @neuron_catalog end |
#parms ⇒ Object
Parameters for evolution (NeatParameters)
331 332 333 |
# File 'lib/rubyneat/rubyneat.rb', line 331 def parms @parms end |
#population ⇒ Object (readonly)
population object and class specification
334 335 336 |
# File 'lib/rubyneat/rubyneat.rb', line 334 def population @population end |
#population_class ⇒ Object (readonly)
population object and class specification
334 335 336 |
# File 'lib/rubyneat/rubyneat.rb', line 334 def population_class @population_class end |
#population_history ⇒ Object (readonly)
population object and class specification
334 335 336 |
# File 'lib/rubyneat/rubyneat.rb', line 334 def population_history @population_history end |
#seq_num ⇒ Object (readonly)
current sequence number being evaluated
318 319 320 |
# File 'lib/rubyneat/rubyneat.rb', line 318 def seq_num @seq_num end |
Instance Method Details
#gaussian ⇒ Object
530 |
# File 'lib/rubyneat/rubyneat.rb', line 530 def gaussian ; @gaussian.() ; end |
#new_innovation ⇒ Object
529 |
# File 'lib/rubyneat/rubyneat.rb', line 529 def new_innovation ; self.glob_innov_num += 1 ; end |
#run ⇒ Object
Run this evolution.
533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 |
# File 'lib/rubyneat/rubyneat.rb', line 533 def run pre_run_initialize (1..@parms.max_generations).each do |gen_number| @generation_num = gen_number # must be set first @population_history << unless @population.nil? @population else @population = @population_class.new(self) end @population.generation = gen_number @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 self.verbosity < 3 new_pop = @population.evolve ## Report hook for evaluation report_hooks(@population.report) ## Exit if fitness criteria is reached #FIXME handle this exit condition better!!!!! exit_neat if stop_on_fit_func_hook(@population.report.last[:fitness], self) unless stop_on_fit_func_none? ## Evolve population @population = new_pop ## Finish up this run end_run_hooks(self) end end |