Top Description Fields Constructors Methods
org.apache.commons.math3.optim.nonlinear.scalar.noderiv

public abstract Class AbstractSimplex

extends Object
implements OptimizationData
Class Inheritance
All Implemented Interfaces
org.apache.commons.math3.optim.OptimizationData
Known Direct Subclasses
org.apache.commons.math3.optim.nonlinear.scalar.noderiv.MultiDirectionalSimplex, org.apache.commons.math3.optim.nonlinear.scalar.noderiv.NelderMeadSimplex
Imports
java.util.Arrays, .Comparator, org.apache.commons.math3.analysis.MultivariateFunction, org.apache.commons.math3.exception.NotStrictlyPositiveException, .DimensionMismatchException, .ZeroException, .OutOfRangeException, .NullArgumentException, .MathIllegalArgumentException, org.apache.commons.math3.exception.util.LocalizedFormats, org.apache.commons.math3.optim.PointValuePair, .OptimizationData

This class implements the simplex concept. It is intended to be used in conjunction with SimplexOptimizer.
The initial configuration of the simplex is set by the constructors AbstractSimplex(double[]) or AbstractSimplex(double[][]). The other constructor will set all steps to 1, thus building a default configuration from a unit hypercube.
Users must call the build method in order to create the data structure that will be acted on by the other methods of this class.
Since
3.0
See Also
SimplexOptimizer

Field Summary

Modifier and TypeField and Description
private final int
dimension

Simplex dimension (must be equal to simplex.length - 1).

private PointValuePair[]
simplex

Simplex.

private double[][]
startConfiguration

Start simplex configuration.

Constructor Summary

AccessConstructor and Description
protected
AbstractSimplex(int
Dimension of the simplex.
n
)

Build a unit hypercube simplex.

protected
AbstractSimplex(int
Dimension of the simplex.
n
,
double
Length of the sides of the hypercube.
sideLength
)

Build a hypercube simplex with the given side length.

protected
AbstractSimplex(final double[]
Steps along the canonical axes representing box edges. They may be negative but not zero.
steps
)

The start configuration for simplex is built from a box parallel to the canonical axes of the space.

protected
AbstractSimplex(final double[][]
Reference simplex.
referenceSimplex
)

The real initial simplex will be set up by moving the reference simplex such that its first point is located at the start point of the optimization.

Method Summary

Modifier and TypeMethod and Description
public void
build(final double[]
First point of the simplex.
startPoint
)

Build an initial simplex.

private static double[]

Returns:

the steps.
createHypercubeSteps
(int
Dimension of the hypercube.
n
,
double
Length of the sides of the hypercube.
sideLength
)

Create steps for a unit hypercube.

public void
evaluate(final MultivariateFunction
Evaluation function.
evaluationFunction
,
final Comparator<PointValuePair>
Comparator to use to sort simplex vertices from best to worst.
comparator
)

Evaluate all the non-evaluated points of the simplex.

public int

Returns:

the dimension of the simplex.
getDimension
()

Get simplex dimension.

public PointValuePair

Returns:

the point at location index.
getPoint
(int
Location.
index
)

Get the simplex point stored at the requested index.

public PointValuePair[]

Returns:

all the simplex points.
getPoints
()

Get the points of the simplex.

public int

Returns:

the size of the simplex.
getSize
()

Get simplex size.

public abstract void
iterate(final MultivariateFunction
Evaluation function.
evaluationFunction
,
final Comparator<PointValuePair>
Comparator to use to sort simplex vertices from best to worst.
comparator
)

Compute the next simplex of the algorithm.

protected void
replaceWorstPoint(PointValuePair
Point to insert.
pointValuePair
,
final Comparator<PointValuePair>
Comparator to use for sorting the simplex vertices from best to worst.
comparator
)

Replace the worst point of the simplex by a new point.

protected void
setPoint(int
Location.
index
,
PointValuePair
New value.
point
)

Store a new point at location index.

protected void
setPoints(PointValuePair[]
New Points.
points
)

Replace all points.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

dimensionback to summary
private final int dimension

Simplex dimension (must be equal to simplex.length - 1).

simplexback to summary
private PointValuePair[] simplex

Simplex.

startConfigurationback to summary
private double[][] startConfiguration

Start simplex configuration.

Constructor Detail

AbstractSimplexback to summary
protected AbstractSimplex(int n)

Build a unit hypercube simplex.

Parameters
n:int

