Multidimensional Minimization

This chapter describes routines for finding minima of arbitrary multidimensional functions. The library provides low level components for a variety of iterative minimizers and convergence tests. These can be combined by the user to achieve the desired solution, while providing full access to the intermediate steps of the algorithms. Each class of methods uses the same framework, so that you can switch between minimizers at runtime without needing to recompile your program. Each instance of a minimizer keeps track of its own state, allowing the minimizers to be used in multi-threaded programs.

Contents:

  1. Overview

  2. Caveats

  3. Initializing the Multidimensional Minimizer

  4. Providing a function to minimize

  5. Iteration

  6. Stopping Criteria

  7. Examples

    1. FdfMinimizer

    2. FMinimizer

Overview

The problem of multidimensional minimization requires finding a point x such that the scalar function, takes a value which is lower than at any neighboring point. For smooth functions the gradient g = nabla f vanishes at the minimum. In general there are no bracketing methods available for the minimization of n-dimensional functions. The algorithms proceed from an initial guess using a search algorithm which attempts to move in a downhill direction.

Algorithms making use of the gradient of the function perform a one-dimensional line minimisation along this direction until the lowest point is found to a suitable tolerance. The search direction is then updated with local information from the function and its derivatives, and the whole process repeated until the true n-dimensional minimum is found.

The Nelder-Mead Simplex algorithm applies a different strategy. It maintains n+1 trial parameter vectors as the vertices of a n-dimensional simplex. In each iteration step it tries to improve the worst vertex by a simple geometrical transformation until the size of the simplex falls below a given tolerance.

Both types of algorithms use a standard framework. The user provides a high-level driver for the algorithms, and the library provides the individual functions necessary for each of the steps. There are three main phases of the iteration. The steps are,

Each iteration step consists either of an improvement to the line-minimisation in the current direction or an update to the search direction itself. The state for the minimizers is held in a GSL::MultiMin::FdfMinimizer or a GSL::MultiMin::FMinimizer object.

Caveats

Note that the minimization algorithms can only search for one local minimum at a time. When there are several local minima in the search area, the first minimum to be found will be returned; however it is difficult to predict which of the minima this will be. In most cases, no error will be reported if you try to find a local minimum in an area where there is more than one.

It is also important to note that the minimization algorithms find local minima; there is no way to determine whether a minimum is a global minimum of the function in question.

Initializing the Multidimensional Minimizer





Providing a function to minimize

You must provide a parametric function of n variables for the minimizers to operate on. You may also need to provide a routine which calculates the gradient of the function. In order to allow for general parameters the functions are defined by the classes, GSL::MultiMin::Function_fdf and GSL::MultiMin::Function.



Iteration




Stopping Criteria

A minimization procedure should stop when one of the following conditions is true:

The handling of these conditions is under user control. The methods below allow the user to test the precision of the current result.



Examples

FdfMinimizer

#!/usr/bin/env ruby
require("gsl")
include GSL::MultiMin

my_f = Proc.new { |v, params|
  x = v[0]; y = v[1]
  p0 = params[0]; p1 = params[1]
  10.0*(x - p0)*(x - p0) + 20.0*(y - p1)*(y - p1) + 30.0
}

my_df = Proc.new { |v, params, df|
  x = v[0]; y = v[1]
  p0 = params[0]; p1 = params[1]
  df[0] = 20.0*(x-p0)
  df[1] = 40.0*(y-p1)
}

my_func = Function_fdf.alloc(my_f, my_df, 2)
my_func.set_params([1.0, 2.0])      # parameters

x = Vector.alloc(5.0, 7.0)          # starting point

minimizer = FdfMinimizer.alloc("conjugate_fr", 2)
minimizer.set(my_func, x, 0.01, 1e-4)

iter = 0
begin
  iter += 1
  status = minimizer.iterate()
  status = minimizer.test_gradient(1e-3)
  if status == GSL::SUCCESS
    puts("Minimum found at")
  end
  x = minimizer.x
  f = minimizer.f
  printf("%5d %.5f %.5f %10.5f\n", iter, x[0], x[1], f)
end while status == GSL::CONTINUE and iter < 100

FMinimizer

#!/usr/bin/env ruby
require("gsl")
include GSL::MultiMin

np = 2

my_f = Proc.new { |v, params|
  x = v[0]; y = v[1]
  p0 = params[0]; p1 = params[1]
  10.0*(x - p0)*(x - p0) + 20.0*(y - p1)*(y - p1) + 30.0
}

my_func = Function.alloc(my_f, np)
my_func.set_params([1.0, 2.0])      # parameters

x = Vector.alloc([5, 7])
ss = Vector.alloc(np)
ss.set_all(1.0)

minimizer = FMinimizer.alloc("nmsimplex", np)
minimizer.set(my_func, x, ss)

iter = 0
begin
  iter += 1
  status = minimizer.iterate()
  status = minimizer.test_size(1e-2)
  if status == GSL::SUCCESS
    puts("converged to minimum at")
  end
  x = minimizer.x
  printf("%5d ", iter);
  for i in 0...np do
    printf("%10.3e ", x[i])
  end
  printf("f() = %7.3f size = %.3f\n", minimizer.fval, minimizer.size);
end while status == GSL::CONTINUE and iter < 100

prev next

Reference index top