Class: NEAT::Critter

Inherits:
NeatOb show all
Defined in:
lib/rubyneat/critter.rb

Overview

Critters for NEAT

The Critter class comprises a Genotype and a Phenotype. The Genotype comprises Genes and Neurons.

Defined Under Namespace

Classes: Genotype, Phenotype

Instance Attribute Summary (collapse)

Attributes inherited from NeatOb

#controller, #name

Instance Method Summary (collapse)

Methods inherited from NeatOb

#log, log, #to_s

Constructor Details

- (Critter) initialize(pop, mating = false, &block)

Critter construction. We construct the genotype. The phenotype will be constructed by the Expressor operator.



20
21
22
23
24
25
# File 'lib/rubyneat/critter.rb', line 20

def initialize(pop, mating = false, &block)
  super pop.controller
  @population = pop
  @genotype = Genotype.new(self, mating)
  block.(self) unless block.nil?
end

Instance Attribute Details

- (Object) fitness

Ratings assigned by Evaluator



16
17
18
# File 'lib/rubyneat/critter.rb', line 16

def fitness
  @fitness
end

- (Object) genotype

Returns the value of attribute genotype



13
14
15
# File 'lib/rubyneat/critter.rb', line 13

def genotype
  @genotype
end

- (Object) novelty

Ratings assigned by Evaluator



16
17
18
# File 'lib/rubyneat/critter.rb', line 16

def novelty
  @novelty
end

- (Object) phenotype

Returns the value of attribute phenotype



13
14
15
# File 'lib/rubyneat/critter.rb', line 13

def phenotype
  @phenotype
end

- (Object) population (readonly)

Returns the value of attribute population



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

def population
  @population
end

Instance Method Details

- (Object) compare(oc)

Compare ourselves against another critter for compability.

The function to be used here is: distance = c1*E + c2*D + c3*W

Where: E, D - The number of excess and disjoint genes repesctively. N - The number of genes in the largest genome. W - The sum of absolute weight differences.

This is a variation of the formulation suggested by the Stanley paper, which normalizes the E and D terms by N.



333
334
335
336
337
338
339
340
341
# File 'lib/rubyneat/critter.rb', line 333

def compare(oc)
  c1 = @controller.parms.excess_coefficient
  c2 = @controller.parms.disjoint_coefficient
  c3 = @controller.parms.weight_coefficient
  e = excess(oc)
  d = disjoint(oc)
  w = weight_diff(oc)
  return c1 * e + c2 * d + c3 * w
end

- (Object) dump_s

Critter print



344
345
346
# File 'lib/rubyneat/critter.rb', line 344

def dump_s
  to_s + @genotype.dump_s + "\n" + @phenotype.to_s + "\n"
end

- (Object) evaluate!

A single evaluation step. Evaluate and generate fitness, novelty, etc. Returns the result.



50
51
52
# File 'lib/rubyneat/critter.rb', line 50

def evaluate!
  @controller.evaluator.evaluate! self
end

- (Object) express!

Exoress this critter using the Expressor plugin.



36
37
38
# File 'lib/rubyneat/critter.rb', line 36

def express!
  @controller.expressor.express! self
end

- (Object) initialize_neurons!

This initializes neurons in preparation for recurrence. Note that the Critter should already have expressed its genotype before this is called.



43
44
45
# File 'lib/rubyneat/critter.rb', line 43

def initialize_neurons!
  @phenotype.initialize_neurons
end

- (Object) ready_for_expression!

Get the Critter ready for the Expressor to express the geneotype.



29
30
31
32
33
# File 'lib/rubyneat/critter.rb', line 29

def ready_for_expression!
  @genotype.wire!
  @phenotype = NEAT::Critter::Phenotype[self]
  @phenotype
end