forum.alglib.net http://forum.alglib.net/ |
|
Function callback after each iteration http://forum.alglib.net/viewtopic.php?f=2&t=127 |
Page 1 of 1 |
Author: | gael_r [ Tue Nov 23, 2010 3:30 am ] |
Post subject: | Function callback after each iteration |
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 |
Author: | Sergey.Bochkanov [ Tue Nov 23, 2010 5:56 am ] |
Post subject: | Re: Function callback after each iteration |
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... |
Author: | gael_r [ Wed Nov 24, 2010 5:20 am ] |
Post subject: | Re: Function callback after each iteration |
Thank you! This very would be very meaning full in the documentation of the lsfitfit function (since it is here that rep is passed). |
Author: | gael_r [ Wed Nov 24, 2010 5:58 pm ] |
Post subject: | Re: Function callback after each iteration |
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 |
Author: | Sergey.Bochkanov [ Thu Nov 25, 2010 6:45 am ] |
Post subject: | Re: Function callback after each iteration |
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 |
Page 1 of 1 | All times are UTC |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |