Class: Noggin::Edge
- Inherits:
-
Object
- Object
- Noggin::Edge
- Defined in:
- lib/noggin/edge.rb
Instance Attribute Summary collapse
-
#backward_input ⇒ Object
Returns the value of attribute backward_input.
-
#backward_output ⇒ Object
Returns the value of attribute backward_output.
-
#derivative ⇒ Object
Returns the value of attribute derivative.
-
#dest ⇒ Object
Returns the value of attribute dest.
-
#forward_input ⇒ Object
Returns the value of attribute forward_input.
-
#forward_output ⇒ Object
Returns the value of attribute forward_output.
-
#origin ⇒ Object
Returns the value of attribute origin.
-
#weight ⇒ Object
Returns the value of attribute weight.
Instance Method Summary collapse
- #backward_activate! ⇒ Object
- #forward_activate! ⇒ Object
-
#initialize(origin: origin, dest: dest, weight: rand(0.20...0.80), momentum: 1, learning_rate: 0.3) ⇒ Edge
constructor
A new instance of Edge.
- #learn! ⇒ Object
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_input ⇒ Object
Returns the value of attribute backward_input.
4 5 6 |
# File 'lib/noggin/edge.rb', line 4 def backward_input @backward_input end |
#backward_output ⇒ Object
Returns the value of attribute backward_output.
4 5 6 |
# File 'lib/noggin/edge.rb', line 4 def backward_output @backward_output end |
#derivative ⇒ Object
Returns the value of attribute derivative.
4 5 6 |
# File 'lib/noggin/edge.rb', line 4 def derivative @derivative end |
#dest ⇒ Object
Returns the value of attribute dest.
4 5 6 |
# File 'lib/noggin/edge.rb', line 4 def dest @dest end |
#forward_input ⇒ Object
Returns the value of attribute forward_input.
4 5 6 |
# File 'lib/noggin/edge.rb', line 4 def forward_input @forward_input end |
#forward_output ⇒ Object
Returns the value of attribute forward_output.
4 5 6 |
# File 'lib/noggin/edge.rb', line 4 def forward_output @forward_output end |
#origin ⇒ Object
Returns the value of attribute origin.
4 5 6 |
# File 'lib/noggin/edge.rb', line 4 def origin @origin end |
#weight ⇒ Object
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 |