IGLib  1.7.2
The IGLib base library for development of numerical, technical and business applications.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
IG.Num.ScalarFunctionQuadratic Class Reference

Quadratic scalar function of vector variable. Function is evaluated according to q(x) = (1/2)*x^T*G*x + b^T*x + c where x is vector of parameters, G is constant Hessian matrix, b is vector of linear coefficients (gradient at x=0) and c is the scalar term (function value at x=0). More...

+ Inheritance diagram for IG.Num.ScalarFunctionQuadratic:
+ Collaboration diagram for IG.Num.ScalarFunctionQuadratic:

Public Member Functions

 ScalarFunctionQuadratic (IMatrix hessian, IVector gradient0, double scalarTerm)
 Creation of a quadratic scalar function. WARNING: Matrix argument is interpreted as Hessian, i.e. twice the matrix of quadratic coefficients. More...
 
override double Value (IVector parameters)
 Returns the value of this function at the specified parameter. More...
 
override void GradientPlain (IVector parameters, IVector gradient)
 Calculates first order derivatives (gradient) of this function at the specified parameters. WARNING: Plain function, does not check consistency of arguments. More...
 
override void HessianPlain (IVector parameters, IMatrix hessian)
 Calculates the second derivative (Hessian matrix) of this function at the specified parameters. WARNING: Plain function, does not check consistency of arguments. More...
 
- Public Member Functions inherited from IG.Num.ScalarFunctionUntransformedBase
virtual void Evaluate (IScalarFunctionResults data)
 Evaluates whatever needs to be evaluated and stores the results on the specified storage object. More...
 
virtual void Gradient (IVector parameters, ref IVector gradient)
 Calculates first order derivatives (gradient) of this function at the specified parameters. More...
 
virtual void Hessian (IVector parameters, ref IMatrix hessian)
 Calculates the second derivative (Hessian matrix) of this function at the specified parameters. More...
 
virtual void NumericalGradientForwardPlain (IVector x, IVector stepSizes, IVector gradient)
 Calculates numerical derivatives (gradient) of this function. Forward difference formula is normally used. More...
 
void NumericalGradientForward (IVector x, IVector stepSizes, ref IVector gradient)
 Calculates numerical derivatives (gradient) of this function. Forward difference formula is normally used. More...
 
void NumericalGradientForward (IVector x, double stepSize, ref IVector gradient)
 Calculates numerical derivatives (gradient) of this function. Forward difference formula is used. More...
 
virtual void NumericalGradientCentralPlain (IVector x, IVector stepSizes, IVector gradient)
 Calculates numerical derivatives (gradient) of this function. Forward difference formula is normally used. More...
 
void NumericalGradientCentral (IVector x, IVector stepSizes, ref IVector gradient)
 Calculates numerical derivatives (gradient) of this function. Forward difference formula is normally used. More...
 
void NumericalGradientCentral (IVector x, double stepSize, ref IVector gradient)
 Calculates numerical derivatives (gradient) of this function. Forward difference formula is normally used. More...
 
virtual void NumericalHessianForwardPlain (IVector x, IVector stepSizes, IVector aux, IMatrix hessian)
 Calculates numerical second derivatives (Hessian) of this function. Forward difference formula is normally used. WARNING: Dimensions of vector arguments must match. This function does not check for consistency of argument dimensions. REMARK: Vector x is changed during operation, but is set to initial value before function returns (unless an exception is thrown). More...
 
virtual void NumericalHessianForward (IVector x, IVector stepSizes, ref IVector aux, ref IMatrix hessian)
 Calculates numerical second derivatives (Hessian) of this function. Forward difference formula is normally used. REMARK: if auxiliary vector or result matrix don't have correct dimensions or they are not allocated, then allocation is performed first. REMARK: Vector x is changed during operation, but is set to initial value before function returns (unless an exception is thrown). More...
 
virtual void NumericalHessianForward (IVector x, double stepSize, ref IVector aux, ref IMatrix hessian)
 Calculates numerical second derivatives (Hessian) of this function. Forward difference formula is normally used. REMARK: if auxiliary vector or result matrix don't have correct dimensions or they are not allocated, then allocation is performed first. REMARK: Vector x is changed during operation, but is set to initial value before function returns (unless an exception is thrown). More...
 
