Class: NEAT::Critter::Genotype::Gene

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

Overview

Gene Specification

The Gene specifies a singular input and output neuron, which represents a connection between them, along with the weight of that connection, which may be positive, negative, or zero.

There is also the enabled flag

Instance Attribute Summary collapse

Attributes inherited from NeatOb

#controller, #name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from NeatOb

attr_neat, log, #log

Constructor Details

#initialize(genotype, &block) ⇒ Gene

Returns a new instance of Gene.



247
248
249
250
251
252
253
254
# File 'lib/rubyneat/critter.rb', line 247

def initialize(genotype, &block)
  super genotype.controller
  @genotype = genotype
  @enabled = true
  @innovation = NEAT::new_innovation
  @in_neuron = @out_neuron = nil
  block.(self) unless block.nil?
end

Instance Attribute Details

#enabledObject

Is this gene enabled?



245
246
247
# File 'lib/rubyneat/critter.rb', line 245

def enabled
  @enabled
end

#genotypeObject

parent genotype



233
234
235
# File 'lib/rubyneat/critter.rb', line 233

def genotype
  @genotype
end

#in_neuronObject

input neuron’s name (where our output goes) output neuron’s name (neuron to be queried)



240
241
242
# File 'lib/rubyneat/critter.rb', line 240

def in_neuron
  @in_neuron
end

#innovationObject

innovation number



236
237
238
# File 'lib/rubyneat/critter.rb', line 236

def innovation
  @innovation
end

#out_neuronObject

input neuron’s name (where our output goes) output neuron’s name (neuron to be queried)



240
241
242
# File 'lib/rubyneat/critter.rb', line 240

def out_neuron
  @out_neuron
end

#weightObject

weight of the connection



243
244
245
# File 'lib/rubyneat/critter.rb', line 243

def weight
  @weight
end

Class Method Details

.[](genotype, input, output, weight = 0.0, innov = nil) ⇒ Object

Create a new Gene and set it up fully. genotype – genotype input – name of input neuron connection output – name of output neuron connection weight – weight to give neuron (optional) innov – innovation number of gene (optional)



265
266
267
268
269
270
271
272
# File 'lib/rubyneat/critter.rb', line 265

def self.[](genotype, input, output, weight = 0.0, innov = nil)
  g = Gene.new genotype
  g.in_neuron = (input.kind_of? Symbol) ? input : input.name
  g.out_neuron = (output.kind_of? Symbol) ? output : output.name
  g.weight = weight
  g.innovation = innov unless innov.nil?
  return g
end

Instance Method Details

#disabled?Boolean

Returns:

  • (Boolean)


257
# File 'lib/rubyneat/critter.rb', line 257

def disabled? ; not enabled? ; end

#enabled?Boolean

Returns:

  • (Boolean)


256
# File 'lib/rubyneat/critter.rb', line 256

def enabled? ; @enabled ; end

#to_sObject Also known as: dump_s



274
275
276
# File 'lib/rubyneat/critter.rb', line 274

def to_s
  super + "[i%s,w%s,%s]" % [@innovation, @weight, self.enabled?]
end