|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.hedgehog.HObject
com.hedgehog.math.functions.Function
com.hedgehog.math.functions.OneVariableFunction
public class OneVariableFunction
Title: OneVariableFunction - represents a 1-variable function of signature HDouble function(HDouble x).
Description: Represents a one-argument method of form: HDouble function(HDouble x). Note that HDouble is used as opposed to Double because Double has no setValue() method which makes it difficult to use when returning values via reference.
Copyright: Copyright (c) Hedgehog Software 2007-2009.
Company: Hedgehog Software
| Field Summary |
|---|
| Fields inherited from class com.hedgehog.math.functions.Function |
|---|
method |
| Fields inherited from class com.hedgehog.HObject |
|---|
mID, mName |
| Constructor Summary | |
|---|---|
OneVariableFunction()
Default constructor. |
|
OneVariableFunction(java.lang.reflect.Method method)
Constructor. |
|
OneVariableFunction(OneVariableFunction object)
Copy constructor. |
|
OneVariableFunction(java.lang.String className,
java.lang.String methodName)
Constructor. |
|
| Method Summary | |
|---|---|
double |
bisection(java.lang.Object object,
double x1,
double x2,
int max_iterations,
double tolerance,
HBoolean converged)
Returns the root of this function using the bisection method. |
HDouble |
evaluate(java.lang.Object object,
HDouble x)
Evaluates the method for the supplied invoking object and argument. |
double |
firstOrderNewtonRaphson(java.lang.Object object,
double x0,
double h,
int noOfDerivativePoints,
int max_iterations,
double tolerance,
HInteger iterations_to_converge,
HBoolean converged)
Performs Newton-Raphson method on a function without a specified first-derivative function. |
double |
firstOrderNewtonRaphson(java.lang.Object object,
double x0,
java.lang.reflect.Method derivative,
int max_iterations,
double tolerance,
HInteger iterations_to_converge,
HBoolean converged)
Performs Newton-Raphson method on a function with a specified first-derivative function. |
double |
gaussChebyshevIntegration(java.lang.Object object,
Interval interval,
int order)
Gauss-Chebyshev integration over the interval [a:b] ; i.e., Int w(x)y(x)dx where w(x)=1/sqrt(1-x^2). |
double |
gaussianIntegration(java.lang.Object object,
Interval interval,
int order)
Gaussian integration over the interval [a:b] order restricted to range [1:10] and a |
boolean |
isValid()
Tests whether or not a valid object. |
static boolean |
isValid(java.lang.reflect.Method m)
Static version of isValid(). |
PairDouble |
optimisationBFGS(java.lang.Object object,
Interval interval,
double x0,
java.lang.reflect.Method firstDerivative)
Returns the minimum/maximum of the 1-variable function within the specified interval. |
double |
optimisationGA(java.lang.Object object,
Interval interval,
int populationSize,
int maxAllowedEvolutions,
java.lang.String xmlPathFileName,
HDouble bestSolutionFitnessValue)
Returns the maximum/minimum of the 1-variable function within the specified interval. |
java.util.Vector<TripleIntDoubleDouble> |
optimisationSwarm(java.lang.Object object,
Interval interval,
int nParticles,
int nIterations,
int neighbourhoodSize)
Performs a particle-swarm optimisation of this function of one variable. |
double |
parabolicInterpolationMinimum(java.lang.Object object,
double x1,
double x2,
double x3,
HDouble xmin,
HBoolean collinearPoints)
Returns the minimum function value of a parabola through the three points f(x1), f(x2) and f(x3) at the minimum xmin. |
double |
richardsonFirstDerivative(java.lang.Object object,
double x0,
double r,
double h)
Returns the first derivative of the function at point x0 using Richardson extrapolation. |
double |
simpsonsIntegration(java.lang.Object object,
double a,
double b,
int even_no_subintervals)
Simpson's rule of integration over the interval [a,b]. |
double |
taylorsSeriesFirstDerivative(java.lang.Object object,
double x0,
double h,
int nPoints)
Returns the first derivative using Taylor's series for either 2 or 4 points. |
double |
taylorsSeriesSecondDerivative(java.lang.Object object,
double x0,
double h,
int nPoints)
Returns the second derivative using Taylor's series for either 3 or 5 points. |
double |
trapezoidalIntegration(java.lang.Object object,
Interval interval,
int no_subintervals)
Trapeziodal rule of integration over the interval [a,b] |
int |
turningPoint(java.lang.Object object,
double xMinMaxInflexionPoint)
Determines whether the function at the specified point is a maxima, minima or point of inflexion. |
| Methods inherited from class com.hedgehog.math.functions.Function |
|---|
getMethod, setMethod, toString |
| Methods inherited from class com.hedgehog.HObject |
|---|
clone, compare, compareTo, copy, equals, getID, getName, hashCode, hasID, hasName, setID, setName |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public OneVariableFunction()
public OneVariableFunction(java.lang.reflect.Method method)
throws java.lang.IllegalArgumentException
Constructor. Sets the function to the specified method. Encapsulated method is set to null if an invalid object is specified. For example:
Class c = Class.forName("com.hedgehog.X") ;
Class funcArg = Class.forName("com.hedgehog.types.HDouble");
Class[] funcArgs = { funcArg } ;
Method function = c.getMethod("function",funcArgs) ;
OneVariableFunction ovf = new OneVariableFunction(function);
method - Function operated-on.
java.lang.IllegalArgumentException - Thrown if an invalid method is supplied. If exception thrown
then encapsulated method is set to null.
public OneVariableFunction(java.lang.String className,
java.lang.String methodName)
throws java.lang.IllegalArgumentException
className - Fully qualified name of class that method belongs to.methodName - Name of function operated-on.
java.lang.IllegalArgumentException - Thrown if an invalid method is supplied. If exception thrown
then encapsulated method is set to null.public OneVariableFunction(OneVariableFunction object)
object - Object to copy.| Method Detail |
|---|
public HDouble evaluate(java.lang.Object object,
HDouble x)
object - Invoking object.x - Argument value.
public double firstOrderNewtonRaphson(java.lang.Object object,
double x0,
java.lang.reflect.Method derivative,
int max_iterations,
double tolerance,
HInteger iterations_to_converge,
HBoolean converged)
throws java.lang.IllegalArgumentException,
java.lang.IllegalAccessException,
java.lang.reflect.InvocationTargetException
For example, to compute the square root of 2:
double x0=2.0;
HInteger iterations_to_converge = new HInteger(0);
HBoolean converged = new HBoolean(false);
double nr = ovf.firstOrderNewtonRaphson(this,x0,derivative,100,1e-06,iterations_to_converge,converged);
with function and derivative:
public static Double function(Double x)
{
double xv = x.doubleValue();
return new Double(xv*xv-2.0);
}
public static Double derivative(Double x)
{
double xv = x.doubleValue();
return new Double(2.0*xv);
}
object - Invoking object.x0 - Initial starting point.derivative - Derivative function. Must of type Double derivative(Double x).max_iterations - Maximum number of iterations.tolerance - Required tolerance; typically 1e-03.iterations_to_converge - Set upon return to the number of iterations to acheive requested convergence.converged - Set upon return to whether or not the routine converged.
java.lang.IllegalArgumentException - Thrown if the derivative function is invalid according to isValid().
java.lang.IllegalAccessException - Thrown if problem accessing the derivative function.
java.lang.reflect.InvocationTargetException - Thrown if problem invoking the derivative function.
public double firstOrderNewtonRaphson(java.lang.Object object,
double x0,
double h,
int noOfDerivativePoints,
int max_iterations,
double tolerance,
HInteger iterations_to_converge,
HBoolean converged)
throws java.lang.IllegalArgumentException
object - Invoking object.x0 - Initial starting point.h - Value of h for Taylor's series derivative.noOfDerivativePoints - Number of points in Taylor's series derivative; either 2 or 4.max_iterations - Maximum number of iterations.tolerance - Required tolerance; typically 1e-03.iterations_to_converge - Set upon return to the number of iterations to acheive requested convergence.converged - Set upon return to whether or not the routine converged.
java.lang.IllegalArgumentException - Thrown if noOfDerivativePoints is not 2 or 4.
public double bisection(java.lang.Object object,
double x1,
double x2,
int max_iterations,
double tolerance,
HBoolean converged)
object - Invoking object.x1 - Lower interval value.x2 - Upper interval value.max_iterations - Maximum number of iterations.tolerance - Required tolerance.converged - Set upon return to logical-true if a root is found, else logical-false.
public double gaussChebyshevIntegration(java.lang.Object object,
Interval interval,
int order)
throws java.lang.IllegalArgumentException
object - Invoking object.interval - Interval of intergration.order - Order of integration; restricted to range [1:10].
java.lang.IllegalArgumentException - exception if order < 1 or b
public double gaussianIntegration(java.lang.Object object,
Interval interval,
int order)
throws java.lang.IllegalArgumentException
object - Invoking object.interval - Interval of intergration.order - Order of integration. Must be in range [1:10].
java.lang.IllegalArgumentException - Thrown if order<1 or order>10, interval is null or bpublic boolean isValid()
isValid in class Functionpublic static boolean isValid(java.lang.reflect.Method m)
m - Method to test validity of.
public double optimisationGA(java.lang.Object object,
Interval interval,
int populationSize,
int maxAllowedEvolutions,
java.lang.String xmlPathFileName,
HDouble bestSolutionFitnessValue)
throws java.lang.Exception
object - Invoking object.interval - Interval within which solution is sought.populationSize - Number of chromosomes. The more Chromosomes the larger
number of potential solutions (which is good for finding the answer), but the
longer it will take to evolve the population. If a negative or zero value
is specified then it is set to 500.maxAllowedEvolutions - Maximum number of evolutions allowed. If a negative or zero value
is specified then it is set to 50.xmlPathFileName - XML path and file name to save solution for later reuse.bestSolutionFitnessValue - Returns, via reference, the function evaluation (eg f(xmin)) of the best solution obtained.
java.lang.Exception - Thrown in XML error.
public double parabolicInterpolationMinimum(java.lang.Object object,
double x1,
double x2,
double x3,
HDouble xmin,
HBoolean collinearPoints)
throws java.lang.IllegalArgumentException
object - Invoking object.x1 - Point 1.x2 - point 2.x3 - Point 3.xmin - Set upon return to the point at which the minimum occurs.collinearPoints - Set upon return to logical-true if the three points are collinear, else logical-false.
java.lang.IllegalArgumentException - Thrown if x1
public PairDouble optimisationBFGS(java.lang.Object object,
Interval interval,
double x0,
java.lang.reflect.Method firstDerivative)
throws FunctionEvaluationException
Example:
try
{
hedgehog.utility.Interval sinfInterval = new hedgehog.utility.Interval(180,360);
hedgehog.math.functions.library.SinFunction sinf = new hedgehog.math.functions.library.SinFunction(sinfInterval,true);
hedgehog.math.functions.OneVariableFunction ovf = new hedgehog.math.functions.OneVariableFunction("hedgehog.math.functions.library.SinFunction","evaluate");
double x0 = 200.0;
hedgehog.utility.PairDouble xmin_approx_deriv = ovf.optimisationBFGS(sinf,sinfInterval,x0,null);
java.lang.System.out.println("sinf min using approx deriv: " + xmin_approx_deriv);
}
catch (hedgehog.math.exceptions.FunctionEvaluationException e)
{
java.lang.System.out.println("error performing optimisation");
}
with output (exact minimum occurring at x=270 and sin(x)=-1):
sinf min using approx deriv: PairDouble -1 {(269.9999922533225,-0.9999999999999909)}
For further information refer to Gill, Murray and Wright(1981) "Practical Optimization", Academic Press and
Press et al () "Numerical Recipes in C++" (chapter 10), Cambridge University Press.
object - Invoking object.interval - Interval over which the optimisation is to be performed.x0 - Initial evaluation of x for function minimum/maximum.firstDerivative - Function first derivative. If unknown then set to null and the 4-point version of taylorsSeriesFirstDerivative() will be used.
FunctionEvaluationException - Thrown if an internal error occurred evaluating the min/max value.
public java.util.Vector<TripleIntDoubleDouble> optimisationSwarm(java.lang.Object object,
Interval interval,
int nParticles,
int nIterations,
int neighbourhoodSize)
throws java.lang.IllegalArgumentException
object - Invoking object.interval - Solution interval.nParticles - Number of particles.nIterations - Maximum number of iterations.neighbourhoodSize - Particle neighbourhood size.
java.lang.IllegalArgumentException - Thrown if 1) object is null, 2) interval is null, 3) nParticles<=0, 4) nIterations<=0 or 5) neighbourhoodSize<=0.
public double richardsonFirstDerivative(java.lang.Object object,
double x0,
double r,
double h)
throws java.lang.IllegalArgumentException
object - Invoking object.x0 - Point at which first derivative is to be evaluated.r - Value r.h - Value h.
java.lang.IllegalArgumentException - Thrown if h <0.
public double simpsonsIntegration(java.lang.Object object,
double a,
double b,
int even_no_subintervals)
throws java.lang.IllegalArgumentException
object - Object invoked by method.a - Minimum of interval [a:b].b - Maximum of interval [a:b].even_no_subintervals - Even number of subintervals.
java.lang.IllegalArgumentException - Thrown if any of the following are true: 1) even_no_subintervals<=0 or even_no_subintervals not even or 2) b < a.
public double taylorsSeriesFirstDerivative(java.lang.Object object,
double x0,
double h,
int nPoints)
throws java.lang.IllegalArgumentException
object - Invoking object.x0 - Point at whch derivative evaluated.h - Value of h. Typically 0.01 is sufficient.nPoints - The number of sample points at which the function is evaluated (2 or 4).
java.lang.IllegalArgumentException - Thrown if object==null, h
public double taylorsSeriesSecondDerivative(java.lang.Object object,
double x0,
double h,
int nPoints)
throws java.lang.IllegalArgumentException
object - Invoking object.x0 - Point at whch derivative evaluated.h - Value of h. Typically 0.01 is sufficient.nPoints - The number of sample points at which the function is evaluated (3 or 5)
java.lang.IllegalArgumentException - Thrown if object==null, h
public double trapezoidalIntegration(java.lang.Object object,
Interval interval,
int no_subintervals)
throws java.lang.IllegalArgumentException
object - Invoking object.interval - Interval in which integration is to be evaluated.no_subintervals - Number of sub-intervals.
java.lang.IllegalArgumentException - Thrown if no_subintervals<0, interval is null or b
public int turningPoint(java.lang.Object object,
double xMinMaxInflexionPoint)
throws java.lang.IllegalArgumentException
object - Invoking object.xMinMaxInflexionPoint - Point at which to evaluate function to test if maxima,
minima or inflexion point.
java.lang.IllegalArgumentException - Thrown if object is null.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||