virtual void NumericalHessianCentralPlain (IVector x, IVector stepSizes, IVector aux1, IVector aux2, IMatrix hessian)
 Calculates numerical second derivatives (Hessian) of this function. Forward difference formula is normally used. WARNING: Dimensions of vector arguments must match. This function does not check for consistency of argument dimensions. REMARK: Vector x is changed during operation, but is set to initial value before function returns (unless an exception is thrown). More...
 
virtual void NumericalHessianCentral (IVector x, IVector stepSizes, ref IVector aux1, ref IVector aux2, ref IMatrix hessian)
 Calculates numerical second derivatives (Hessian) of this function. Forward difference formula is normally used. REMARK: if auxiliary vector or result matrix don't have correct dimensions or they are not allocated, then allocation is performed first. REMARK: Vector x is changed during operation, but is set to initial value before function returns (unless an exception is thrown). More...
 
virtual void NumericalHessianCentral (IVector x, double stepSize, ref IVector aux1, ref IVector aux2, ref IMatrix hessian)
 Calculates numerical second derivatives (Hessian) of this function. Forward difference formula is normally used. REMARK: if auxiliary vector or result matrix don't have correct dimensions or they are not allocated, then allocation is performed first. REMARK: Vector x is changed during operation, but is set to initial value before function returns (unless an exception is thrown). More...
 
virtual void NumericalHessianCentralPlain (IVector x, IVector stepSizes, IVector aux1, IVector aux2, IMatrix hessian, bool useAnalyticalGradient)
 Calculates numerical second derivatives (Hessian) of this function by the central difference formula. WARNING: Dimensions of vector arguments must match. This function does not check for consistency of argument dimensions. REMARK: Vector x is changed during operation, but is set to initial value before function returns (unless an exception is thrown). More...
 
virtual void NumericalHessianCentral (IVector x, IVector stepSizes, ref IVector aux1, ref IVector aux2, ref IMatrix hessian, bool useAnalyticalGradient)
 Calculates numerical second derivatives (Hessian) of this function by the central difference formula. REMARK: if auxiliary vector or result matrix don't have correct dimensions or they are not allocated, then allocation is performed first. REMARK: Vector x is changed during operation, but is set to initial value before function returns (unless an exception is thrown). More...
 
virtual void NumericalHessianCentral (IVector x, double stepSize, ref IVector aux1, ref IVector aux2, ref IMatrix hessian, bool useAnalyticalGradient)
 Calculates numerical second derivatives (Hessian) of this function. Forward difference formula is normally used. REMARK: if auxiliary vector or result matrix don't have correct dimensions or they are not allocated, then allocation is performed first. REMARK: Vector x is changed during operation, but is set to initial value before function returns (unless an exception is thrown). More...
 
void TestSpeed (IVector parameters, int numEvaluations, bool randomPerturbations, double relativePerturbationSize, bool calcValue, bool calcGradient, bool calcHessian, bool writeLastResult)
 Tests speed of evaluation of the current scalar function and writes results to the console. More...
 
void TestGradient (IVector parameters, IVector stepSizes, int stepReductionFactor, int numStepReductions, bool checkNumerical, bool writeErrorComponents, bool writeGradientComponents)
 Tests the calculation of gradients of the current scalar function. More...
 
void TestGradient (IVector parameters, IVector stepSizes, int stepReductionFactor, int numStepReductions, bool checkNumerical, bool writeErrorComponents, bool writeGradientComponents, bool useCentralDifference)
 Tests the calculation of gradients of the current scalar function. More...
 
void TestHessian (IVector parameters, IVector stepSizes, int stepReductionFactor, int numStepReductions, bool checkNumerical, bool writeErrorComponents, bool writeHessianComponents)
 Tests the calculation of Hessians of the current scalar function. More...
 
void TestHessian (IVector parameters, IVector stepSizes, int stepReductionFactor, int numStepReductions, bool checkNumerical, bool writeErrorComponents, bool writeHessianComponents, bool useCentralDifference)
 Tests the calculation of Hessians of the current scalar function. More...
 
void Test (IVector from, IVector to, int numProbes, IVector stepSizes, double tolerance, bool testDerivatives, bool testSecondDerivatives, bool printDifferences, bool printResults)
 Performs numerical tests on the function, with output written to the console. Derivatives and second derivatives are tested and compared to numerical derivatives. More...
 
void Test (IVector from, IVector to, int numProbes, IVector stepSizes, double tolerance)
 Performs numerical tests on the function, with output written to the console. Derivatives and second derivatives are tested and compared to numerical derivatives. This method tests first and second order derivatives, prints differences between analytical and numerical values to the console, and prints reports where absolute differences exceed rolerance. More...
 
