forum.alglib.net
http://forum.alglib.net/

Non-linear LSQ parameter error
http://forum.alglib.net/viewtopic.php?f=2&t=293
Page 1 of 1

Author:  toldi00 [ Fri Feb 04, 2011 9:00 am ]
Post subject:  Non-linear LSQ parameter error

Does anyone know if it is possible to have parameter errors in non-linear least squares? I'm using lsfitcreatefg and lsfitcreatefgw.

Author:  Sergey.Bochkanov [ Fri Feb 04, 2011 9:02 pm ]
Post subject:  Re: Non-linear LSQ parameter error

It is planned in the upcoming release, although there exists small probability that it will be delayed.

As for now, you can try using LSFitState.OptState.QuadraticModel field - it contains Hessian matrix at the last point where function value was evaluated. You can calculate errors using this Hessian matrix (I think that Wikipedia has corresponding formulas). This field can be hidden between several layers of OOP protection (details depend on programming language you use), so you have to modify ALGLIB source to be able to read it.

Author:  toldi00 [ Thu Sep 20, 2012 8:36 am ]
Post subject:  Re: Non-linear LSQ parameter error

Hi,

I return to work with Alglib and I try to get LSQ parameter error.
I remember that quadraticmodel contains 2*J^TJ - Hessian. But I have some problems. Here i s an example:
Code:
void function_cx_1_func(const real_1d_array &c, const real_1d_array &x, double &func, void *ptr)
{
    func = c[0] + x[0]*c[1];
}

int main(int argc, char **argv)
{

    real_2d_array x = "[[0.],[1.],[2.],[3.]]";
    real_1d_array y = "[1., 2., 4., 8.]";
    real_1d_array c = "[0., 0.]";
    double epsf = 0;
    double epsx = 0.000001;
    ae_int_t maxits = 0;
    ae_int_t info;
    lsfitstate state;
    lsfitreport rep;
    double diffstep = 0.0001;

    lsfitcreatef(x, y, c, diffstep, state);
    lsfitsetcond(state, epsf, epsx, maxits);
    lsfitfit(state, function_cx_1_func);
    lsfitresults(state, info, c, rep);

    for(int i=0; i<2; i++)
   for(int j=0; j<2; j++)
       printf("%f\n", state.c_ptr()->optstate.quadraticmodel.ptr.pp_double[i][j]);

    return 0;

}


and this is output:
8 12
12 28
and now if i change y array for:
Code:
real_1d_array y = "[1., 2., 4., 7";

i have got this same output - this is incorrect.
What is wrong?

Author:  Sergey.Bochkanov [ Fri Sep 28, 2012 12:45 pm ]
Post subject:  Re: Non-linear LSQ parameter error

Sorry for the long delay with reply.

The fact that Hessian does not change with change in y-values is not an error - it is just consequence of the fact that you solve linear problem. You expect that when you change y-values, your solution (c-vector) is changed, which in turn changes Jacobian - and, consequently, Hessian.

However, in linear problems Jacobian is same for all value of c. df/dc0 is same for any value of c0 (given fixed x), df/dc1 is same for any c1 (again, given fixed x). Thus, if you change y-values, solution vector is changed, but Hessian remains the same.

BTW, if you change x-matrix (not y!), you will see significant changes in Hessian.

Author:  toldi00 [ Tue Oct 02, 2012 11:10 am ]
Post subject:  Re: Non-linear LSQ parameter error

Hi,

thank you for the reply. I have got one more question. So how can I calculate error value for c vector? I know that covariance matrix (covar) equels (J^T J)^(-1) and QuadraticModel contains (2 J^T J). In this way for different y vector I have got different c values but still the same Hessian. I would like to fit linear expresion and gauss curve. Maybe I still don't understand something or maybe new version of Alglib will have function to get errors vector for c values?

Author:  Sergey.Bochkanov [ Wed Oct 03, 2012 10:46 am ]
Post subject:  Re: Non-linear LSQ parameter error

I've found an article on this question: www.duke.edu/~hpgavin/ce281/lm.pdf

It is planned to implement such functionality in one of the next ALGLIB releases, but I still not sure which release will it be.

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/