Class AbstractSimplex
- java.lang.Object
-
- org.hipparchus.optim.nonlinear.scalar.noderiv.AbstractSimplex
-
- All Implemented Interfaces:
OptimizationData
- Direct Known Subclasses:
MultiDirectionalSimplex
,NelderMeadSimplex
public abstract class AbstractSimplex extends Object implements OptimizationData
This class implements the simplex concept. It is intended to be used in conjunction withSimplexOptimizer
.
The initial configuration of the simplex is set by the constructorsAbstractSimplex(double[])
orAbstractSimplex(double[][])
. The otherconstructor
will set all steps to 1, thus building a default configuration from a unit hypercube.
Users must call thebuild
method in order to create the data structure that will be acted on by the other methods of this class.- See Also:
SimplexOptimizer
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractSimplex(double[] steps)
The start configuration for simplex is built from a box parallel to the canonical axes of the space.protected
AbstractSimplex(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.protected
AbstractSimplex(int n)
Build a unit hypercube simplex.protected
AbstractSimplex(int n, double sideLength)
Build a hypercube simplex with the given side length.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
build(double[] startPoint)
Build an initial simplex.void
evaluate(MultivariateFunction evaluationFunction, Comparator<PointValuePair> comparator)
Evaluate all the non-evaluated points of the simplex.int
getDimension()
Get simplex dimension.PointValuePair
getPoint(int index)
Get the simplex point stored at the requestedindex
.PointValuePair[]
getPoints()
Get the points of the simplex.int
getSize()
Get simplex size.abstract void
iterate(MultivariateFunction evaluationFunction, Comparator<PointValuePair> comparator)
Compute the next simplex of the algorithm.protected void
replaceWorstPoint(PointValuePair pointValuePair, Comparator<PointValuePair> comparator)
Replace the worst point of the simplex by a new point.protected void
setPoint(int index, PointValuePair point)
Store a new point at locationindex
.protected void
setPoints(PointValuePair[] points)
Replace all points.
-
-
-
Constructor Detail
-
AbstractSimplex
protected AbstractSimplex(int n)
Build a unit hypercube simplex.- Parameters:
n
- Dimension of the simplex.
-
AbstractSimplex
protected AbstractSimplex(int n, double sideLength)
Build a hypercube simplex with the given side length.- Parameters:
n
- Dimension of the simplex.sideLength
- Length of the sides of the hypercube.
-
AbstractSimplex
protected AbstractSimplex(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
- Steps along the canonical axes representing box edges. They may be negative but not zero.- Throws:
NullArgumentException
- ifsteps
isnull
.MathIllegalArgumentException
- if one of the steps is zero.
-
AbstractSimplex
protected AbstractSimplex(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
- Reference simplex.- Throws:
MathIllegalArgumentException
- if the reference simplex does not contain at least one point.MathIllegalArgumentException
- if there is a dimension mismatch in the reference simplex.IllegalArgumentException
- if one of its vertices is duplicated.
-
-
Method Detail
-
getDimension
public int getDimension()
Get simplex dimension.- Returns:
- the dimension of the simplex.
-
getSize
public int getSize()
Get simplex size. After calling thebuild
method, this method will will be equivalent togetDimension() + 1
.- Returns:
- the size of the simplex.
-
iterate
public abstract void iterate(MultivariateFunction evaluationFunction, Comparator<PointValuePair> comparator)
Compute the next simplex of the algorithm.- Parameters:
evaluationFunction
- Evaluation function.comparator
- Comparator to use to sort simplex vertices from best to worst.- Throws:
MathIllegalStateException
- if the algorithm fails to converge.
-
build
public void build(double[] startPoint)
Build an initial simplex.- Parameters:
startPoint
- First point of the simplex.- Throws:
MathIllegalArgumentException
- if the start point does not match simplex dimension.
-
evaluate
public void evaluate(MultivariateFunction evaluationFunction, Comparator<PointValuePair> comparator)
Evaluate all the non-evaluated points of the simplex.- Parameters:
evaluationFunction
- Evaluation function.comparator
- Comparator to use to sort simplex vertices from best to worst.- Throws:
MathIllegalStateException
- if the maximal number of evaluations is exceeded.
-
replaceWorstPoint
protected void replaceWorstPoint(PointValuePair pointValuePair, Comparator<PointValuePair> comparator)
Replace the worst point of the simplex by a new point.- Parameters:
pointValuePair
- Point to insert.comparator
- Comparator to use for sorting the simplex vertices from best to worst.
-
getPoints
public PointValuePair[] getPoints()
Get the points of the simplex.- Returns:
- all the simplex points.
-
getPoint
public PointValuePair getPoint(int index)
Get the simplex point stored at the requestedindex
.- Parameters:
index
- Location.- Returns:
- the point at location
index
.
-
setPoint
protected void setPoint(int index, PointValuePair point)
Store a new point at locationindex
. Note that no deep-copy ofpoint
is performed.- Parameters:
index
- Location.point
- New value.
-
setPoints
protected void setPoints(PointValuePair[] points)
Replace all points. Note that no deep-copy ofpoints
is performed.- Parameters:
points
- New Points.
-
-