TMtxMultiNonLinReg Class

Source: StatTools.cs · Assembly: Dew.Stats
ComponentTMtxComponentTMtxMultiNonLinReg

public class TMtxMultiNonLinReg : TMtxComponent

Performs multiple-nonlinear regression.

How to use TMtxMultiNonLinReg component?
1. Drop a Dew.Stats.TMtxMultiNonLinReg component on the form. 2. Define Dew.Stats.TMtxMultiNonLinReg.X the vector of independent variables. 3. Define Dew.Stats.TMtxMultiNonLinReg.Y the vector of dependent variables. Make sure that X and Y have the same length. 4. Define initial estimates for Dew.Stats.TMtxMultiNonLinReg.B regression parameters. 5. (Optionaly) define Dew.Stats.TMtxMultiNonLinReg.Weights. If you'll use weights, set Dew.Stats.TMtxMultiNonLinReg.UseWeights property to true. 6. Define regression function. 7. (Optionally) define the derivative procedure. If you don't define derivative procedure then the numeric approximation will be used to calculate the derivative at specific point. 8. Define the optimization method. Depending on your function different methods will give better/worse results. 9. (Optionally) define desired tolerance for result. 10. Define the maximum number of steps for optimization method. Internal optimization method will stop when number of iterations exceeds MaxIter or internal minimum precision is within Tolerance. 11. Verbose property, if assigned, stores Fun, evaluated at each iteration step. Optionally, you can also assign Dew.Math.TOptControl object to the Verbose property. This allows the optimization procedure to be interrupted from another thread and optionally also allows logging and iteration count monitoring.

Results:
1. Dew.Stats.TMtxMultiNonLinReg.B : Regression coefficients estimates. 2. Dew.Stats.TMtxMultiNonLinReg.YCalc : Fitted Y values.

The component internally performs vectorized optimization process. It can also be used to speed-up nonlinear regression with only one independent variable by 10-20x.

Examples

csharp
using Dew.Math;
    using Dew.Stats;
    using Dew.Stats.Units;
    using System;
    namespace Dew.Examples
    {
        private void Rat43(TVec b, TVecList x, TVec y)
        {
//        return b[0] / Math.Pow((1.0 + Math.Exp(b[1]-b[2]*x)),1/b[3]);

    y.Mul(x[0], -B[2]);
    y.Add(B[1]);
    y.Exp();
    y.Add(1);
    y.Power(1/B[3]);
    y.DivideBy(B[0]);
    }

    private void Example(TMtxMultiNonLinReg nlr)
    {
        // Load data - independent variable
        nlr.X.Add():
        nlr.X[0].SetIt(false,new double[] {9.000, 14.000, 21.000, 28.000,
            42.000, 57.000, 63.000, 70.000,
            79.000});
        // Load data - dependent variable
        nlr.Y.SetIt(false,new double[] {8.930, 10.800, 18.590, 22.330,
            39.350, 56.110, 61.730, 64.620,
            67.080});
        // Initial estimates for regression coefficients
        nlr.B.SetIt(false,new double[] {100,10,1,1});
        // setup optimization parameters
        nlr.Tolerance = 1.0e-6; // 6 digits should do the trick
        nlr.GradTolerance = 1.0e-3; // 3 digits
        nlr.MaxIterations = 400;
        nlr.RegressFunction = +Rat43; // regression function
        // Marquardt method
        nlr.OptMethod = TOptMethod.optMarquardt;
        nlr.Recalc();
        // MtxNinLinReg->b now stores calculated regression parameter estimates
    }
    }

Properties

NameTypeDescription
AutoUpdateBooleanIf true then changing any of the TMtxMultiNonLinReg properties will trigger the Dew.Stats.TMtxMultiNonLinReg.Recalc method.
BTVecStores the regression coefficients.
BlockAssignBooleanBlock streaming of specific properties when storing only a "template".
DeriveProcedureTMultiDeriveProcDefines derivatives of regression function.
DirtyBooleanWhen any of the TMtxNonLinReg properties changes, this property is automatically set to true.
EditorActiveBooleanReturns True, if the component editor is displayed.
GradToleranceDoubleDefines minimal allowed gradient C-Norm.
MaxIterationInt32Defines one of the conditions for terminating the regression coefficient calculation.
OptMethodTOptMethodOptimization method used.
ReferenceTReferenceListStores a list of components that have to be notified, when this component is destroyed.
RegressFunctionTMultiRegressFunDefines the regression function of several regression parameters.
SoftSearchBooleanDefines line search algorithm for Quasi-Newton and Conjugate methods.
StopReasonTOptStopReasonReturns the reason why regression parameters calculation stopped.
ToleranceDoubleDefines one of the conditions for terminating the regression coefficient calculation.
UseWeightsBooleanWeighted non-linear regression.
VerboseTStringsIf not nil then the optimization method uses it for logging each optimization step.
WeightsTVecWeights.
XTVecListVector of independant variables.
YTVecVector of dependant variables.
YCalcTVecVector of calculated values.

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.
EditorClassTo be overriden in descendanr classses.
LoadFromStreamLoad the component from Src stream.
LoadTemplateFromFileLoad a template from file.
LoadTemplateFromStreamLoad a template from stream.
RecalcTriggers non-linear regression recalculation.
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.