Class: Minimization::FletcherReeves

Inherits:
NonLinearConjugateGradientMinimizer show all
Defined in:
lib/multidim/conjugate_gradient.rb

Overview

Conjugate Gradient Fletcher Reeves minimizer.

A multidimensional minimization methods.

Usage.

require 'minimization' f = proc{ |x| (x - 2)**2 + (x - 5)**2 + (x - 100)**2 } fd = proc{ |x| [ 2 * (x[0] - 2) , 2 * (x[1] - 5) , 2 * (x[2] - 100) ] } min = Minimization::FletcherReeves.minimize(f, fd, [0, 0, 0]) min.x_minimum min.f_minimum

Constant Summary

Constants inherited from NonLinearConjugateGradientMinimizer

NonLinearConjugateGradientMinimizer::EPSILON_DEFAULT, NonLinearConjugateGradientMinimizer::MAX_ITERATIONS_DEFAULT

Instance Attribute Summary

Attributes inherited from NonLinearConjugateGradientMinimizer

#converging, #f_minimum, #initial_step, #x_minimum

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from NonLinearConjugateGradientMinimizer

#converged, #f, #find_upper_bound, #gradient, #iterate, #line_search_func, #precondition, #solve

Constructor Details

#initialize(f, fd, start_point) ⇒ FletcherReeves

Returns a new instance of FletcherReeves.



227
228
229
# File 'lib/multidim/conjugate_gradient.rb', line 227

def initialize(f, fd, start_point)
  super(f, fd, start_point, :fletcher_reeves)
end

Class Method Details

.minimize(f, fd, start_point) ⇒ Object

Convenience method to minimize using Fletcher Reeves method

Parameters:

  • f: Function to minimize
  • fd: First derivative of f
  • start_point: Starting point

Usage:

f = proc{ |x| (x - 2)**2 + (x - 5)**2 + (x - 100)**2 } fd = proc{ |x| [ 2 * (x[0] - 2) , 2 * (x[1] - 5) , 2 * (x[2] - 100) ] } min = Minimization::FletcherReeves.minimize(f, fd, [0, 0, 0])



241
242
243
244
245
246
247
# File 'lib/multidim/conjugate_gradient.rb', line 241

def self.minimize(f, fd, start_point)
  min = Minimization::FletcherReeves.new(f, fd, start_point)
  while(min.converging?)
    min.iterate
  end
  return min
end