class Newral::Networks::Sigmoid
Public Instance Methods
adjust_weights( expected: nil, learning_rate:0.5, layer: :output, weights_at_output_nodes: nil, output: nil )
click to toggle source
depending on where the neuron is placed we need other infos to adjust the weights on output we just need the expected results for hidden neurons we also need to know the weights at the output nodes and the actual output of the network
# File lib/newral/networks/sigmoid.rb, line 45 def adjust_weights( expected: nil, learning_rate:0.5, layer: :output, weights_at_output_nodes: nil, output: nil ) error_delta = layer.to_sym == :output ? delta_rule( expected: expected ) : delta_rule_hidden( output: output, expected: expected, weights_at_output_nodes: weights_at_output_nodes ) @weights.each_with_index do |weight,idx| @weights[idx] = @weights[idx]-error_delta[ idx ]*learning_rate end end
delta_rule( expected: nil )
click to toggle source
if you want to know how this works visit mattmazur.com/2015/03/17/a-step-by-step-backpropagation-example/
# File lib/newral/networks/sigmoid.rb, line 12 def delta_rule( expected: nil ) error_delta = [] @weights.each_with_index do |weight,idx| input = calculate_input( @inputs[ idx ] ) error_delta << -(expected-output)*(output)*(1-output )*input end error_delta end
output()
click to toggle source
# File lib/newral/networks/sigmoid.rb, line 5 def output value = calculate_value @last_output = 1/(1+Math.exp(value*-1)) end