Module: Neuronet::Backpropagate

Included in:
MiddleNeuron, Neuron, OutputNeuron
Defined in:
lib/neuronet/backpropagate.rb

Overview

Backpropagate provides simple, clamp-limited weight/bias updates.

Instance Method Summary collapse

Instance Method Details

#backpropagate(error) ⇒ Object

Back-propagates errors, updating bias and connection weights. Clamps updates to [-max, +max]. Recursively calls on connected neurons. rubocop: disable Metrics, Style



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/neuronet/backpropagate.rb', line 10

def backpropagate(error)
  bmax = Config.bias_clamp
  b = bias + error
  self.bias = b.abs > bmax ? (b.positive? ? bmax : -bmax) : b

  wmax = Config.weight_clamp
  connections.each do |c|
    n = c.neuron
    w = c.weight + (n.activation * error)
    c.weight = w.abs > wmax ? (w.positive? ? wmax : -wmax) : w
    n.backpropagate(error)
  end
end