## org.apache.commons.math.optimization
Class MultiStartDifferentiableMultivariateRealOptimizer

    java.lang.Object
      org.apache.commons.math.optimization.MultiStartDifferentiableMultivariateRealOptimizer

All Implemented Interfaces:
  DifferentiableMultivariateRealOptimizer

    public class MultiStartDifferentiableMultivariateRealOptimizer

extends java.lang.Object
implements DifferentiableMultivariateRealOptimizer

Special implementation of the `DifferentiableMultivariateRealOptimizer` interface adding multi-start features to an existing optimizer.

This class wraps a classical optimizer to use it several times in turn with different starting points in order to avoid being trapped into a local extremum when looking for a global one.

Since:
  2.0
Version:
  $Revision: 811685 $ $Date: 2009-09-05 13:36:48 -0400 (Sat, 05 Sep 2009) $

Field Summary
`private RandomVectorGenerator` `generator` Random generator for multi-start.
`private int` `maxEvaluations` Maximal number of evaluations allowed.
`private int` `maxIterations` Maximal number of iterations allowed.
`private RealPointValuePair[]` `optima` Found optima.
`private DifferentiableMultivariateRealOptimizer` `optimizer` Underlying classical optimizer.
`private int` `starts` Number of starts to go.
`private int` `totalEvaluations` Number of evaluations already performed for all starts.
`private int` `totalGradientEvaluations` Number of gradient evaluations already performed for all starts.
`private int` `totalIterations` Number of iterations already performed for all starts.

Constructor Summary
`MultiStartDifferentiableMultivariateRealOptimizer(DifferentiableMultivariateRealOptimizer optimizer, int starts, RandomVectorGenerator generator)` Create a multi-start optimizer from a single-start optimizer

Method Summary
`RealConvergenceChecker` `getConvergenceChecker()` Get the convergence checker.
`int` `getEvaluations()` Get the number of evaluations of the objective function.
`int` `getGradientEvaluations()` Get the number of evaluations of the objective function gradient.
`int` `getIterations()` Get the number of iterations realized by the algorithm.
`int` `getMaxEvaluations()` Get the maximal number of functions evaluations.
`int` `getMaxIterations()` Get the maximal number of iterations of the algorithm.
`RealPointValuePair[]` `getOptima()` Get all the optima found during the last call to `optimize`.
`RealPointValuePair` `optimize(DifferentiableMultivariateRealFunction f, GoalType goalType, double[] startPoint)` Optimizes an objective function.
`void` `setConvergenceChecker(RealConvergenceChecker checker)` Set the convergence checker.
`void` `setMaxEvaluations(int maxEvaluations)` Set the maximal number of functions evaluations.
`void` `setMaxIterations(int maxIterations)` Set the maximal number of iterations of the algorithm.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### optimizer

    private final DifferentiableMultivariateRealOptimizer optimizer

  Underlying classical optimizer.

### maxIterations

    private int maxIterations

  Maximal number of iterations allowed.

### totalIterations

    private int totalIterations

  Number of iterations already performed for all starts.

### maxEvaluations

    private int maxEvaluations

  Maximal number of evaluations allowed.

### totalEvaluations

    private int totalEvaluations

  Number of evaluations already performed for all starts.

### totalGradientEvaluations

    private int totalGradientEvaluations

  Number of gradient evaluations already performed for all starts.

### starts

    private int starts

  Number of starts to go.

### generator

    private RandomVectorGenerator generator

  Random generator for multi-start.

### optima

    private RealPointValuePair[] optima

  Found optima.

Constructor Detail

### MultiStartDifferentiableMultivariateRealOptimizer

    public MultiStartDifferentiableMultivariateRealOptimizer(DifferentiableMultivariateRealOptimizer optimizer,
                                                             int starts,
                                                             RandomVectorGenerator generator)

  Create a multi-start optimizer from a single-start optimizer

  Parameters:
    `optimizer` - single-start optimizer to wrap
    `starts` - number of starts to perform (including the first one), multi-start is disabled if value is less than or equal to 1
    `generator` - random vector generator to use for restarts

Method Detail

