Class: Brainz::Synapse

Inherits:
Object
  • Object
show all
Defined in:
lib/brainz/synapse.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(from, to) ⇒ Synapse

Returns a new instance of Synapse.



6
7
8
9
10
# File 'lib/brainz/synapse.rb', line 6

def initialize(from, to)
  @weight = Kernel.rand(0.4) - 0.2
  @change = 0
  @from, @to = from, to
end

Instance Attribute Details

#changeObject

Returns the value of attribute change.



4
5
6
# File 'lib/brainz/synapse.rb', line 4

def change
  @change
end

#fromObject (readonly)

Returns the value of attribute from.



3
4
5
# File 'lib/brainz/synapse.rb', line 3

def from
  @from
end

#toObject (readonly)

Returns the value of attribute to.



3
4
5
# File 'lib/brainz/synapse.rb', line 3

def to
  @to
end

#weightObject (readonly)

Returns the value of attribute weight.



3
4
5
# File 'lib/brainz/synapse.rb', line 3

def weight
  @weight
end

Class Method Details



16
17
18
19
20
# File 'lib/brainz/synapse.rb', line 16

def self.link(from, to)
  synapse = Synapse.new(from, to)
  to.dendrites.push(synapse)
  from.axon_synapses.push(synapse)
end

Instance Method Details

#adjust(diff) ⇒ Object



12
13
14
# File 'lib/brainz/synapse.rb', line 12

def adjust(diff)
  @weight += diff
end