1-d and n-d Functions
Mathwrist C++ API Series
Abstract
This document details the C++ programming interface of 1-d and n-d mathematical functions, 1-d interpolation, 1-d integration, 1-d root finding and 1-d minimization features in Mathwrist’s Numerical Programming Library (NPL). Please refer to of our 1-d and n-d function white paper for a technical overview of these features.
1 1-d Functions
1.1 Function1D Base Class
Function1D is the pure virtual base class for all 1-dimensional functions. It is defined in header file “function_1d.h”.
1.1.1 Clone
Description:
For concrete derived classes to create a cloned object.
1.1.2 Evaluation
Description:
Return the function value at a given point . Parameter _derv1 and _derv2 are optional. If non-zero pointers are provided, it is expected to compute the first and second derivatives of respectively and save the result to the supplied pointers.
1.1.3 Integration
Description:
Return the finite integral of the function. The Function1D base class by default throws an un-supported exception in this integral() function. It is upto the derived classes to override this default behavior if necessary.
1.1.4 Finite Difference Approximation
Description:
For convenience, the Function1D base class provides these derivative approximation functions using finite difference method. A smooth function derived from the Function1D base class may use these approximation methods as appropriate. The default bump size is , where is the machine epsilon. A derived class may change this bump size by overriding a protected member function Function1D::pertubed_size().
-
1.
Return the approximation of the first derivative by forward finite difference. .
-
2.
Return the approximation of the first derivative by center finite difference. .
-
3.
Return the approximation of the second derivative by forward finite difference on the first derivatives. . The implementation of function is expected to compute first derivatives and .
-
4.
Return the approximation of the second derivative by center finite difference. . Optional parameter _base_value holds the function value , if a non-zero pointer is supplied.
1.2 1-d Piecewise Function
Class FunctPiecewise is an intermediate pure virtual class to represent 1-d piecewise functions, defined in C++ header file “funtion_pw.h”. It is derived from Function1D base class. Concrete piecewise functions are further derived from this FunctPiecewise intermediate class.
1.2.1 Piece Lookup
Description:
Given a buffer of knot points in ascending order, return the offset set such that or return if is numerically equal to .
Parameter _x_begin is a pointer to the buffer address. Parameter n_x specifies the number of elements in the buffer. Parameter x is the lookup value.
REQUIRED: . An out of range exception will be thrown otherwise.
1.2.2 Knot Point Functions
Description:
-
1.
Return the number of knot points.
-
2.
Return the address of the knot point buffer.
1.2.3 Integration
Description:
-
1.
Implement the virtual integral() function declared in Function1D base class by summing up piecewise integrals.
-
2.
Refresh the internal cache of piecewise integrals, i.e after function value changes.
1.3 Piecewise Constant Function
Class FunctPiecewiseConst is a concrete type to represent 1-d piecewise constant functions. It is derived from the intermediate FunctPiecewise class.
1.3.1 Constructor
Description:
-
1.
Default contructor, create an empty object.
-
2.
Initialize the piecewise constant function with number of knot points and function values at .
Parameter n is the number of knot points. Parameter _x points to the buffer of knot points sorted in ascending order. Parameter _y points to the buffer of function values.
REQUIRED: The piecewise function internally just saves the pointer address _x and _y. Hence, the memory of these knot points and function values must be valid during the entire life of the piecewise function. The memory of _x and _y are not freed by the destructor.
1.3.2 Piecewise Values
Description:
This function returns the pointer of piecewise function values .
1.3.3 Evaluation
Description:
This function implements the public interface of the Function1D base class. It returns a value , if . The first and second derivatives are 0. See also Function1D::eval().
1.3.4 Refresh Integral Cache
This function implements the public interface of the FunctPiecewise base class. Whenever the piecewise function values are changed, this refresh() function needs be called to recompute the piecewise integral cache. Please refer to FunctPiecewise::refresh() for API details.
1.4 Piecewise Linear Function
Class FunctPiecewiseLinear is a concrete type to represent 1-d continuous piecewise linear functions. It is derived from the intermediate FunctPiecewise class.
1.4.1 Constructor
Description:
-
1.
Default contructor, create an empty object.
-
2.
Initialize the piecewise linear function with number of knot points and function values at .
Parameter n is the number of knot points. Parameter _x points to the buffer of knot points sorted in ascending order. Parameter _y points to the buffer of function values.
REQUIRED: The piecewise function internally just saves the pointer address _x and _y. Hence, the memory of these knot points and function values must be valid during the entire life of the piecewise function. The memory of _x and _y are not freed by the destructor.
1.4.2 Piecewise Values
Description:
This function returns the pointer of piecewise function values .
1.4.3 Evaluation
Description:
This function implements the public interface of the Function1D base class. It returns a linearly interpolated value between and , if . The first derivative is the linear slope. The second derivative is 0. See also Function1D::eval().
1.4.4 Refresh Integral Cache
This function implements the public interface of the FunctPiecewise base class. Whenever the piecewise function values are changed, this refresh() function needs be called to recompute the piecewise integral cache. Please refer to FunctPiecewise::refresh() for API details.
1.5 Piecewise Linear with Jump Function
Class FunctPiecewiseLinearJump is a concrete type to represent non-continuous 1-d piecewise linear functions. It is derived from the intermediate FunctPiecewise class.
1.5.1 Constructor
Description:
-
1.
Default contructor, create an empty object.
-
2.
Initialize the piecewise linear non-continuous function with number of knot points and function values.
Parameter n is the number of knot points. Parameter _x points to the buffer of knot points sorted in ascending order. Parameter _y points to the buffer of function values. The function values are arranged by the start and end values of the first, second piece etc.
REQUIRED: The piecewise function internally just saves the pointer address _x and _y. Hence, the memory of these knot points and function values must be valid during the entire life of the piecewise function. The memory of _x and _y are not freed by the destructor.
1.5.2 Piecewise Values
Description:
This function returns the pointer of piecewise function values .
1.5.3 Evaluation
Description:
This function implements the public interface of the Function1D base class. It returns a linearly interpolated value between and , if . The first derivative is the linear slope. The second derivative is 0. See also Function1D::eval().
1.5.4 Refresh Integral Cache
This function implements the public interface of the FunctPiecewise base class. Whenever the piecewise function values are changed, this refresh() function needs be called to recompute the piecewise integral cache. Please refer to FunctPiecewise::refresh() for API details.
1.6 B-spline Curve
Class BSplineCurve is a concrete type to represent continuous (smooth) functions using piecewise B-spline basis. It is derived from the intermediate FunctPiecewise class. BSplineCurve class is defined in the header file “b_spline_curve.h”.
1.6.1 Constructor, Destructor and Copy
Description:
-
1.
Create a B-spline curve object of certain degree. Parameter degree is the degree of the B-spline basis. The degree is equal to B-spline’s order less 1.
-
2.
Copy constructor.
-
3.
Assignment operator to deep copy a B-spline object.
-
4.
Destructor, free all resources used by a B-spline object.
1.6.2 Knot Point Functions
Description:
-
1.
Set the knot points by evenly breaking the domain to pieces.
-
2.
Set the knot points with a given sequence of break points. Parameter x is the pointer address of the knot points. Parameter n is the total number of knot points.
1.6.3 Basis Functions
Description:
-
1.
Return the total number of basis functions used by the B-spline curve.
-
2.
Set the coefficients of B-spline basis functions. Parameter _beta is the pointer address to the coefficients. If a zero pointer is passed, the curve sets all coefficients equal to 0.
-
3.
Set the coefficients of B-spline basis functions. Parameter beta is a vector of the coefficients.
-
4.
Return a constant reference of the B-spline basis coefficients stored in the B-spline curve object.
1.6.4 Evaluation
Description:
This function implements the public interface of the Function1D base class. It returns the B-spline curve function value and computes derivatives. See also Function1D::eval().
1.7 Chebyshev Curve
Class ChebyshevCurve is a concrete type to represent continuous (smooth) functions using Chebyshev basis polynomials. It is a directly derived class from the Function1D base class. Class ChebyshevCurve is defined in header file “chebyshev_curve.h”.
1.7.1 Constructor
Description:
Constructor, create a Chebyshev curve object with working domain and a given degree of the approximation polynomial. Parameter a and b defines the domain . Parameter n_degree is the highest degree of Chebyshev basis polynomial to be used in the curve.
1.7.2 Query Functions
Description:
-
1.
Return the lower bound of the working domain.
-
2.
Return the upper bound of the working domain.
-
3.
Return the highest degree of Chebyshev basis polynomial used in the curve.
1.7.3 Basis Functions
Description:
-
1.
Set the coefficients of Chebyshev basis polynomials. Parameter _beta is the pointer address to the coefficients. If a zero pointer is passed, the curve sets all coefficients equal to 0.
-
2.
Set the coefficients of Chebyshev basis polynomials. Parameter beta is a vector of the coefficients.
-
3.
Return a constant reference of the Chebyshev basis coefficients stored in the Chebyshev curve object.
1.7.4 Evaluation
Description:
This function implements the public interface of the Function1D base class. It returns the Chebyshev curve function value and computes derivatives. See also Function1D::eval().
1.7.5 Integration
Description:
This function implements the public interface of the Function1D base class. It computes the finite integral over . See also Function1D::eval().
1.7.6 Approximation
Description:
This function approximates a given function and sets the coefficients of Chebyshev expansion basis by matching the function values at number of node points, where
-
•
is the highest degree of the Chebyshev polynomial;
-
•
node point .
2 n-d Functions
2.1 FunctionND Base Class
FunctionND is the pure virtual base class for all multi-dimensional functions. It is defined in header file “function_nd.h”.
2.1.1 Clone
Description:
For concrete derived classes to create a cloned object.
2.1.2 Evaluation
Description:
Return the function value at a given point . Parameter _g and _H are optional. If non-zero pointers are provided, it is expected to compute the gradient and Hessian of respectively and save the result to the supplied pointers.
2.1.3 Integration
Description:
Return the multi-dimensional finite integral of the function. The FunctionND base class by default throws an un-supported exception in this integral() function. It is upto the derived classes to override this default behavior if necessary. Parameters X_LO and X_HI are the vectors of lower and upper limits of the integral respectively.
2.1.4 Dimension Size
Description:
This function returns the actual dimension size of the n-d function.
2.1.5 Finite Difference Approximation
Description:
For convenience, the FunctionND base class provides gradient and Hessian approximation functions using finite difference method. A smooth n-d function derived from FunctionND base class may use these approximation funcitons as appropriate.
The default bump size is , where is the machine epsilon. A derived class may change this bump size by overriding a protected member function FunctionND::pertubed_size(). Let be a vector of zero elements except its -th element is equal to .
In the same order of the above listed functions,
-
1.
Return the approximation of the gradient by forward finite difference. .
-
2.
Return the gradient approximation by center finite difference. .
-
3.
This approximation method requires the derived n-d function to compute gradient vectors. It then uses the gradient forward difference to approximate the Hessian. , where is the partial derivative .
-
4.
This approximation doesn’t require gradient calculation. It approximate the Hessian by center difference of function values only. .
2.2 2-d Piecewise Function
Class FunctPiecewise2D is an intermediate pure virtual class to represent 2-d piecewise functions, defined in C++ header file “funtion_pw.h”. It is derived from FunctionND base class. Concrete 2-d piecewise functions are further derived from this FunctPiecewise2D intermediate class.
2.2.1 Knot Point Function
Description:
-
1.
Return the number of knot points along axis.
-
2.
Return the number of knot points along axis.
-
3.
Return the buffer address of knot points along axis.
-
4.
Return the buffer address of knot points along axis.
2.2.2 Integration
Description:
This function implements the virtual integral() function declared in FunctionND base class by summing up piecewise integrals.
2.3 2-d Piecewise Constant Function
Class FunctPiecewise2DConst is a concrete type to represent 2-d piecewise constant functions. It is derived from the intermediate FunctPiecewise2D class.
2.3.1 Constructors
Description:
-
1.
Default contructor, create an empty object.
-
2.
Initialize the 2-d piecewise constant function with number of knot points in axis, number of knot points in axis and number of piecewise function values at , , .
Parameter n_x and n_y are the number of knot points along and respectively. Parameter _x and _y point to the buffer of knot points sorted in ascending order along and respectively. Parameter _z points to the buffer of function values.
REQUIRED: The piecewise function internally just saves the pointer address _x, _y and _z. Hence, the memory of these knot points and function values must be valid during the entire life of the piecewise function. The memory of _x, _y and _z are not freed by the destructor.
2.3.2 Piecewise Values
Description:
This function returns the pointer of piecewise function values .
2.3.3 Evaluation
Description:
This function implements the public interface of the FunctionND base class. It returns a value , if and . The gradient and Hessian are set to 0 values, if non-zero pointers are supplied. See also FunctionND::eval().
2.4 B-spline Surface
Class BSplineSurface is a concrete type to represent continuous (smooth) surface using the tensor product of two sets of B-spline basis along and . It is derived from the intermediate FunctPiecewise2D class. BSplineSurface class is defined in the header file “b_spline_surface.h”.
2.4.1 Constructor, Destructor and Copy
Description:
-
1.
Create a B-spline surface of certain degrees. Parameter degree_x and degree_y are the degrees of the B-spline basis in and dimension. The degree is equal to B-spline’s order less 1.
-
2.
Copy constructor.
-
3.
Assignment operator to deep copy a B-spline surface object.
-
4.
Destructor, free all resources used by a B-spline surface object.
2.4.2 Knot Point Functions
Description:
-
1.
Set the knot points along dimension by evenly breaking the domain to pieces.
-
2.
Set the knot points along dimension by evenly breaking the domain to pieces.
-
3.
Set the knot points along dimension with a given sequence of break points. Parameter x is the pointer address of the knot points. Parameter n is the total number of knot points.
-
4.
Set the knot points along dimension with a given sequence of break points. Parameter y is the pointer address of the knot points. Parameter n is the total number of knot points.
2.4.3 Basis Functions
Description:
-
1.
Return the total number of basis functions along used by the surface.
-
2.
Return the total number of basis functions along used by the surface.
-
3.
Set the tensor product coefficients of B-spline basis functions. Parameter _theta is the pointer address to the basis coefficients, where and are the number of basis in and coordinate respectively. If a zero pointer is passed, the surface sets all coefficients equal to 0.
-
4.
Set the tensor product coefficient matrix of B-spline basis functions. Parameter theta is the coefficient matrix.
-
5.
Return a constant reference of the B-spline basis tensor product coefficients. Coefficient are stored in the surface object in row-wise major.
2.4.4 Evaluation
Description:
This function implements the public interface of the FunctionND base class. It returns the B-spline surface value and computes gradient and Hessian if required. See also FunctionND::eval().
2.5 Bi-linear Surface
Class BilinearSurface is a concrete type to represent bi-linear surfaces using the tensor product of two sets of linear basis along and . It is derived from the intermediate FunctPiecewise2D class. BilinearSurface class is defined in the header file “bi_linear_surface.h”.
2.5.1 Knot Point Functions
Description:
-
1.
Set the knot points along dimension by evenly breaking the domain to pieces.
-
2.
Set the knot points along dimension by evenly breaking the domain to pieces.
-
3.
Set the knot points along dimension with a given sequence of break points. Parameter x is the pointer address of the knot points. Parameter n is the total number of knot points.
-
4.
Set the knot points along dimension with a given sequence of break points. Parameter y is the pointer address of the knot points. Parameter n is the total number of knot points.
2.5.2 Basis Functions
Description:
-
1.
Return the total number of basis functions along used by the surface.
-
2.
Return the total number of basis functions along used by the surface.
-
3.
Set the tensor product coefficients of bi-linear basis functions. Parameter _theta is the pointer address to the basis coefficients, where and are the number of basis in and coordinate respectively. If a zero pointer is passed, the surface sets all coefficients equal to 0.
-
4.
Set the tensor product coefficient matrix of bi-linear basis functions. Parameter theta is the coefficient matrix.
-
5.
Return a constant reference of the bi-linear basis tensor product coefficients. Coefficient are stored in the surface object in row-wise major.
2.5.3 Evaluation
Description:
This function implements the public interface of the FunctionND base class. It returns the bi-linear surface value and computes gradient and Hessian if required. See also FunctionND::eval().
2.6 Chebyshev Surface
Class ChebyshevSurface is a concrete type to represent continuous (smooth) surface using the tensor product of two sets of Chebyshev basis polynomials along and . It is a directly derived class from the FunctionND base class. Class ChebyshevSurface is defined in header file “chebyshev_surface.h”.
2.6.1 Constructor
Description:
Constructor, create a Chebyshev surface over with working domain and highest degrees of the polynomial. Parameter a and b defines the domain along . Parameter c and d defines the domain along . Parameter degree_x and degree_y are the highest degrees of Chebyshev basis polynomial along and respectively.
2.6.2 Query Functions
Description:
-
1.
Return the lower bound of the working domain along .
-
2.
Return the upper bound of the working domain along .
-
3.
Return the lower bound of the working domain along .
-
4.
Return the upper bound of the working domain along .
-
5.
Return the highest degree of Chebyshev basis polynomial along .
-
6.
Return the highest degree of Chebyshev basis polynomial along .
2.6.3 Basis Functions
Description:
-
1.
Set the tensor product coefficients of Chebyshev basis polynomials. Parameter _theta is the pointer address to the basis coefficients, where and are the number of basis in and coordinate respectively. In other words, and are the highest degree of Chebyshev basis in and respectively. If a zero pointer is passed, the surface sets all coefficients equal to 0.
-
2.
Set the tensor product coefficients of Chebyshev basis polynomials. Parameter theta is the coefficient matrix.
-
3.
Return a constant reference of the tensor product basis coefficient matrix stored in the Chebyshev surface object.
2.6.4 Evaluation
Description:
This function implements the public interface of the FunctionND base class. It returns the Chebyshev surface value and computes gradient and Hessian if required. See also FunctionND::eval().
2.6.5 Integration
Description:
This function implements the public interface of the FunctionND base class. It computes the finite integral with lower and upper limits given in parameter X_LO and X_HI respectively. See also FunctionND::eval().
3 n-d Vector Valued Functions
3.1 VtrValueFunctionND Base Class
VtrValueFunctionND is the pure virtual base class for vector valued multi-dimensional functions. It is defined in header file “function_nd.h”.
3.1.1 Evaluation
Description:
Given a -dimensional unknown variable , this function evaluates where the result is a -element vector. Parameter x holds the unknown variable . Parameter _v is optional. If a non-zero pointer is supplied, it will hold the result of on return. Parameter _J is optional. If a non-zero pointer is supplied, it will hold the Jacobian matrix on return.
When users need supply an implementation of the VtrValueFunctionND interface, i.e. a vector-valued residual function for model fitting, they could choose to just compute the value vector and call the protected function jacobian_fwd_diff implemented in VtrValueFunctionND to approximate the Jacobian matrix by finite difference. An example of such implementation could be,
3.1.2 Query Function
Description:
-
1.
Return the number of value elements to be computed in result vector.
-
2.
Return the dimension size of unknown variables.
3.2 VtrValueFunctionND_M
Class VtrValueFunctionND_M is a concrete type derived from VtrValueFunctionND base class. It holds number of FunctionND object handles in a buffer and evaluates them simultaneously to produce a -element result vector. A FunctionND::Handle is typedefed from shared pointer of FunctionND.
4 1-d Interpolation
Class InterpCubicSplineCurve in interp_cubic_spline_curve.h provides a generalized cubic spline interpolation method that can match one, two or all three of at a list of data points. This allows users to more effectively control the level, slope and curvature of the interpolated curve.
InterpCubicSplineCurve is a derived class from Function1D. Once fitted to the given interpolation points, it can be used just like a regular 1-d function.
4.1 Definition of Data Points
Interpolation data points are represented by a nested struct, InterpCubicSplineCurve::Point, inside the InterpCubicSplineCurve class. The details of this Point are given below by the line numbers in the struct definition.
-
•
Line number 3-8, this is the type enumeration indicating whether the point holds a function value , slope or curvature .
-
•
Line number 10, member variable x holds the coordinate value of the data point.
-
•
Line number 11, member variable v holds the value of , or .
-
•
Line number 12, member variable type indicates the value type of member variable v.
-
•
Line number 14-15, contructors to initialize a data point object.
4.2 Interpolation Constructor
Description:
Create a cublic spline interpolation curve. This curve can be fit to a list of data points at a later time.
4.3 Clone
Description:
Implement the interface function Function1D::clone(). It returns a new instance of cubic interpolation curve identical to the current curve.
4.4 Evaluation
Description:
Implement the interface function Function1D::eval(). It returns the cubic spline function value and computes if non-zero parameters are supplied to _derv1 and _derv2.
4.5 Integration
Description:
Implement the interface function Function1D::integral(). It returns the finite integral of the cubic spline function from lower limit lo to upper limit hi.
4.6 Interpolation
Description:
Interpolate the cubic spline curve through a list of data points and match , or depending on the value type specified in the data point object. doesn’t need be sorted. The buffer can also hold data points with same but different value types. This function can be repeated called, in which case the curve object is fitted to the new list of input data points.
5 1-d Integration
Class Integrate1D in integrate_1d.h implements an adaptive Gaussian quadrature method to numerically approximate a finite integral .
5.1 Constructor
Description:
The first parameter f is a constant reference of the 1-d integrand function . The quadrature object internally saves as a data member.
The second parameter eps is the error tolerance that controls whether the adaptive quadrature needs further refine a sub-interval.
REQUIRED: The 1-d integrand function object needs be alive in the lifecycle of the quadrature.
5.2 Integrand Function
Description:
Return a constant reference to the integrand function. The reference is held as a data member of class Integrate1D.
5.3 Precision Control
Description:
-
1.
Return the error tolerance level used in adaptive quadrature method.
-
2.
Set the error tolerance used in adaptive quadrature method.
5.4 Integrate Operator
Description:
Return the quadrature approximation of finite integral . Parameters a and b are the lower and upper limite of the integral.
6 Iterative Method
Most numerical problems are solved iteratively with some convergence requirement. The IterativeMethod class defined in iterative.h is the common base class of iterative solvers implemented in the library.
6.1 Constructor and Destructor
Description:
This class is a pure virtual class. It has a protected default constructor and public pure virtual destructor.
6.2 Iteration Control
Description:
-
1.
Set the max number of iterations allowed to run.
-
2.
Return the max number of iterations allowed.
-
3.
Return the actual number of iterations being used by an solver.
-
4.
Enable or disable throwing an exception when the max number of iterations is reached.
6.3 Convergence Control
Description:
-
1.
Set the convergence tolerance. It is upto the actual algorithm to perform convergency test.
-
2.
Return the convergence tolerance used by a solver.
-
3.
Return if a vector’s max norm is smaller than the convergence tolerance.
-
4.
Return if two vector’s difference is smaller than the convergence tolerance. REQUIRED: v and t are vectors of same size.
7 Numerical Bounds
NPL represents the numerical boundary of variable by class Bound in header file bound.h. Across the library, two doubles and are considered as numerically equal if for some tolerance , default to . Note that this default tolerance is not the machine precision. The Bound class uses this default tolerance to test if a value is equal to the boundary value.
7.1 Object Construction
Description:
-
1.
Default constructor, initialized the object as unbounded.
-
2.
Initialize the object with a given lower and upper bound. REQUIRED: upper bound is strictly greater than or numerically equal to lower bound.
-
3.
Create a lower bound object.
-
4.
Create an upper bound object.
7.2 Comparison Operator
Description:
-
1.
Return if two bound objects have numerically equal lower and upper bounds.
-
2.
Return if two bound objects do NOT have numerically equal lower and upper bounds.
7.3 Arithmetic Operator
Description:
-
1.
Shift (addition) both lower and upper bounds of the current object by amount v.
-
2.
Shift (subtraction) both lower and upper bounds of the current object by amount v.
-
3.
Scale both lower and upper bounds of the current object by factor v.
-
4.
Return a new object that shifts (addition) both lower and upper bounds of the current object by amount v.
-
5.
Return a new object that shifts (subtraction) both lower and upper bounds of the current object by amount v.
-
6.
Return a new object that scales both lower and upper bounds of the current object by amount v.
7.4 Elastic Bounds
Description:
This set of functions is only used for nonlinear programming at the moment.
-
1.
Allow both the lower and upper bound to be elastic.
-
2.
Explicitly set the lower bound to be elastic.
-
3.
Explicitly set the upper bound to be elastic.
-
4.
Return the current object has elastic lower bound.
-
5.
Return the current object has elastic upper bound.
7.5 Query Functions
Description:
-
1.
Return the lower bound value.
-
2.
Return the upper bound value.
-
3.
Return if the object has a lower bound.
-
4.
Return if the object has a upper bound.
-
5.
Return if the object has both lower and upper bounds.
-
6.
Return if the object has either lower or upper bound.
-
7.
Return if the lower bound is same as upper bound, effective an equality bound.
-
8.
Return 0 if a value is in the range between lower and upper bounds; or a positive distance above upper bound; or a negative distance below lower bound.
-
9.
Return one of the level enumerations to indicate the status of a value relative to the bounds.
Level Enumerations:
8 1-d Root Finding
Class RootSolver1D in root_1d.h derives from IterativeMethod base class. It solves 1-dimensional root finding problem using a safeguarded algorithm that combines bitsection, rational interpolation and Newton method. Please see our white paper for details of the algorithm.
8.1 Constructor
Description:
The first parameter f is a constant reference of the 1-d objective function . The root-finding solver internally saves as a data member.
REQUIRED: The 1-d function object needs be alive in the lifecycle of the root-finding solver.
The second parameter domain is optional. By default, has unbounded working domain . When a bounded domain is provided, the solver will throw an exception when a bracketing operation exceeds the domain.
8.2 Query Functions
Description:
-
1.
Return the constant reference to the underlying objective function . This reference is saved as a class data member.
-
2.
Return the working domain of .
8.3 Enable or Disable Derivatives
Description:
Enable or disable the solver to use the derivatives . Newton method is used to compute the search sequence if is enabled. Otherwise, rational interpolation is used.
8.4 Solver Operator
Description:
This function computes the root such that , where is set by the set_converge_tolerance() function from base class IterativeMethod.
Parameter a and b is a guess of the bracketing interval . If it actually doesn’t bracket, the solver will enter bracketing mode to locate a bracketing interval.
Parameter x holds the initial guess on call. REQUIRED: . On return, parameter x holds the solution . Meanwhile, is returned.
9 1-d Minimization
Class MiniSolver1D in mini_1d.h derives from IterativeMethod base class. It solves 1-dimensional minimization problem
using a safeguarded algorithm that combines polynomial interpolation with Golden section method. Please see our white paper for details of the algorithm.
9.1 Constructor
Description:
The first parameter f is a constant reference of the 1-d objective function . The minimization solver internally saves as a data member.
REQUIRED: The 1-d function object needs be alive in the lifecycle of the minimization solver.
The second parameter domain is optional. By default, has unbounded working domain . When a bounded domain is provided, the solver will restrict the search strictly within the specified domain.
9.2 Query Functions
Description:
-
1.
Return the constant reference to the underlying objective function . This reference is saved as a class data member.
-
2.
Return the working domain of .
9.3 Enable or Disable Derivatives
Description:
Enable or disable the solver to use the derivatives . The solver internally fits a quadratic model function to approximate . If is enabled, will match , and at two points and . When only function values is used, is fit to match function values at three points.
9.4 Step Length Control
Description:
-
1.
Set the max step length that is allowed to change at each iteration.
-
2.
Return the max step that is allowed to change.
9.5 Solver Operator
Description:
This function computes a local minimum for function . Parameter a and b is a guess of the bracketing interval . Parameter x is the initial guess on call. On termination, parameter x holds the solution and is returned. REQUIRED: .
The solver will first test if the initial interval is indeed a bracketing interval. If not, it will enter bracketing mode to locate a bracketing interval. Once the interval is found, the algorithm will enter safeguarded mode to compute . It terminates when the max number of iterations is reached, or when . Both and can be set by calling relevant member functions of the base class IterativeMethod.