TMtxOptimization Class

Header: Dew.Math/MtxVecTools.h · Cross-compiler
tObject→TMtxComponent→TMtxOptimization

class TMtxOptimization : public TMtxComponent;

Interfaces the optimization routines.

The component can be used to find the minimum of function of several variables.

How to use TMtxOptimization component?

Results:

Examples

cpp
#include "MtxVec.h"
#include "MtxVecTools.h"
#include "Optimization.h"
#include "Units.Math387.h"

using namespace Dew;
using namespace Dew::Math;
using namespace Dew::Math::Units::Math387;

// define the real function to be minimized
static double Banana(TVec* pars, TVec* consts, const DewArray<tObject*>& objConsts)
{
    return 100*Power((*pars)[1] - Power((*pars)[0], 2), 2) + Power(1 - (*pars)[0], 2);
}

void Example()
{
    TMtxOptimization* MtxOptim = new TMtxOptimization(nullptr);
    if (MtxOptim != nullptr)
    {
        // define two variables and their initial values
        MtxOptim->VariableParameters->SetIt(false, DewArray<double>{2, -1});
        // use BFGS optimization method
        MtxOptim->OptimizationMethod = TOptMethod::optBFGS;
        // tolerance for MinValue and gradient calculation
        // additional note : since we did not define the GradProc,
        // the internal numerical gradient approximation will be used
        MtxOptim->Tolerance = 2.0e-6;
        MtxOptim->GradTolerance = 2.0e-6;
        // function to be minimized
        MtxOptim->RealFunction = Banana;
        // finally, calculate minimum
        MtxOptim->Recalculate();
    }
    delete MtxOptim;
}

Constructors

NameDescription
TMtxOptimization (2)

Destructors

NameDescription
~TMtxOptimization

Properties

NameTypeDescription
AutoUpdateboolAutomatic recalculation.
BlockAssignboolBlock streaming of specific properties when storing only a "template".
ConstantParametersTVec*set/read the additional constants used in minimized function.
DirtyboolBecomes true after any of the properties have changed.
EditorActiveboolReturns True, if the component editor is displayed.
GradHessProcedureTGradHessDefines the gradient vector and Hessian matrix calculation routine.
GradProcedureTGradDefines the gradient vector calculation routine.
GradTolerancedoubleThe precision for numeric gradient and/or Hessian matrix calculation.
Lambda0doubleInitial lambda step used in Marquardt optimization algorithm.
MaxIterationsintmaximum number of iterations allowed for minimum search.
NameDewString
NumericGradMethodTNumericGradMethodDefines which gradient numerical approximation method will be used to to evaluate gradient.
OptimizationMethodTOptMethodOptimization algorithm used for minimum search.
RealFunctionTRealFunctionDefines the function to be minimized.
ReferenceTReferenceList*Stores a list of components that have to be notified, when this component is destroyed.
SoftSearchboolInternal line search algorithm.
StopReasonTOptStopReasonStop reason for optimization algorithm.
TolerancedoublePrecision.
VariableParametersTVec*Set/read the variables in minimized function.
VerbosetStrings*If not nil then the optimization method uses it for logging each optimization step.

Methods

NameDescription
AllowStreamingReturns the negatated value of BlockAssign.
AssignAssign values of all published properties from Source.
AssignTemplateAssign values of "template-like" published properties from Source.
EditorClass
LoadFromStreamLoad the component from Src stream.
LoadTemplateFromFileLoad a template from file.
LoadTemplateFromStreamLoad a template from stream.
RecalculateTriggers TMtxOptimization recalculation.
ReferenceRemoved
ResetReset is called after loading the data from stream or file.
SaveTemplateToFileSave template to file.
SaveTemplateToStreamSave template to stream.
SaveToStreamSave the component to Dst stream.
SetObjectsDefine any additional Object constant parameters in the RealFunction.

Fields

NameTypeDescription
InverseHessTMtx *Returns the inverse of Hessian matrix.
IterationsintReturns number of optimization algorithm iterations.
MinValuedoubleStores value of the objective function, evaluated at minimum.
Tagintptr_t