forum.alglib.net

ALGLIB forum
It is currently Sun Dec 22, 2024 6:48 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  [ 5 posts ] 
Author Message
 Post subject: Function callback after each iteration
PostPosted: Tue Nov 23, 2010 3:30 am 
Offline

Joined: Tue Nov 23, 2010 3:13 am
Posts: 3
First thank you for this very nice library.

I am very interested in fitting part of it.
It looks like the function I specify as "rep" in the lsfitfit arguments is never called.

Starting from the example 1, 2 or 3, and adding a pointer to my function like this:
Code:
   lsfitfit(state, function_cx_1_func, function_cx_1_grad, my_function_to_call_after_each_iteration, 0);

the code compile and run (and fits), but my_function_to_call_after_each_iteration is never called.

It looks like in the code of lsfitfit:
Code:
        while( alglib_impl::lsfititeration(state.c_ptr(), &_alglib_env_state) )
        {
            if( state.needf )
            {
                func(state.c, state.x, state.f, ptr);
                continue;
            }
            if( state.needfg )
            {
                grad(state.c, state.x, state.f, state.g, ptr);
                continue;
            }
            if( state.xupdated )
            {
                if( rep!=NULL )
                    rep(state.x, state.f, ptr);
                continue;
            }
            throw ap_error("ALGLIB: error in 'lsfitfit' (some derivatives were not provided?)");
        }

the if( state.xupdated ) is never tested. I put a break point here but it never fires.

Thank you,
Gael


Last edited by gael_r on Wed Nov 24, 2010 5:20 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Function callback after each iteration
PostPosted: Tue Nov 23, 2010 5:56 am 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 927
You have to turn reports on by calling lsfitsetxrep(). This part of interface is somewhat counterintuitive, may be it will change it in the next version...


Top
 Profile  
 
 Post subject: Re: Function callback after each iteration
PostPosted: Wed Nov 24, 2010 5:20 am 
Offline

Joined: Tue Nov 23, 2010 3:13 am
Posts: 3
Thank you!
This very would be very meaning full in the documentation of the lsfitfit function (since it is here that rep is passed).


Top
 Profile  
 
 Post subject: Re: Function callback after each iteration
PostPosted: Wed Nov 24, 2010 5:58 pm 
Offline

Joined: Tue Nov 23, 2010 3:13 am
Posts: 3
About the rep function being called after each iteration.
I assume it could be used to monitor the parameters of the fit function as they are being optimized.

It looks however that in the lsfitfit function:
Code:
        while( alglib_impl::lsfititeration(state.c_ptr(), &_alglib_env_state) )
        {
            if( state.needf )
            {
                func(state.c, state.x, state.f, ptr);
                continue;
            }
            if( state.xupdated )
            {
                if( rep!=NULL )
                    rep(state.x, state.f, ptr);
                continue;
            }

it is one of the data point X value that is passed to rep
Shouldn't it be state.c passed to the function ?

also, what us the state.f reference for? Am I supposed to do something with it?

Thanks
Gael


Top
 Profile  
 
 Post subject: Re: Function callback after each iteration
PostPosted: Thu Nov 25, 2010 6:45 am 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 927
Yes, you are right - there was an error in the code generator for 3.1, which was fixed in the 3.2 (expected to be released in the first days of December). You can safely replace it by state.c


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 4 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