lib/newral/functions/base.rb
# finds the (local) minimum descent of a function
finds the (local) minimum descent of a function
finds the ( local ) minimum descent of a function
def find_minimum( start_input, max_iterations: 1000, treshold: 10**-9 , learning_rate: 0.01 )
        descent = calculate_descent( start_input )
        iterations = 0
        input = start_input
        while descent.abs >  treshold && iterations < max_iterations
          old_input = input
          input = input-descent.to_f*learning_rate
          new_descent = calculate_descent( input )
          learning_rate = learning_rate.to_f/10   if new_descent*descent < 0  
          descent = new_descent
          iterations = iterations+1
        end 
        { input: input, descent: descent, learning_rate: learning_rate, output: calculate( input ), iterations: iterations }
      end
def find_minimum ( start_input , max_iterations : 1000 , treshold : 10 ** - 9 , learning_rate : 0.01 ) descent = calculate_descent ( start_input ) iterations = 0 input = start_input while descent . abs > treshold && iterations < max_iterations old_input = input input = input - descent . to_f * learning_rate new_descent = calculate_descent ( input ) learning_rate = learning_rate . to_f / 10 if new_descent * descent < 0 descent = new_descent iterations = iterations + 1 end { input : input , descent : descent , learning_rate : learning_rate , output : calculate ( input ) , iterations : iterations } end
finds the (local) minimum descent of a function
finds the ( local ) minimum descent of a function
# slow down if descent changes
start_input
max_iterations
treshold
learning_rate