Class: NEAT::Evolver

Inherits:
Operator show all
Defined in:
lib/rubyneat/evolver.rb

Overview

Evolver – Basis of all evolvers.

All evolvers shall derive from this basic evolver (or this one can be used as is). Here, we’ll have many different evolutionary operators that will perform operations on the various critters in the population.

Defined Under Namespace

Classes: CritterOp

Instance Attribute Summary collapse

Attributes inherited from NeatOb

#controller, #name

Instance Method Summary collapse

Methods inherited from NeatOb

attr_neat, log, #log, #to_s

Constructor Details

#initialize(c) ⇒ Evolver

Returns a new instance of Evolver.



14
15
16
17
# File 'lib/rubyneat/evolver.rb', line 14

def initialize(c)
  super
  @critter_op = CritterOp.new self
end

Instance Attribute Details

#npopObject (readonly)

Returns the value of attribute npop.



12
13
14
# File 'lib/rubyneat/evolver.rb', line 12

def npop
  @npop
end

Instance Method Details

#evolve(population) ⇒ Object

Here we clone the population and then evolve it on the basis of fitness and novelty, etc.

Returns the newly-evolved population.



54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/rubyneat/evolver.rb', line 54

def evolve(population)
  @npop = population.dclone
  
  # Population sorting and evaluation for breeding, mutations, etc.
  prepare_speciation!
  prepare_fitness!
  prepare_novelty!

  mate!

  return @npop
end

#gen_initial_genes!(genotype) ⇒ Object

Generate the initial genes for a given genotype. We key genes off their innovation numbers.



21
22
23
24
25
26
27
28
29
# File 'lib/rubyneat/evolver.rb', line 21

def gen_initial_genes!(genotype)
  genotype.genes = {}
  genotype.neural_inputs.each do |s1, input|
    genotype.neural_outputs.each do |s2, output|
      g = Critter::Genotype::Gene[genotype, input, output, NEAT::controller.gaussian]
      genotype.genes[g.innovation] = g
    end
  end
end

#mutate!(population) ⇒ Object

Here we mutate the population.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/rubyneat/evolver.rb', line 32

def mutate!(population)
  @npop = population

  if @controller.parms.mate_only_prob.nil? or rand > @controller.parms.mate_only_prob
    log.debug "[[[ Neuron and Gene Giggling!"
    mutate_perturb_gene_weights!
    mutate_change_gene_weights!
    mutate_add_neurons!
    mutate_change_neurons!
    mutate_add_genes!
    mutate_disable_genes!
    mutate_reenable_genes!
    log.debug "]]] End Neuron and Gene Giggling!\n"
  else
    log.debug "*** Mating only!"
  end
end