1
{ **********************************************************************
4
* (c) J. Debord, August 2000 *
5
**********************************************************************
6
This unit fits the increasing exponential :
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(Method : Integer; X, Y, W : PVector;
34
N : Integer; B : PVector) : Integer;
39
function FuncName : String;
40
{ --------------------------------------------------------------------
41
Returns the name of the regression function
42
-------------------------------------------------------------------- }
44
FuncName := 'y = A[1 - exp(-k.x)]';
47
function FirstParam : Integer;
48
{ --------------------------------------------------------------------
49
Returns the index of the first parameter to be fitted
50
-------------------------------------------------------------------- }
55
function LastParam : Integer;
56
{ --------------------------------------------------------------------
57
Returns the index of the last parameter to be fitted
58
-------------------------------------------------------------------- }
63
function ParamName(I : Integer) : String;
64
{ --------------------------------------------------------------------
65
Returns the name of the I-th parameter
66
-------------------------------------------------------------------- }
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 :
80
-------------------------------------------------------------------- }
82
RegFunc := B^[0] * (1.0 - Expo(- B^[1] * 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) }
99
function FitModel(Method : Integer; X, Y, W : PVector;
100
N : Integer; B : PVector) : Integer;
101
{ --------------------------------------------------------------------
102
Approximate fit of the increasing exponential by linear regression:
104
--------------------------------------------------------------------
105
Input : Method = 0 for unweighted regression, 1 for weighted
106
X, Y = point coordinates
109
Output : B = estimated regression parameters
110
-------------------------------------------------------------------- }
112
Y1 : PVector; { Transformed ordinates }
113
W1 : PVector; { Weights }
114
A : PVector; { Linear regression parameters }
115
V : PMatrix; { Variance-covariance matrix }
116
K : Integer; { Loop variable }
117
ErrCode : Integer; { Error code }
125
B^[0] := 1.1 * Max(Y, 1, N);
129
Y1^[K] := Log(1.0 - Y^[K] / B^[0]);
130
W1^[K] := Sqr(Y^[K] - B^[0]);
131
if Method = 1 then W1^[K] := W1^[K] * W^[K];
134
ErrCode := WLinFit(X, Y1, W1, N, A, V);
136
if ErrCode = MAT_OK then