Class Minimization
- java.lang.Object
-
- jahuwaldt.tools.math.Minimization
-
public class Minimization extends java.lang.Object
A collection of static routines to find the minima or maxima of functions or sets of functions.Modified by: Joseph A. Huwaldt
- Version:
- January 23, 2014
- Author:
- Joseph A. Huwaldt Date: July 22, 2006
-
-
Constructor Summary
Constructors Constructor Description Minimization()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
bracket1D(double ax, double bx, double[] triple, double[] values, Evaluatable1D eval)
Method that searches in the downhill direction (defined by the function as evaluated at the initial points) and returns new points (in triple) that bracket a minimum of the function.static double
find(Evaluatable1D eval, double x1, double x2, double tol, double[] output)
Method that isolates the minimum of a 1D function to a fractional precision of about "tol".static double
find(Evaluatable1D eval, double ax, double bx, double cx, double tol, double[] output)
Method that isolates the minimum of a 1D function to a fractional precision of about "tol".static double
findND(ScalarFunctionND func, double[] p, int n, double tol)
Method that isolates the minimum of an n-Dimensional scalar function to a fractional precision of about "tol".static void
main(java.lang.String[] args)
Used to test out the methods in this class.
-
-
-
Constructor Detail
-
Minimization
public Minimization()
-
-
Method Detail
-
find
public static double find(Evaluatable1D eval, double x1, double x2, double tol, double[] output) throws RootException
Method that isolates the minimum of a 1D function to a fractional precision of about "tol". A version of Brent's method is used with derivative information if it is available or a version without if it is not.
- Parameters:
eval
- An evaluatable 1D function that returns the function value at x and optionally returns the function derivative value (d(fx)/dx) at x. It is guaranteed that "function()" will always be called before "derivative()".x1
- The lower bracket surrounding the minimum (assumed that minimum lies between x1 and x2).x2
- The upper bracket surrounding the root (assumed that minimum lies between x1 and x2).tol
- The root will be refined until it's accuracy is better than this. This should generally not be smaller than Math.sqrt(EPS)!output
- An optional 2-element array that will be filled in with the abscissa (x) and function minimum ordinate ( f(x) ) on output. output[xmin,f(xmin)]. Pass "null" if this is not required.- Returns:
- The abscissa (x) of the minimum value of f(x).
- Throws:
RootException
- Unable to find a minimum of the function.
-
find
public static double find(Evaluatable1D eval, double ax, double bx, double cx, double tol, double[] output) throws RootException
Method that isolates the minimum of a 1D function to a fractional precision of about "tol". A version of Brent's method is used with derivative information if it is available or a version without if it is not.
- Parameters:
eval
- An evaluatable 1D function that returns the function value at x and optionally returns the function derivative value (d(fx)/dx) at x. It is guaranteed that "function()" will always be called before "derivative()". The return value from the 1st call to "function()" is ignored.ax
- The lower bracket known to surround the minimum (assumed that minimum lies between ax and cx).bx
- Abscissa point that lies between ax and cx where f(bx) is less than both f(ax) and f(cx).cx
- The upper bracket known to surround the root (assumed that minimum lies between ax and cx).tol
- The root will be refined until it's accuracy is better than this. This should generally not be smaller than Math.sqrt(EPS)!output
- An optional 2-element array that will be filled in with the abscissa (x) and function minimum ordinate ( f(x) ) on output. output[xmin,f(xmin)]. Pass "null" if this is not required.- Returns:
- The abscissa (x) of the minimum value of f(x).
- Throws:
RootException
- Unable to find a minimum of the function.
-
bracket1D
public static void bracket1D(double ax, double bx, double[] triple, double[] values, Evaluatable1D eval) throws RootException
Method that searches in the downhill direction (defined by the function as evaluated at the initial points) and returns new points (in triple) that bracket a minimum of the function.- Parameters:
ax
- The lower bracket surrounding the minimum (assumed that minimum lies between ax and bx).bx
- The upper bracket surrounding the root (assumed that minimum lies between ax and bx).triple
- A 3-element array that will be filled in with the abcissa of the three points that bracket the minium triple[ax,bx,cx].values
- A 3-element array that contains the function values that correspond with the points ax, bx and cx in triple. Null may be passed for this if the function values are not required.eval
- An evaluatable 1D function that returns the function value at x and optionally returns the function derivative value (d(fx)/dx) at x. It is guaranteed that "function()" will always be called before "derivative()".- Throws:
RootException
-
findND
public static double findND(ScalarFunctionND func, double[] p, int n, double tol) throws RootException
Method that isolates the minimum of an n-Dimensional scalar function to a fractional precision of about "tol". If no derivatives are available then Powell's method is used. If derivatives are available, then a Polak-Reibiere minimization is used.
- Parameters:
func
- An evaluatable n-D scalar function that returns the function value at a point, p[1..n], and optionally returns the function derivatives (d(fx[1..n])/dx) at p[1..n]. It is guaranteed that "function()" will always be called before "derivatives()".p
- On input, this is the initial guess at the minimum point. On output, this is filled in with the values that minimize the function.n
- The number of variables in the array p.tol
- The convergence tolerance on the function value.- Returns:
- The minimum value of f(p[1..n]).
- Throws:
RootException
- if unable to find a minimum of the function.
-
main
public static void main(java.lang.String[] args)
Used to test out the methods in this class.
-
-