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

java.lang.Object
  extended by edu.jhu.bme.smile.commons.optimize.FunctionNumericNDDifferentiation
All Implemented Interfaces:
OptimizableNDContinuous, OptimizableNDContinuousDifferentiable

public class FunctionNumericNDDifferentiation
extends java.lang.Object
implements OptimizableNDContinuousDifferentiable

This class does numeric differentiation in ND. There are lots of methods of doing so, and depending on how many points are used, enter that value in for the method variable. Also computes 2nd derivatives and hessians Defaults to 3-point method.

Author:
Yufeng Guo, Hanlin Wan

Constructor Summary
FunctionNumericNDDifferentiation(OptimizableNDContinuous function)
          Creates an object which can differentiate an ND function with default values.
FunctionNumericNDDifferentiation(OptimizableNDContinuous function, double step, int method)
          Creates an object which can differentiate an ND function in various ways.
 
Method Summary
 double[][] get2ndDerivative(double[] x)
          Creates the hessian matrix
 double get2ndDerivative(double[] x, int dim1, int dim2)
          Gets 2nd partial derivative for the dimensions given
 double[] getDerivative(double[] x)
          Gets the gradient
 double[] getDomainMax()
          Gets the domain maximum
 double[] getDomainMin()
          Gets the domain minimum
 double getDomainTolerance()
          Gets the tolerance
 int getMethod()
          Gets the method used
 int getNumberOfDimensions()
          Gets the number of dimensions
 double getStep()
          Gets the step size used
 double getValue(double[] x)
          Gets the value
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FunctionNumericNDDifferentiation

public FunctionNumericNDDifferentiation(OptimizableNDContinuous function)
Creates an object which can differentiate an ND function with default values. Step is 1e-5 and method is 3-point.

Parameters:
function - the function to be differentiated

FunctionNumericNDDifferentiation

public FunctionNumericNDDifferentiation(OptimizableNDContinuous function,
                                        double step,
                                        int method)
Creates an object which can differentiate an ND function in various ways.

Parameters:
function - the function to be differentiated
step - the step size
method - the differentiating method requested: 0,1,3,5,7, or 9. Default is 3.
Method Detail

get2ndDerivative

public double get2ndDerivative(double[] x,
                               int dim1,
                               int dim2)
Gets 2nd partial derivative for the dimensions given

Specified by:
get2ndDerivative in interface OptimizableNDContinuousDifferentiable
Parameters:
x - a double array that contains the location of the derivative required
dim1 - the first dimension of the derivative
dim2 - the second dimension of the derivative
Returns:
the 2nd derivative

get2ndDerivative

public double[][] get2ndDerivative(double[] x)
Creates the hessian matrix

Specified by:
get2ndDerivative in interface OptimizableNDContinuousDifferentiable
Parameters:
x - location to evaluate derivative at
Returns:
hessian matrix at location x

getDerivative

public double[] getDerivative(double[] x)
Gets the gradient

Specified by:
getDerivative in interface OptimizableNDContinuousDifferentiable
Parameters:
x - location to evaluate derivative at
Returns:
gradient at location x

getMethod

public int getMethod()
Gets the method used

Returns:
method

getStep

public double getStep()
Gets the step size used

Returns:
step size

getDomainMax

public double[] getDomainMax()
Gets the domain maximum

Specified by:
getDomainMax in interface OptimizableNDContinuous
Returns:
domain max

getDomainMin

public double[] getDomainMin()
Gets the domain minimum

Specified by:
getDomainMin in interface OptimizableNDContinuous
Returns:
domain min

getDomainTolerance

public double getDomainTolerance()
Gets the tolerance

Specified by:
getDomainTolerance in interface OptimizableNDContinuous
Returns:
tolerance

getValue

public double getValue(double[] x)
Gets the value

Specified by:
getValue in interface OptimizableNDContinuous
Parameters:
x - location to get value at
Returns:
value at location x

getNumberOfDimensions

public int getNumberOfDimensions()
Gets the number of dimensions

Specified by:
getNumberOfDimensions in interface OptimizableNDContinuous
Returns:
number of dimensions