void Test (IVector from, IVector to, int numProbes, double stepSize, double tolerance, bool testDerivatives, bool testSecondDerivatives, bool printDifferences, bool printResults)
 Performs numerical tests on the function, with output written to the console. Derivatives and second derivatives are tested and compared to numerical derivatives. More...
 
void Test (IVector from, IVector to, int numProbes, double stepSize, double tolerance)
 Performs numerical tests on the function, with output written to the console. Derivatives and second derivatives are tested and compared to numerical derivatives. More...
 

Static Public Member Functions

static ScalarFunctionQuadratic ExampleFunction2d ()
 Creates and returns quadratic scalar function in 2D. More...
 
static ScalarFunctionQuadratic ExampleFunctionDiagonal2d ()
 Creates and returns quadratic scalar function with diagonal Hessian. More...
 
static ScalarFunctionQuadratic ExampleFunctionPureQuadratic2d ()
 Creates and returns quadratic scalar function with only quadratic terms. More...
 
static ScalarFunctionQuadratic ExampleFunctionDiagonalPureQuadratic2d ()
 Creates and returns quadratic function with diagonal Hessian. More...
 
static int GetNumConstants (int dim)
 Returns the number of constants that specify the quadratic function of the specified dimension. More...
 

Properties

int NumActualConstants [get]
 Gets the number of constants that define the current function. If e.g. the matrix coefficient or the vector coefficient is not defined then the corresponding constants are not counted. More...
 
IMatrix HessianMatrix [get, protected set]
 Twice the matrix of quadratic coefficients (Hessian matrix). More...
 
IVector Gradient0 [get, protected set]
 Vector of linear coefficients (equal to gradient of the function at x=0). More...
 
double ScalarTerm [get, protected set]
 Scalar additive constant. More...
 
override bool ValueDefined [get, protected set]
 Tells whether value of the function is defined by implementation. Always true for this case. More...
 
override bool GradientDefined [get, protected set]
 Tells whether the first derivative is defined for this function (by implementation, not mathematically) More...
 
override bool HessianDefined [get, protected set]
 Tells whether the second derivative is defined for this function (by implementation, not mathematically) More...
 
- Properties inherited from IG.Num.ScalarFunctionUntransformedBase
virtual string Name [get, set]
 Returns a short name of thecurrent function. More...
 
virtual string Description [get, set]
 Returns a short description of the current function. More...
 
abstract bool ValueDefined [get, protected set]
 Tells whether value of the function is defined by implementation. More...
 
abstract bool GradientDefined [get, protected set]
 Tells whether the first derivative is defined for this function (by implementation, not mathematically) More...
 
abstract bool HessianDefined [get, protected set]
 Tells whether the second derivative is defined for this function (by implementation, not mathematically) More...
 
- Properties inherited from IG.Num.IScalarFunctionUntransformed
string Name [get]
 Returns a short name of the function. More...
 
string Description [get]
 Returns a short description of the function. More...
 
bool ValueDefined [get]
 Tells whether value of the function is defined by implementation. More...
 
bool GradientDefined [get]
 Tells whether the first derivative is defined for this function (by implementation, not mathematically) More...
 
bool HessianDefined [get]
 Tells whether the second derivative is defined for this function (by implementation, not mathematically) More...
 

Private Member Functions

 ScalarFunctionQuadratic ()
 

Private Attributes

IMatrix _G
 
IVector _b
 
double _c
 

Additional Inherited Members

- Protected Attributes inherited from IG.Num.ScalarFunctionUntransformedBase
string _name
 
string _description
 

Detailed Description

Quadratic scalar function of vector variable. Function is evaluated according to q(x) = (1/2)*x^T*G*x + b^T*x + c where x is vector of parameters, G is constant Hessian matrix, b is vector of linear coefficients (gradient at x=0) and c is the scalar term (function value at x=0).

When quadratic function is created or its parameters set, the Matrix parameter of the function is interpreted as Hessian, i.e. twice the matrix of quadratic coefficients.

$A Igor xx Dec10;

Constructor & Destructor Documentation

IG.Num.ScalarFunctionQuadratic.ScalarFunctionQuadratic ( )
inlineprivate
IG.Num.ScalarFunctionQuadratic.ScalarFunctionQuadratic ( IMatrix  hessian,
IVector  gradient0,
double  scalarTerm 
)
inline

