using Dew.Math;
using Dew.Stats;
using Dew.Stats.Units;
using System;
namespace Dew.Examples
{
private double Rat43(
TVec b,
double x)
{
return b[0] / Math.Pow((1.0 + Math.Exp(b[1]-b[2]*x)),1/b[3]);
}
private void Example(TMtxNonLinReg nlr)
{
// Load data - independent variable
nlr.X.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.MaxIteration = 400;
nlr.RegressFunction += Rat43;
// regression function
// Marquardt method
nlr.OptMethod = TOptMethod.optMarquardt;
nlr.Recalc();
// MtxNinLinReg->b now stores calculated regression parameter estimates
}
}