module GSL::MultiMin

Overview

This module implements Multidimensional Minimization

Usage examples:

center = {1.0, 2.0}
scale = {10.0, 20.0}
height = 30.0

result, min_x, min_f = GSL::MultiMin.find_min(initial: GSL::Vector.new([5.0, 7.0]), initial_step: 1.0, eps_abs: 1e-2, max_iter: 100) do |x|
  scale[0]*Math.sqr(x[0] - center[0]) + scale[1]*Math.sqr(x[1] - center[1]) + height
end

result.should eq GSL::Result::Success
min_x.should eq GSL::Vector.new([1.0, 2.0])
min_f.should eq 30.0
center = {1.0, 2.0}
scale = {10.0, 20.0}
height = 30.0

result, min_x, min_f = GSL::MultiMin.find_min(initial: GSL::Vector.new([5.0, 7.0]), initial_step: 1.0, eps_abs: 1e-2, max_iter: 100) do |x, y, dy|
  if y
    y.value = scale[0]*Math.sqr(x[0] - center[0]) + scale[1]*Math.sqr(x[1] - center[1]) + height
  end
  if dy
    dy[0] = 2.0*scale[0]*(x[0] - center[0])
    dy[1] = 2.0*scale[1]*(x[1] - center[1])
  end
end

result.should eq GSL::Result::Success
min_x.should eq GSL::Vector.new([1.0, 2.0])
min_f.should eq 30.0

Defined in:

gsl/maths/optimization/multimin.cr

Class Method Summary

Class Method Detail

def self.find_min(f : GSL::MultiMinFunction, initial : GSL::Vector, initial_step : GSL::Vector | Float64 = 1.0, eps_abs : Float64 = 1e-6, *, algorithm : GSL::MultiMin::AlgorithmF = GSL::MultiMin::AlgorithmF::NMSimplex2, max_iter = 10000) #

High-level interface to minimizer.

  • f - function to minimize
  • initial - initial guess
  • initial_step - initial step
  • eps_abs - tolerance by x. Iterations terminates when characteristic size of algorithm is <= eps_abs
  • algorithm - root finding algorithm to be used
  • max_iter - maximum number of iterations

returns {result, x_min, f_min}

  • result (type GSL::Result) represents result of minimization
  • x_min - value of x on last iteration
  • f_min - value of f on last iteration

[View source]
def self.find_min(initial : GSL::Vector, initial_step : GSL::Vector | Float64 = 1.0, eps_abs : Float64 = 1e-6, *, algorithm : GSL::MultiMin::AlgorithmF = GSL::MultiMin::AlgorithmF::NMSimplex2, max_iter = 10000, &f : GSL::MultiMinFunction) #

[View source]
def self.find_min_fdf(f : GSL::MultiMinFunctionFDF, initial : GSL::Vector, initial_step : Float64 = 0.01, eps_abs : Float64 = 1e-6, *, line_tol = 0.1, algorithm : GSL::MultiMin::AlgorithmFDF = GSL::MultiMin::AlgorithmFDF::BFGS2, max_iter = 10000) #

High-level interface to minimizer.

  • f - function to minimize
  • initial - initial guess
  • initial_step - initial step
  • eps_abs - tolerance by x. Iterations terminates when norm of gradient is <= eps_abs
  • algorithm - root finding algorithm to be used
  • max_iter - maximum number of iterations
  • line_tol - the accuracy of the line minimization (internal parameter) returns {result, x_min, f_min}
  • result (type GSL::Result) represents result of minimization
  • x_min - value of x on last iteration
  • f_min - value of f on last iteration

[View source]
def self.find_min_fdf(initial : GSL::Vector, initial_step : GSL::Vector | Float64 = 1.0, eps_abs : Float64 = 1e-6, *, algorithm : GSL::MultiMin::AlgorithmFDF = GSL::MultiMin::AlgorithmFDF::BFGS2, max_iter = 10000, &f : GSL::MultiMinFunctionFDF) #

[View source]