- java.lang.Object
-
- net.finmath.optimizer.GoldenSectionSearch
-
public class GoldenSectionSearch extends Object
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); }
- Version:
- 1.1
- Author:
- Christian Fries - http://www.christian-fries.de
-
-
Field Summary
Fields Modifier and Type Field Description static double
GOLDEN_SECTION_RATIO
-
Constructor Summary
Constructors Constructor Description GoldenSectionSearch(double leftPoint, double rightPoint)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description double
getAccuracy()
double
getBestPoint()
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
getNextPoint()
Returns the next point for which a valuation is requested.int
getNumberOfIterations()
boolean
isDone()
static void
main(String[] args)
GoldenSectionSearch
optimize()
void
setValue(double value)
Set the value corresponding to the point returned by a previous call ofgetNextPoint()
.double
value(double parameter)
-
-
-
Method Detail
-
main
public static void main(String[] args)
-
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
public GoldenSectionSearch 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.
-
-