forum.alglib.net

ALGLIB forum
It is currently Mon Dec 23, 2024 5:18 am

All times are UTC


Forum rules


1. This forum can be used for discussion of both ALGLIB-related and general numerical analysis questions
2. This forum is English-only - postings in other languages will be removed.



Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Non-linear LSQ parameter error
PostPosted: Fri Feb 04, 2011 9:00 am 
Offline

Joined: Fri Feb 04, 2011 8:57 am
Posts: 3
Does anyone know if it is possible to have parameter errors in non-linear least squares? I'm using lsfitcreatefg and lsfitcreatefgw.


Top
 Profile  
 
 Post subject: Re: Non-linear LSQ parameter error
PostPosted: Fri Feb 04, 2011 9:02 pm 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 927
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.


Top
 Profile  
 
 Post subject: Re: Non-linear LSQ parameter error
PostPosted: Thu Sep 20, 2012 8:36 am 
Offline

Joined: Fri Feb 04, 2011 8:57 am
Posts: 3
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?


Top
 Profile  
 
 Post subject: Re: Non-linear LSQ parameter error
PostPosted: Fri Sep 28, 2012 12:45 pm 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 927
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.


Top
 Profile  
 
 Post subject: Re: Non-linear LSQ parameter error
PostPosted: Tue Oct 02, 2012 11:10 am 
Offline

Joined: Fri Feb 04, 2011 8:57 am
Posts: 3
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?


Top
 Profile  
 
 Post subject: Re: Non-linear LSQ parameter error
PostPosted: Wed Oct 03, 2012 10:46 am 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 927
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 11 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group