java.lang.Object
net.finmath.optimizer.GoldenSectionSearch
This class implements a Golden Section search algorithm, i.e., a minimization,
implemented as a question-and-answer search algorithm.
Example:
GoldenSectionSearch search = new GoldenSectionSearch(-1.0, 5.0);
while(search.getAccuracy() > 1E-11 && !search.isDone()) {
double x = search.getNextPoint();
double y = (x - 0.656) * (x - 0.656);
search.setValue(y);
}
For an example on how to use this class see also its main method.- Version:
- 1.1
- Author:
- Christian Fries - http://www.christian-fries.de
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondouble
double
static double
getGoldenSection(double left, double right)
Get the golden section of an interval as gs * left + (1-gs) * right, where gs is GOLDEN_SECTION_RATIO.double
Returns the next point for which a valuation is requested.int
boolean
isDone()
static void
optimize()
void
setValue(double value)
Set the value corresponding to the point returned by a previous call ofgetNextPoint()
.double
value(double parameter)
-
Field Details
-
GOLDEN_SECTION_RATIO
public static final double GOLDEN_SECTION_RATIO
-
-
Constructor Details
-
GoldenSectionSearch
public GoldenSectionSearch(double leftPoint, double rightPoint)- Parameters:
leftPoint
- left point of search intervalrightPoint
- right point of search interval
-
-
Method Details
-
main
-
getBestPoint
public double getBestPoint()- Returns:
- Returns the best point obtained so far.
-
getNextPoint
public double getNextPoint()Returns the next point for which a valuation is requested.- Returns:
- Returns the next point for which a value should be set using
setValue
.
-
setValue
public void setValue(double value)Set the value corresponding to the point returned by a previous call ofgetNextPoint()
. If setValue is called without prior call to getNextPoint(), e.g., when called twice, a RuntimeException is thrown.- Parameters:
value
- Value corresponding to point returned by previousgetNextPoint()
call.
-
optimize
-
value
public double value(double parameter) -
getGoldenSection
public static double getGoldenSection(double left, double right)Get the golden section of an interval as gs * left + (1-gs) * right, where gs is GOLDEN_SECTION_RATIO.- Parameters:
left
- Left point of the interval.right
- Right point of the interval.- Returns:
- Returns the golden section of an interval.
-
getNumberOfIterations
public int getNumberOfIterations()- Returns:
- Returns the number of iterations needed so far.
-
getAccuracy
public double getAccuracy()- Returns:
- Returns the accuracy obtained so far.
-
isDone
public boolean isDone()- Returns:
- Returns true if the solver is unable to improve further. This may be either due to reached accuracy or due to no solution existing.
-