public class GoldenSectionSearch extends Object
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.Constructor and Description |
---|
GoldenSectionSearch(double leftPoint,
double rightPoint) |
Modifier and Type | Method and Description |
---|---|
double |
getAccuracy() |
double |
getBestPoint() |
double |
getNextPoint()
Returns the next point for which a valuation is requested.
|
int |
getNumberOfIterations() |
boolean |
isDone() |
static void |
main(String[] args) |
void |
optimize() |
void |
setValue(double value)
Set the value corresponding to the point returned by a previous call of
getNextPoint() . |
double |
value(double parameter) |
public GoldenSectionSearch(double leftPoint, double rightPoint)
leftPoint
- left point of search intervalrightPoint
- right point of search intervalpublic static void main(String[] args)
public double getBestPoint()
public double getNextPoint()
setValue
.public void setValue(double value)
getNextPoint()
.
If setValue is called without prior call to getNextPoint(),
e.g., when called twice, a RuntimeException is thrown.value
- Value corresponding to point returned by previous getNextPoint()
call.public void optimize()
public double value(double parameter)
public int getNumberOfIterations()
public double getAccuracy()
public boolean isDone()
Copyright © 2015. All rights reserved.