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

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

public class NewtonMethod1D
extends java.lang.Object
implements Optimizer1DContinuousDifferentiable

This optimizer uses Newton's Method of finding roots to find extrema. The extrema occur where the first derivative is 0. Newton's method takes the 2nd derivative of the original function to find the roots of the first derivative, which in turn gives you the extrema. This method depends heavily on what the derivative looks like. You must start close to the extrema. Otherwise, it might go in the right direction. But for nice functions, it is very fast.

Author:
Hanlin Wan

Constructor Summary
NewtonMethod1D()
          Default constructor.
NewtonMethod1D(int maxIter)
          Constructor to specify optimizer and maximum iterations
 
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(Optimizable1DContinuousDifferentiable function)
          Initialize the optimizer with the Differentiable 1D function.
 void initialize(Optimizable1DContinuousDifferentiable function, double init)
          Initialize the optimizer with the Differentiable 1D function.
 void logData(boolean turnOn, int maxSteps)
          Turns on logging for each iteration of the optimization.
 boolean optimize(boolean findMinima)
          Optimizes the function
 void setGamma(double g)
          Sets gamma, the coefficient to multiply the step by.
 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

NewtonMethod1D

public NewtonMethod1D()
Default constructor.


NewtonMethod1D

public NewtonMethod1D(int maxIter)
Constructor to specify optimizer and maximum iterations

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 Optimizer1DContinuousDifferentiable
Returns:
the extrema array of where the extrema is

getIterations

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

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

setGamma

public void setGamma(double g)
Sets gamma, the coefficient to multiply the step by. The flatter the function, the larger gamma could be. It should never exceed 1. The default is 1.

Parameters:
g - gamma

initialize

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

Specified by:
initialize in interface Optimizer1DContinuousDifferentiable
Parameters:
function - your Optimizable1DContinuousDifferentiable function

initialize

public void initialize(Optimizable1DContinuousDifferentiable function,
                       double init)
Initialize the optimizer with the Differentiable 1D function. You can set your initial point.

Parameters:
function - your Optimizable1DContinuousDifferentiable function
init - initial point

optimize

public boolean optimize(boolean findMinima)
Optimizes the function

Specified by:
optimize in interface Optimizer1DContinuousDifferentiable
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 Optimizer1DContinuousDifferentiable
Returns:
string of the status message