class Ai::Neat::Creature

Attributes

fitness[RW]
network[RW]
score[RW]

Public Class Methods

new(models) click to toggle source
# File lib/ai/neat/creature.rb, line 8
def initialize(models)
  @network = Network.new(models)
  @fitness = 0
  @score = 0
end

Public Instance Methods

decision() click to toggle source
# File lib/ai/neat/creature.rb, line 14
def decision
  index = -1
  max = -Float::INFINITY

  (0..(@network.layers.last.nodes.count - 1)).each do |i|
    if @network.layers.last.nodes[i].value > max
      max = @network.layers.last.nodes[i].value
      index = i
    end
  end

  index
end
feed_forward() click to toggle source
# File lib/ai/neat/creature.rb, line 28
def feed_forward
  @network.feed_forward
end
flatten_genes() click to toggle source
# File lib/ai/neat/creature.rb, line 32
def flatten_genes
  genes = []

  (0..(@network.layers.count - 2)).each do |i|
    @network.layers[i].nodes.each do |node|
      node.weights.each do |weight|
        genes.push(weight)
      end
    end

    @network.layers[i].bias.weights.each do |weight|
      genes.push(weight)
    end
  end

  genes
end
flatten_genes=(genes) click to toggle source
# File lib/ai/neat/creature.rb, line 50
def flatten_genes=(genes)
  (0..(@network.layers.count - 2)).each do |i|
    @network.layers[i].nodes.each do |node|
      node.weights.each do |weight|
        weight = genes.first
        genes.shift
      end
    end

    @network.layers[i].bias.weights.each do |weight|
      weight = genes.first
      genes.shift
    end
  end
end
inputs() click to toggle source
# File lib/ai/neat/creature.rb, line 66
def inputs
  @network.layers.first.values
end
inputs=(values) click to toggle source
# File lib/ai/neat/creature.rb, line 70
def inputs=(values)
  @network.layers.first.values = values
end