Dimension of the simplex.

AbstractSimplexback to summary
protected AbstractSimplex(int n, double sideLength)

Build a hypercube simplex with the given side length.

Parameters
n:int

Dimension of the simplex.

sideLength:double

Length of the sides of the hypercube.

AbstractSimplexback to summary
protected AbstractSimplex(final double[] steps)

The start configuration for simplex is built from a box parallel to the canonical axes of the space. The simplex is the subset of vertices of a box parallel to the canonical axes. It is built as the path followed while traveling from one vertex of the box to the diagonally opposite vertex moving only along the box edges. The first vertex of the box will be located at the start point of the optimization. As an example, in dimension 3 a simplex has 4 vertices. Setting the steps to (1, 10, 2) and the start point to (1, 1, 1) would imply the start simplex would be: { (1, 1, 1), (2, 1, 1), (2, 11, 1), (2, 11, 3) }. The first vertex would be set to the start point at (1, 1, 1) and the last vertex would be set to the diagonally opposite vertex at (2, 11, 3).

Parameters
steps:double[]

Steps along the canonical axes representing box edges. They may be negative but not zero.

Exceptions
NullArgumentException:
if steps is null.
ZeroException:
if one of the steps is zero.
AbstractSimplexback to summary
protected AbstractSimplex(final double[][] referenceSimplex)

The real initial simplex will be set up by moving the reference simplex such that its first point is located at the start point of the optimization.

Parameters
referenceSimplex:double[][]

Reference simplex.

Exceptions
NotStrictlyPositiveException:
if the reference simplex does not contain at least one point.
DimensionMismatchException:
if there is a dimension mismatch in the reference simplex.
IllegalArgumentException:
if one of its vertices is duplicated.

Method Detail

buildback to summary
public void build(final double[] startPoint)

Build an initial simplex.

Parameters
startPoint:double[]

First point of the simplex.

Exceptions
DimensionMismatchException:
if the start point does not match simplex dimension.
createHypercubeStepsback to summary
private static double[] createHypercubeSteps(int n, double sideLength)

Create steps for a unit hypercube.

Parameters
n:int

Dimension of the hypercube.

sideLength:double

Length of the sides of the hypercube.

Returns:double[]

the steps.

evaluateback to summary
public void evaluate(final MultivariateFunction evaluationFunction, final Comparator<PointValuePair> comparator)

Evaluate all the non-evaluated points of the simplex.

Parameters
evaluationFunction:MultivariateFunction

Evaluation function.

comparator:Comparator<PointValuePair>

Comparator to use to sort simplex vertices from best to worst.

Exceptions
TooManyEvaluationsException:
if the maximal number of evaluations is exceeded.
getDimensionback to summary
public int getDimension()

Get simplex dimension.

Returns:int

the dimension of the simplex.

getPointback to summary
public PointValuePair getPoint(int index)

Get the simplex point stored at the requested index.

Parameters
index:int

Location.

Returns:PointValuePair

the point at location index.

getPointsback to summary
public PointValuePair[] getPoints()

Get the points of the simplex.

Returns:PointValuePair[]

all the simplex points.

getSizeback to summary
public int getSize()

Get simplex size. After calling the build method, this method will will be equivalent to getDimension() + 1.

Returns:int

the size of the simplex.

iterateback to summary
public abstract void iterate(final MultivariateFunction evaluationFunction, final Comparator<PointValuePair> comparator)

Compute the next simplex of the algorithm.

Parameters
evaluationFunction:MultivariateFunction

Evaluation function.

comparator:Comparator<PointValuePair>

Comparator to use to sort simplex vertices from best to worst.

Exceptions
TooManyEvaluationsException:
if the algorithm fails to converge.
replaceWorstPointback to summary
protected void replaceWorstPoint(PointValuePair pointValuePair, final Comparator<PointValuePair> comparator)

Replace the worst point of the simplex by a new point.

Parameters
pointValuePair:PointValuePair

Point to insert.

comparator:Comparator<PointValuePair>

Comparator to use for sorting the simplex vertices from best to worst.

setPointback to summary
protected void setPoint(int index, PointValuePair point)

Store a new point at location index. Note that no deep-copy of point is performed.

Parameters
index:int

Location.

point:PointValuePair

New value.

setPointsback to summary
protected void setPoints(PointValuePair[] points)

Replace all points. Note that no deep-copy of points is performed.

Parameters
points:PointValuePair[]

New Points.