Class: Noggin::Edge

Inherits:
Object
  • Object
show all
Defined in:
lib/noggin/edge.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(origin: origin, dest: dest, weight: rand(0.20...0.80), momentum: 1, learning_rate: 0.3) ⇒ Edge

Returns a new instance of Edge.



6
7
8
9
10
11
12
13
# File 'lib/noggin/edge.rb', line 6

def initialize origin: origin, dest: dest, weight: rand(0.20...0.80), momentum: 1, learning_rate: 0.3
  @origin = origin
  @dest = dest
  @weight = weight
  @momentum = momentum
  @previous_derivative = 0
  @learning_rate = learning_rate
end

Instance Attribute Details

#backward_inputObject

Returns the value of attribute backward_input.



4
5
6
# File 'lib/noggin/edge.rb', line 4

def backward_input
  @backward_input
end

#backward_outputObject

Returns the value of attribute backward_output.



4
5
6
# File 'lib/noggin/edge.rb', line 4

def backward_output
  @backward_output
end

#derivativeObject

Returns the value of attribute derivative.



4
5
6
# File 'lib/noggin/edge.rb', line 4

def derivative
  @derivative
end

#destObject

Returns the value of attribute dest.



4
5
6
# File 'lib/noggin/edge.rb', line 4

def dest
  @dest
end

#forward_inputObject

Returns the value of attribute forward_input.



4
5
6
# File 'lib/noggin/edge.rb', line 4

def forward_input
  @forward_input
end

#forward_outputObject

Returns the value of attribute forward_output.



4
5
6
# File 'lib/noggin/edge.rb', line 4

def forward_output
  @forward_output
end

#originObject

Returns the value of attribute origin.



4
5
6
# File 'lib/noggin/edge.rb', line 4

def origin
  @origin
end

#weightObject

Returns the value of attribute weight.



4
5
6
# File 'lib/noggin/edge.rb', line 4

def weight
  @weight
end

Instance Method Details

#backward_activate!Object



19
20
21
22
# File 'lib/noggin/edge.rb', line 19

def backward_activate!
  @backward_output = dest.backward_output * weight
  @derivative = dest.backward_output * origin.forward_output
end

#forward_activate!Object



15
16
17
# File 'lib/noggin/edge.rb', line 15

def forward_activate!
  @forward_output = @forward_input * weight
end

#learn!Object



24
25
26
27
# File 'lib/noggin/edge.rb', line 24

def learn!
  @weight -= @learning_rate * @derivative + (@previous_derivative * @momentum)
  @previous_derivative = @derivative
end