I was looking for some samples on how to use ulogifit for 4 parameters logistic curve fit,Enclosed is a demo project performing a logistic fit to synthesized data. In the "Input parameters" box the coefficients of the logistic function can be specified for creation of data. In the "Start parameters" you must provide estimates for these coefficients with which the fit should start, they should not be off too much, otherwise numerical overflows can occur depending on the choice of the fitting algorithm (I found that the "Simplex algorithm" seems to be more tolerant than the default "Marquardt algorithm"). Click "Create data" to create the data to be fitted, then "Calc fit" to execute the fit. The fitted curve is drawn over the input data, and the fitted parameters are listed.
Could someone share some tips or guide please?
varI agree with Paolo that there is a problem with the indices. The 3rd and 4th parameters of the LogiFit procedure are the start and end index of the data array provided as first and second parameter. Since DimVector() internally simply calls Setlength() which creates a 0-based array the 3rd LogiFit parameter must be 0 rather than 1; the 4th parameter (last array index) is correct. And the matrix MatV is an m x m matrix where m is the count of fit parameters (5, here); so, the DimMatrix() call must be DimMatrix(MatV, 5, 5); each index i,j in MatV[i,j] then runs from 0 to 4
X:array [0..9] of Float=(0,1,2,3,4,5,6,7,8,9,10);
Y:array [0..9] of Float=(10,11,25,36,82,90,106,201,301,403);
...
DimVector(TX,10);
DimVector(TY,10);
...
DimMatrix(MatV, 0, 4);
LogiFit(TX, TY, 1, 9,true,true, 1000, 0.001, B, MatV);
y := k / (1+(x/c)^b)
Since Wolfram Alpha only calculates a derivative with respect to a variable named x I do a replacement: When I want the partial derivative with respect to b I replace your b by x and your x by a new variable A:derivative of k / (1 + (A/c)^x)
The result isdy/dx = -k * ((A/C)^x * ln(A/C)) / ( (A/C)^x + 1)^2
or, with the original variablesdy/db = -k * (x/C)^b * ln(x/C)) / ( (x/C)^b + 1)^2
Part of it is looking like your pdb = D[3], but yours is lacking the denominator...derivative of k / (1 + (A/x)^b)
and get the resultdy/dx = b * k * (A/x)^b / ( x * ((A/x)^b - 1)^2 )
or, with our variablesdy/dC = b * k * (x/C)^b / (C * ((x/C)^b - 1)^2)
Again, this is different from your equation for pdc = D{2]. HiBy the way, I have committed BGI demo projects which compile and work under Windows 64. See Trunk.
Have a look at the regexlin.pas demo in the demo/bgi/regmodel directory of LMath.
Regards
I agree with Paolo that there is a problem with the indices. The 3rd and 4th parameters of the LogiFit procedure are the start and end index of the data array provided as first and second parameter. Since DimVector() internally simply calls Setlength() which creates a 0-based array the 3rd LogiFit parameter must be 0 rather than 1; the 4th parameter (last array index) is correct. And the matrix MatV is an m x m matrix where m is the count of fit parameters (5, here); so, the DimMatrix() call must be DimMatrix(MatV, 5, 5); each index i,j in MatV[i,j] then runs from 0 to 4DimVector() and DimMatrix(), unlike SetLength(), take highest index of an array as a parameter. That is, DimVector(M) calls SetLength(M+1). Same is true for DimMatrix. So, if you call DimMatrix(5,5), you can use indices from 1 to 5.
So, if you call DimMatrix(5,5), you can use indices from 1 to 5.Sorry to be insistent: While I know that this is caused by the math literature where all vectors and matrices begin with index 1 I think it is a bad concept to abuse standard dynamic arrays for 1-based arrays. As a consequence, the user is on his own, there is no help from the compiler or from run-time errors. As an example, the user of LMath must never mix LMath routines with the routines of the standard Math unit unless he is very aware what he is doing.
As an example, the user of LMath must never mix LMath routines with the routines of the standard Math unit unless he is very aware what he is doing.
> TVector as a separate typeYes, similar. But "my" TVector is a record (no class like TPoints) and, therefore, there is no explicit need for destruction.
Something in direction of TPoints in lmPointsVec from lmComponents? :)
I thought about it. In fact, I have, for my own needs, similar class called TReals, but problem here is that call to GetValue/SetValue each time one wants to assign/read value of an array is very inefficient. If you noticed, variable Points in TPoints is public to get direct access to array elements. Inlining function would make it somewhat faster, but still, there is additional comparison and additional assignment.> TVector as a separate typeYes, similar. But "my" TVector is a record (no class like TPoints) and, therefore, there is no explicit need for destruction.
Something in direction of TPoints in lmPointsVec from lmComponents? :)