### getOptima

    public RealPointValuePair[] getOptima()
                                   throws java.lang.IllegalStateException

  Get all the optima found during the last call to `optimize`.

  The optimizer stores all the optima found during a set of restarts. The `optimize` method returns the best point only. This method returns all the points found at the end of each starts, including the best one already returned by the `optimize` method.

  The returned array as one element for each start as specified in the constructor. It is ordered with the results from the runs that did converge first, sorted from best to worst objective value (i.e in ascending order if minimizing and in descending order if maximizing), followed by and null elements corresponding to the runs that did not converge. This means all elements will be null if the `optimize` method did throw a `ConvergenceException`). This also means that if the first element is non null, it is the best point found across all starts.

  Returns:
    array containing the optima
  Throws:
    `java.lang.IllegalStateException` - if `optimize` has not been called

### setMaxIterations

    public void setMaxIterations(int maxIterations)

  Set the maximal number of iterations of the algorithm.

  Specified by:
    `setMaxIterations` in interface `DifferentiableMultivariateRealOptimizer`
  Parameters:
    `maxIterations` - maximal number of function calls

### getMaxIterations

    public int getMaxIterations()

  Get the maximal number of iterations of the algorithm.

  Specified by:
    `getMaxIterations` in interface `DifferentiableMultivariateRealOptimizer`
  Returns:
    maximal number of iterations

### getIterations

    public int getIterations()

  Get the number of iterations realized by the algorithm.

  The number of evaluations corresponds to the last call to the `optimize` method. It is 0 if the method has not been called yet.

  Specified by:
    `getIterations` in interface `DifferentiableMultivariateRealOptimizer`
  Returns:
    number of iterations

### setMaxEvaluations

    public void setMaxEvaluations(int maxEvaluations)

  Set the maximal number of functions evaluations.

  Specified by:
    `setMaxEvaluations` in interface `DifferentiableMultivariateRealOptimizer`
  Parameters:
    `maxEvaluations` - maximal number of function evaluations

### getMaxEvaluations

    public int getMaxEvaluations()

  Get the maximal number of functions evaluations.

  Specified by:
    `getMaxEvaluations` in interface `DifferentiableMultivariateRealOptimizer`
  Returns:
    maximal number of functions evaluations

### getEvaluations

    public int getEvaluations()

  Get the number of evaluations of the objective function.

  The number of evaluations corresponds to the last call to the `optimize` method. It is 0 if the method has not been called yet.

  Specified by:
    `getEvaluations` in interface `DifferentiableMultivariateRealOptimizer`
  Returns:
    number of evaluations of the objective function

### getGradientEvaluations

    public int getGradientEvaluations()

  Get the number of evaluations of the objective function gradient.

  The number of evaluations corresponds to the last call to the `optimize` method. It is 0 if the method has not been called yet.

  Specified by:
    `getGradientEvaluations` in interface `DifferentiableMultivariateRealOptimizer`
  Returns:
    number of evaluations of the objective function gradient

### setConvergenceChecker

    public void setConvergenceChecker(RealConvergenceChecker checker)

  Set the convergence checker.

  Specified by:
    `setConvergenceChecker` in interface `DifferentiableMultivariateRealOptimizer`
  Parameters:
    `checker` - object to use to check for convergence

### getConvergenceChecker

    public RealConvergenceChecker getConvergenceChecker()

  Get the convergence checker.

  Specified by:
    `getConvergenceChecker` in interface `DifferentiableMultivariateRealOptimizer`
  Returns:
    object used to check for convergence

### optimize

    public RealPointValuePair optimize(DifferentiableMultivariateRealFunction f,
                                       GoalType goalType,
                                       double[] startPoint)
                                throws FunctionEvaluationException,
                                       OptimizationException

  Optimizes an objective function.

  Specified by:
    `optimize` in interface `DifferentiableMultivariateRealOptimizer`
  Parameters:
    `f` - objective function
    `goalType` - type of optimization goal: either `GoalType.MAXIMIZE` or `GoalType.MINIMIZE`
    `startPoint` - the start point for optimization
  Returns:
    the point/value pair giving the optimal value for objective function
  Throws:
    `FunctionEvaluationException` - if the objective function throws one during the search
    `OptimizationException` - if the algorithm failed to converge

Copyright (c) 2003-2011 Apache Software Foundation