Creation of a quadratic scalar function. WARNING: Matrix argument is interpreted as Hessian, i.e. twice the matrix of quadratic coefficients.

Parameters
hessianMatrix of second derivatives (Hessian). Can be null (in this case function degrades to linear function).
gradient0Vector of linear coefficients - gradient of quadratic function at x = 0. Can be null.
scalarTermConstant term.

Member Function Documentation

static ScalarFunctionQuadratic IG.Num.ScalarFunctionQuadratic.ExampleFunction2d ( )
inlinestatic

Creates and returns quadratic scalar function in 2D.

static ScalarFunctionQuadratic IG.Num.ScalarFunctionQuadratic.ExampleFunctionDiagonal2d ( )
inlinestatic

Creates and returns quadratic scalar function with diagonal Hessian.

Returns
static ScalarFunctionQuadratic IG.Num.ScalarFunctionQuadratic.ExampleFunctionPureQuadratic2d ( )
inlinestatic

Creates and returns quadratic scalar function with only quadratic terms.

Returns
static ScalarFunctionQuadratic IG.Num.ScalarFunctionQuadratic.ExampleFunctionDiagonalPureQuadratic2d ( )
inlinestatic

Creates and returns quadratic function with diagonal Hessian.

Returns
static int IG.Num.ScalarFunctionQuadratic.GetNumConstants ( int  dim)
inlinestatic

Returns the number of constants that specify the quadratic function of the specified dimension.

Parameters
dimDimension of the space in which quadratic function is defined.

Referenced by IG.Num.SampledDataSet.CreateExampleQuadratic().

override double IG.Num.ScalarFunctionQuadratic.Value ( IVector  parameters)
inline

Returns the value of this function at the specified parameter.

Implements IG.Num.IScalarFunctionUntransformed.

References IG.Num.MatrixBase.Multiply(), and IG.Num.VectorBase.ScalarProduct().

override void IG.Num.ScalarFunctionQuadratic.GradientPlain ( IVector  parameters,
IVector  gradient 
)
inline

Calculates first order derivatives (gradient) of this function at the specified parameters. WARNING: Plain function, does not check consistency of arguments.

Parameters
parametersVector of parameters where derivatives are evaluated.
gradientVector where first order derivatives (the gradient) are stored.

Implements IG.Num.IScalarFunctionUntransformed.

References IG.Num.VectorBase.Add(), IG.Num.MatrixBase.MultiplyPlain(), and IG.Num.IVector.SetZero().

override void IG.Num.ScalarFunctionQuadratic.HessianPlain ( IVector  parameters,
IMatrix  hessian 
)
inline

Calculates the second derivative (Hessian matrix) of this function at the specified parameters. WARNING: Plain function, does not check consistency of arguments.

Parameters
parametersVector of parameters where derivatives are evaluated.
hessianMatrix where second derivatives (Hessian matrix) are stored.

Implements IG.Num.IScalarFunctionUntransformed.

Member Data Documentation

IMatrix IG.Num.ScalarFunctionQuadratic._G
private
IVector IG.Num.ScalarFunctionQuadratic._b
private
double IG.Num.ScalarFunctionQuadratic._c
private

Property Documentation

int IG.Num.ScalarFunctionQuadratic.NumActualConstants
get

Gets the number of constants that define the current function. If e.g. the matrix coefficient or the vector coefficient is not defined then the corresponding constants are not counted.

IMatrix IG.Num.ScalarFunctionQuadratic.HessianMatrix
getprotected set

Twice the matrix of quadratic coefficients (Hessian matrix).

IVector IG.Num.ScalarFunctionQuadratic.Gradient0
getprotected set

Vector of linear coefficients (equal to gradient of the function at x=0).

double IG.Num.ScalarFunctionQuadratic.ScalarTerm
getprotected set

Scalar additive constant.

override bool IG.Num.ScalarFunctionQuadratic.ValueDefined
getprotected set

Tells whether value of the function is defined by implementation. Always true for this case.

override bool IG.Num.ScalarFunctionQuadratic.GradientDefined
getprotected set

Tells whether the first derivative is defined for this function (by implementation, not mathematically)

override bool IG.Num.ScalarFunctionQuadratic.HessianDefined
getprotected set

Tells whether the second derivative is defined for this function (by implementation, not mathematically)


The documentation for this class was generated from the following file: