Overload List
Overload 1: Int32 NLinRegress(TVec X, TVec Y, TRegressFun RegFun, TDeriveProc DeriveProc, TVec B, TOptMethod Method, ref TOptStopReason StopReason, TVec Weights, TVec YCalc, Boolean SoftSearch, Int32 MaxIter, Double Tol, Double GradTol, TStrings Verbose)
General non-linear regression.
| # | Name | Description |
|---|---|---|
| 1 | X | Vector of the independent variable. |
| 2 | Y | Vector of dependent variable. |
| 3 | RegFun | Regression function. |
| 4 | DeriveProc | Procedure to calculate the derivatives of RegFun. You can define the exact derivative or use Dew.Stats.Units.Regress.NumericDerive routine as numerical approximation. |
| 5 | B | Holds initial estimate for regression parameters. After the call to NLinRegress b returns calculated regression parameters. |
| 6 | Method | Defines which optimization method will be used to find regression parameters (see MtxVec.hlp TOptMethod type to learn more about this). |
| 7 | StopReason | Returns why regression parameters search stopped (see MtxVec.hlp TOptStopReason type to learn more about different stop reasons). |
| 8 | Weights | Weights (optional). |
| 9 | YCalc | Returns calculated values (optional). |
| 10 | SoftSearch | If true, internal line search algoritm will use soft line search method. Set this parameter to true if you're using numerical approximation for derivative. If this parameter is set to false, internal line search algorithm will use exact line search method. Set this parameter to false if you're using *exact* derivative. |
| 11 | MaxIter | Maximum allowed numer of allowed iterations. |
| 12 | Tol | Desired regression parameters tolerance. |
| 13 | GradTol | Minimum allowed gradient C-Norm. |
| 14 | Verbose | If assigned, stores Fun, evaluated at each iteration step. Optionally, you can also pass Dew.Math.TOptControl object to the Verbose parameter. This allows the optimization procedure to be interrupted from another thread and optionally also allows logging and iteration count monitoring. |
Returns: Int32 - Number of iterations needed to calculate regression parameters with specified tolerance.
The routine fits equations to data by minimizing the sum of squared residuals :
SS = Sum [y(k) - ycalc(k)]^2 ,
where y(k) and ycalc(k) are respectively the observed and calculated value of the dependent variable for observation k. ycalc(k) is a function of the regression parameters b(0), b(1) ... Here the observed values obey the following (non-linear) equation:
y(k) = RegFun[x(k), b(0), b(1), ... ]
Y = RegFun[X,b(0),b(1), ...]
where RegFun is the regression function and b(0),..b(i) are the regression parameters.
using Dew.Math;
using Dew.Math.Tee;
using Dew.Stats.Units;
using Dew.Stats;
namespace Dew.Examples
{
// function definition
private double Eckerle4(TVec B, double x)
{
double sqrterm = (x-B[2])/B[1])*(x-B[2])/B[1]);
return B[0]/B[1] * Exp(-0.5*(sqrterm));
}
private void Example()
{
Vector x = new Vector(0);
Vector y = new Vector(0);
Vector b = new Vector(0);
Vector yhat = new Vector(0);
TOptStopReason StopReason;
x.SetIt(false,new double[] {400.0, 405.0, 410.0, 415.0,
420.0, 425.0, 430.0, 435.0,
436.5, 438.0, 439.5, 441.0,
442.5, 444.0, 445.5, 447.0,
448.5, 450.0, 451.5, 453.0,
454.5, 456.0, 457.5, 459.0,
460.5, 462.0, 463.5, 465.0,
470.0, 475.0, 480.0, 485.0,
490.0, 495.0, 500.0});
y.SetIt(false,new double[] {0.0001575, 0.0001699, 0.0002350, 0.0003102,
0.0004917, 0.0008710, 0.0017418, 0.0046400,
0.0065895, 0.0097302, 0.0149002, 0.0237310,
0.0401683, 0.0712559, 0.1264458, 0.2073413,
0.2902366, 0.3445623, 0.3698049, 0.3668534,
0.3106727, 0.2078154, 0.1164354, 0.0616764,
0.0337200, 0.0194023, 0.0117831, 0.0074357,
0.0022732, 0.0008800, 0.0004579, 0.0002345,
0.0001586, 0.0001143, 0.0000710});
b.SetIt(false,new double[] {1.0, 10.0, 500.0}); // initial estimates
Regress.NLinRegress(x,y,Eckerle4,null,b,optMarquardt, out StopReason,
null,yhat,false,300,1e-8,1e-10);
MtxVecTee.DrawValues(x,y,Series1,false); // draw data
MtxVecTee.DrawValues(x,yhat,Series2,false); // draw fitted value
}
}
Overload 2: Int32 NLinRegress(TVec X, TVec Y, TRegressFun RegFun, TDeriveProc DeriveProc, TVec B, TVec BLowerB, TVec BUpperB, TOptMethod Method, ref TOptStopReason StopReason, TVec Weights, TVec YCalc, Boolean SoftSearch, Int32 MaxIter, Double Tol, Double GradTol, TStrings Verbose)
Non-linear regression with lower and upper bounds.
| # | Name | Description |
|---|---|---|
| 1 | X | Vector of the independent variable. |
| 2 | Y | Vector of the dependent variable. |
| 3 | RegFun | Regression function. |
| 4 | DeriveProc | Procedure to calculate the derivatives of RegFun. You can define the exact derivative or use Dew.Stats.Units.Regress.NumericDerive routine as numerical approximation. |
| 5 | B | Holds initial estimate for regression parameters. After the call to NLinRegress b returns calculated regression parameters. |
| 6 | BLowerB | Holds lower bounds for regression parameters. If there are no lower bounds, set BLowerB values to -INF. |
| 7 | BUpperB | Holds upper bounds for regression parameters. If there are no upper bounds, set BUpperB values to +INF. |
| 8 | Method | Defines which optimization method will be used to find regression parameters (see MtxVec.hlp TOptMethod type to learn more about this). |
| 9 | StopReason | Returns why regression parameters search stopped (see MtxVec.hlp TOptStopReason type to learn more about different stop reasons). |
| 10 | Weights | Weights (optional). |
| 11 | YCalc | Returns calculated values (optional). |
| 12 | SoftSearch | If true, internal line search algoritm will use soft line search method. Set this parameter to true if you're using numerical approximation for derivative. If this parameter is set to false, internal line search algorithm will use exact line search method. Set this parameter to false if you're using *exact* derivative. |
| 13 | MaxIter | Maximum allowed numer of allowed iterations. |
| 14 | Tol | Desired regression parameters tolerance. |
| 15 | GradTol | Minimum allowed gradient C-Norm. |
| 16 | Verbose | If assigned, stores Fun, evaluated at each iteration step. Optionally, you can also pass Dew.Math.TOptControl object to the Verbose parameter. This allows the optimization procedure to be interrupted from another thread and optionally also allows logging and iteration count monitoring. |
Returns: Int32 - Number of iterations needed to calculate regression parameters with specified tolerance.
General non-linear regression with lower and upper bounds for regression coefficients.
Overload 3: Int32 NLinRegress(TVecList X, TVec Y, TMultiRegressFun RegFun, TMultiDeriveProc DeriveProc, TVec B, TOptMethod Method, ref TOptStopReason StopReason, TVec Weights, TVec YCalc, Boolean SoftSearch, Int32 MaxIter, Double Tol, Double GradTol, TStrings Verbose)
General vectorized non-linear regression.
| # | Name | Description |
|---|---|---|
| 1 | X | List of vectors of independent variable(s). |
| 2 | Y | Vector of the dependent variable. |
| 3 | RegFun | Regression function. |
| 4 | DeriveProc | Procedure to calculate the derivatives of RegFun. You can define the exact derivative or use Dew.Stats.Units.Regress.MultiNumericDerive routine as numerical approximation. |
| 5 | B | Holds initial estimate for regression parameters. After the call to NLinRegress b returns calculated regression parameters. |
| 6 | Method | Defines which optimization method will be used to find regression parameters (see MtxVec.hlp TOptMethod type to learn more about this). |
| 7 | StopReason | Returns why regression parameters search stopped (see MtxVec.hlp TOptStopReason type to learn more about different stop reasons). |
| 8 | Weights | Weights of X values (optional). |
| 9 | YCalc | Returns calculated values (optional). |
| 10 | SoftSearch | If true, internal line search algoritm will use soft line search method. Set this parameter to true if you're using numerical approximation for derivative. If this parameter is set to false, internal line search algorithm will use exact line search method. Set this parameter to false if you're using *exact* derivative. |
| 11 | MaxIter | Maximum allowed numer of allowed iterations. |
| 12 | Tol | Desired regression parameters tolerance. |
| 13 | GradTol | Minimum allowed gradient C-Norm. |
| 14 | Verbose | If assigned, stores Fun, evaluated at each iteration step. Optionally, you can also pass Dew.Math.TOptControl object to the Verbose parameter. This allows the optimization procedure to be interrupted from another thread and optionally also allows logging and iteration count monitoring. |
Returns: Int32 - Number of iterations needed to calculate regression parameters with specified tolerance.
The routine fits equations to data by minimizing the sum of squared residuals :
SS = Sum [y(k) - ycalc(k)]^2 ,
where y(k) and ycalc(k) are respectively the observed and calculated value of the dependent variable for observation k. ycalc(k) is a function of the regression parameters b(0), b(1) ... Here the observed values obey the following (non-linear) equation:
y(k) = RegFun[x(k), b(0), b(1), ... ]
Y = RegFun[X,b(0),b(1), ...]
where RegFun is the regression function and b(0),..b(i) are the regression parameters.
using Dew.Math;
using Dew.Math.Tee;
using Dew.Stats.Units;
using Dew.Stats;
namespace Dew.Examples
{
// function definition
private void Eckerle4(TVec B, TVecList x, TVec y)
{
// double a = (x-B[2])/B[1];
// result = B[0]/B[1] * Math.Exp(-0.5*a*a);
y.Normalize(x[0], B[2], B[1]);
y.Sqr();
y.Scale(-0.5);
y.Exp();
y.Scale(B[0]/B[1]);
}
private void Example()
{
TVecList x = new TVecList();
x.Add();
Vector y = new Vector(0);
Vector b = new Vector(0);
Vector yhat = new Vector(0);
TOptStopReason StopReason;
x[0].SetIt(false,new double[] {400.0, 405.0, 410.0, 415.0,
420.0, 425.0, 430.0, 435.0,
436.5, 438.0, 439.5, 441.0,
442.5, 444.0, 445.5, 447.0,
448.5, 450.0, 451.5, 453.0,
454.5, 456.0, 457.5, 459.0,
460.5, 462.0, 463.5, 465.0,
470.0, 475.0, 480.0, 485.0,
490.0, 495.0, 500.0});
y.SetIt(false,new double[] {0.0001575, 0.0001699, 0.0002350, 0.0003102,
0.0004917, 0.0008710, 0.0017418, 0.0046400,
0.0065895, 0.0097302, 0.0149002, 0.0237310,
0.0401683, 0.0712559, 0.1264458, 0.2073413,
0.2902366, 0.3445623, 0.3698049, 0.3668534,
0.3106727, 0.2078154, 0.1164354, 0.0616764,
0.0337200, 0.0194023, 0.0117831, 0.0074357,
0.0022732, 0.0008800, 0.0004579, 0.0002345,
0.0001586, 0.0001143, 0.0000710});
b.SetIt(false,new double[] {1.0, 10.0, 500.0}); // initial estimates
Regress.NLinRegress(x, y, Eckerle4, null, b, TOptMethod.optMarquardt, out StopReason, null, yhat, false, 300, 1e-8, 1e-10, null);
MtxVecTee.DrawValues(x[0],y,Series1,false); // draw data
MtxVecTee.DrawValues(x[0],yhat,Series2,false); // draw fitted value
}
}
Overload 4: Int32 NLinRegress(TVecList X, TVec Y, TMultiRegressFun RegFun, TMultiDeriveProc DeriveProc, TVec B, TVec BLowerB, TVec BUpperB, TOptMethod Method, ref TOptStopReason StopReason, TVec Weights, TVec YCalc, Boolean SoftSearch, Int32 MaxIter, Double Tol, Double GradTol, TStrings Verbose)
Non-linear regression with lower and upper bounds.
| # | Name | Description |
|---|---|---|
| 1 | X | List of vectors of independent variable(s). |
| 2 | Y | Vector of dependent variable. |
| 3 | RegFun | Regression function. |
| 4 | DeriveProc | Procedure to calculate the derivatives of RegFun. You can define the exact derivative or use Dew.Stats.Units.Regress.NumericDerive routine as numerical approximation. |
| 5 | B | Holds initial estimate for regression parameters. After the call to NLinRegress b returns calculated regression parameters. |
| 6 | BLowerB | Holds lower bounds for regression parameters. If there are no lower bounds, set BLowerB values to -INF. |
| 7 | BUpperB | Holds upper bounds for regression parameters. If there are no upper bounds, set BUpperB values to +INF. |
| 8 | Method | Defines which optimization method will be used to find regression parameters (see MtxVec.hlp TOptMethod type to learn more about this). |
| 9 | StopReason | Returns why regression parameters search stopped (see MtxVec.hlp TOptStopReason type to learn more about different stop reasons). |
| 10 | Weights | Weights (optional). |
| 11 | YCalc | Returns calculated values (optional). |
| 12 | SoftSearch | If true, internal line search algoritm will use soft line search method. Set this parameter to true if you're using numerical approximation for derivative. If this parameter is set to false, internal line search algorithm will use exact line search method. Set this parameter to false if you're using *exact* derivative. |
| 13 | MaxIter | Maximum allowed numer of allowed iterations. |
| 14 | Tol | Desired regression parameters tolerance. |
| 15 | GradTol | Minimum allowed gradient C-Norm. |
| 16 | Verbose | If assigned, stores Fun, evaluated at each iteration step. Optionally, you can also pass Dew.Math.TOptControl object to the Verbose parameter. This allows the optimization procedure to be interrupted from another thread and optionally also allows logging and iteration count monitoring. |
Returns: Int32 - Number of iterations needed to calculate regression parameters with specified tolerance.
General non-linear regression with lower and upper bounds for regression coefficients.