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.

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.

Attributes

evaluator[RW]
evaluator_class[RW]
evolver[RW]
evolver_class[RW]
expressor[RW]
expressor_class[RW]
generation_num[R]

Current generation count

log[R]

Logger object for all of RubyNEAT

neural_hidden[RW]

Class map of named input and output neurons (each critter will have instantiations of these) name: InputNeuralClass (usually InputNeuron)

neural_inputs[RW]

Class map of named input and output neurons (each critter will have instantiations of these) name: InputNeuralClass (usually InputNeuron)

neural_outputs[RW]

Class map of named input and output neurons (each critter will have instantiations of these) name: InputNeuralClass (usually InputNeuron)

neuron_catalog[RW]

catalog of neurons classes to use { weight => nclass, … }

parms[RW]

Parameters for evolution (NeatParameters)

population[R]

population object and class specification

population_class[R]

population object and class specification

population_history[R]

population object and class specification

seq_num[R]

current sequence number being evaluated

Public Class Methods

new(neural_inputs: nil, neural_outputs: nil, neural_hidden: nil, parameters: NeatSettings.new, &block) click to toggle source
  • 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.

Calls superclass method NEAT::NeatOb::new
# File lib/rubyneat/rubyneat.rb, line 496
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

Public Instance Methods

gaussian() click to toggle source
# File lib/rubyneat/rubyneat.rb, line 528
def gaussian ; @gaussian.() ; end
new_innovation() click to toggle source
# File lib/rubyneat/rubyneat.rb, line 527
def new_innovation ; self.glob_innov_num += 1 ; end
run() click to toggle source

Run this evolution.

# File lib/rubyneat/rubyneat.rb, line 531
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

Private Instance Methods

exit_neat() click to toggle source

Allow us to hook in pre-exit functionality here This function shall never return.

# File lib/rubyneat/rubyneat.rb, line 583
def exit_neat
  pre_exit_hook(self) unless pre_exit_none?
  exit
end
pre_run_initialize() click to toggle source

We must set up the objects we need prior to the run, if not set.

# File lib/rubyneat/rubyneat.rb, line 576
def pre_run_initialize
  @evaluator = @evaluator_class.new(self) if @evaluator.nil?
  @evolver = @evolver_class.new(self) if @evolver.nil?
end