edu.jhu.bme.smile.commons.optimize
Class BrentMethod1D

java.lang.Object
  extended by edu.jhu.bme.smile.commons.optimize.BrentMethod1D
All Implemented Interfaces:
Optimizer1DContinuous

public class BrentMethod1D
extends java.lang.Object
implements Optimizer1DContinuous

Optimizes functions by using Brent's method. It will interpolate a parabola from 3 points when the function is behaving nicely. The minimum of the parabola replaces the worst point, and a new parabola is created. This continues until the 3 points converge. It will then switch to the more robust method of golden section search when things are not nice. Adapted from Numerical Recipes.

Author:
Hanlin Wan

Constructor Summary
BrentMethod1D()
          Default constructor.
BrentMethod1D(int maxIter)
          Constructor to set maximum number of iterations to run
 
Method Summary
 double getExtrema()
          Gets the extrema that was found
 int getIterations()
          Gets the number of iterations done.
 java.util.ArrayList<double[]> getLog()
          Gets the logged data
 void initialize(Optimizable1DContinuous function)
          Initialize the optimizer with the 1D function.
 void logData(boolean turnOn, int maxSteps)
          Turns on logging for each iteration of the optimization.
 boolean optimize(boolean findMinima)
          Optimizes the function
 java.lang.String statusMessage()
          Gets the status message from the optimizing process
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BrentMethod1D

public BrentMethod1D()
Default constructor.


BrentMethod1D

public BrentMethod1D(int maxIter)
Constructor to set maximum number of iterations to run

Parameters:
maxIter - maximum number of iterations
Method Detail

logData

public void logData(boolean turnOn,
                    int maxSteps)
Turns on logging for each iteration of the optimization.

Parameters:
turnOn - true if logging, false if not
maxSteps - maximum number of steps to log

getLog

public java.util.ArrayList<double[]> getLog()
Gets the logged data

Returns:
array of logged data

getExtrema

public double getExtrema()
Gets the extrema that was found

Specified by:
getExtrema in interface Optimizer1DContinuous
Returns:
the location of where the extrema is

getIterations

public int getIterations()
Gets the number of iterations done.

Specified by:
getIterations in interface Optimizer1DContinuous
Returns:
number of iterations

initialize

public void initialize(Optimizable1DContinuous function)
Initialize the optimizer with the 1D function.

Specified by:
initialize in interface Optimizer1DContinuous
Parameters:
function - your Optimizable1DContinuous function

optimize

public boolean optimize(boolean findMinima)
Optimizes the function

Specified by:
optimize in interface Optimizer1DContinuous
Parameters:
findMinima - true if you want to find the minimum, false if you want to find the maximum
Returns:
true if extrema was found successfully, false otherwise

statusMessage

public java.lang.String statusMessage()
Gets the status message from the optimizing process

Specified by:
statusMessage in interface Optimizer1DContinuous
Returns:
string of the status message