1
{ **********************************************************************
4
* (c) J. Debord, August 2000 *
5
**********************************************************************
6
This unit fits the "exponential + linear" model:
8
y = A.[1 - exp(-k.x)] + B.x
10
********************************************************************** }
19
FMath, Matrices, Stat, Regress;
21
function FuncName : String;
23
function FirstParam : Integer;
25
function LastParam : Integer;
27
function ParamName(I : Integer) : String;
29
function RegFunc(X : Float; B : PVector) : Float;
31
procedure DerivProc(X : Float; B, D : PVector);
33
function FitModel(X, Y : PVector; N : Integer; B : PVector) : Integer;
38
function FuncName : String;
39
{ --------------------------------------------------------------------
40
Returns the name of the regression function
41
-------------------------------------------------------------------- }
43
FuncName := 'y = A[1 - exp(-k.x)] + B.x';
46
function FirstParam : Integer;
47
{ --------------------------------------------------------------------
48
Returns the index of the first parameter to be fitted
49
-------------------------------------------------------------------- }
54
function LastParam : Integer;
55
{ --------------------------------------------------------------------
56
Returns the index of the last parameter to be fitted
57
-------------------------------------------------------------------- }
62
function ParamName(I : Integer) : String;
63
{ --------------------------------------------------------------------
64
Returns the name of the I-th parameter
65
-------------------------------------------------------------------- }
74
function RegFunc(X : Float; B : PVector) : Float;
75
{ --------------------------------------------------------------------
76
Computes the regression function at point X
77
B is the vector of parameters, such that :
79
B^[0] = A B^[1] = k B^[2] = B
80
-------------------------------------------------------------------- }
82
RegFunc := B^[0] * (1.0 - Expo(- B^[1] * X)) + B^[2] * X;
85
procedure DerivProc(X : Float; B, D : PVector);
86
{ --------------------------------------------------------------------
87
Computes the derivatives of the regression function at point X
88
with respect to the parameters B. The results are returned in D.
89
D^[I] contains the derivative with respect to the I-th parameter.
90
-------------------------------------------------------------------- }
94
E := Expo(- B^[1] * X); { exp(-k.x) }
95
D^[0] := 1.0 - E; { dy/dA = 1 - exp(-k.x) }
96
D^[1] := B^[0] * X * E; { dy/dk = A.x.exp(-k.x) }
97
D^[2] := X; { dy/dB = x }
100
function FitModel(X, Y : PVector; N : Integer; B : PVector) : Integer;
101
{ --------------------------------------------------------------------
102
Computes initial estimates of the regression parameters
103
--------------------------------------------------------------------
104
Input : N = number of points
105
X, Y = point coordinates
106
Output : B = estimated regression parameters
107
-------------------------------------------------------------------- }
112
{ B is the slope of the last (linear) part of the curve }
114
if K = N then K := Pred(N);
115
B^[2] := (Y^[N] - Y^[K]) / (X^[N] - X^[K]);
117
{ A is the intercept of the linear part }
118
B^[0] := Y^[N] - B^[2] * X^[N];
120
{ Slope of the tangent at origin = B + k.A }
122
if K = 1 then K := 2;
123
D := (Y^[K] - Y^[1]) / (X^[K] - X^[1]);
124
B^[1] := (D - B^[1]) / B^[0];