lsfitfit is going crazy (nonlinear fit not near any points)
Page 1 of 1

Author:  dediggefedde [ Fri Jan 30, 2015 5:34 pm ]
Post subject:  lsfitfit is going crazy (nonlinear fit not near any points)

Hello again!

I tried working with lsfitfit again, to fit a nonlinear function:
y=c0 (x0+c1)^2/(1+c2* x1).

I would like to get c0, c1 and c2 by providing datapoints ({x0,x1},y).
However, I don't have a high amount of datapoints (~3-5) and only the order of magnitude for c-starting parameter.

As a side-note, is this function solving the equation system when only called with 3 parameters? As far as I have experienced, it doesn't seem to and usually gets unaccurate at the 4th or 5th digit.

A set of Parameters that I call the function with:
y="[130.9045354801, 135.9066659041, 131.9036065061, 123.9053434201]";

For this, the solution should be around c="[0.069118, 1184,4528.38, 0.810883]";

The settings I call it with:

The function and gradient:
void function_cx_1_func(const real_1d_array &c, const real_1d_array & x, double &func, void *ptr) {
   func = c[0] * square(x[0] + c[1]) / square(1.0 + c[2] * x[1]);
void function_cx_1_grad(const real_1d_array &c, const real_1d_array & x, double &func, real_1d_array &grad, void *ptr) {
   grad[0] = square(x[0] + c[1]) / square(1 + c[2] * x[1]);
   grad[1] = 2 * c[0] * (x[0] + c[1]) / square(1 + c[2] * x[1]);
   grad[2] = -2 * c[0] * c[1] * square(x[0] + c[1]) / (square(1 + c[2] * x[1])*(1 + c[2] * x[1]));

and the call to lsfitfit:
lsfitcreatefg(x, y, c, diffstep, state);
lsfitsetcond(state, epsf, epsx, maxits);
lsfitsetbc(state, bndl, bndu);
lsfitsetscale(state, cScale);
alglib::lsfitfit(state, function_cx_1_func, function_cx_1_grad);
lsfitresults(state, info, c, rep);

However, last time I tried this, the y-values of the fittet function at the x-coordinates were around 0.1 instead of 130... So I guess I messed up some accuracy-parameters...
However after searching for days I still can't seem to find any clue how to use this right...

Can someone please tell me if I misunderstood the using of e.g. epsx/epsf/cScale/diffstep to get a accurate fit?

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group