Class: Ai::Neat::Creature
- Inherits:
-
Object
- Object
- Ai::Neat::Creature
- Defined in:
- lib/ai/neat/creature.rb
Instance Attribute Summary collapse
-
#fitness ⇒ Object
Returns the value of attribute fitness.
-
#network ⇒ Object
Returns the value of attribute network.
-
#score ⇒ Object
Returns the value of attribute score.
Instance Method Summary collapse
- #decision ⇒ Object
- #feed_forward ⇒ Object
- #flatten_genes ⇒ Object
- #flatten_genes=(genes) ⇒ Object
-
#initialize(models) ⇒ Creature
constructor
A new instance of Creature.
- #inputs ⇒ Object
- #inputs=(values) ⇒ Object
Constructor Details
Instance Attribute Details
#fitness ⇒ Object
Returns the value of attribute fitness.
6 7 8 |
# File 'lib/ai/neat/creature.rb', line 6 def fitness @fitness end |
#network ⇒ Object
Returns the value of attribute network.
6 7 8 |
# File 'lib/ai/neat/creature.rb', line 6 def network @network end |
#score ⇒ Object
Returns the value of attribute score.
6 7 8 |
# File 'lib/ai/neat/creature.rb', line 6 def score @score end |
Instance Method Details
#decision ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# 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 ⇒ Object
28 29 30 |
# File 'lib/ai/neat/creature.rb', line 28 def feed_forward @network.feed_forward end |
#flatten_genes ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# 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) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/ai/neat/creature.rb', line 50 def flatten_genes=(genes) (0..(@network.layers.count - 2)).each do |i| (0..@network.layers[i].nodes.count - 1).each do |w| (0..@network.layers[i].nodes[w].weights.count - 1).each do |e| @network.layers[i].nodes[w].weights[e] = genes.first genes.shift end end (0..@network.layers[i].bias.weights.count - 1).each do |w| @network.layers[i].bias.weights[w] = genes.first genes.shift end end end |
#inputs ⇒ Object
66 67 68 |
# File 'lib/ai/neat/creature.rb', line 66 def inputs @network.layers.first.values end |
#inputs=(values) ⇒ Object
70 71 72 |
# File 'lib/ai/neat/creature.rb', line 70 def inputs=(values) @network.layers.first.values = values end |