forum.alglib.net http://forum.alglib.net/ |
|
ALGLIB and C++ http://forum.alglib.net/viewtopic.php?f=2&t=328 |
Page 1 of 2 |
Author: | Vladimir [ Sat Mar 26, 2011 10:21 pm ] |
Post subject: | ALGLIB and C++ |
Hi! I'm newbie in C++ and I'm trying to write a programm using C++ (not C :)). I want to do approximation using non-linear Least squares method. But lsfitfit function requires pointer to function in global scope. It's not usefull when you use objects (because pointer to method are not equal with global function). So I cant use callback-method (using static requires pointer to source object) for calculation function value like this: Code: class MyClass{ private: void function_cx_1_func(const real_1d_array &c, const real_1d_array &x, double &func, void *ptr) { .... } public: FitCoeff() { ... lsfitfit(state, &function_cx_1_func); ... } }; Maybe made some interface for this function like Code: class IFunction(...) { public: virtual double getValue(...)=0; } and send it to lsfitfit()? (maybe best solution are present, I'm newbie in c++) Also is it possible to include in distribution pre-compiled .dlls and .libs? Because adding to project lot of files from src directory are not usefull and filelist are huge. Thx! |
Author: | Sergey.Bochkanov [ Tue Mar 29, 2011 8:12 am ] |
Post subject: | Re: ALGLIB and C++ |
No, I don't think that it is possible to avoid definition of the global function. You may declare it as static (in order to move it to file-only scope), if you want. About precompiled units - yes, it is possible to make .lib file from ALGLIB. But in any way, according to GPL, you should distribute your project with sources (both your sources and ALGLIB). |
Author: | SteSus85 [ Wed Jul 18, 2012 1:19 pm ] |
Post subject: | Re: ALGLIB and C++ |
Hello, I have exactly the same problem. It is impossible to use global function in my case, because it destroies whole concept of classes. On some forums people recommend to use delegates in this situation, but it looks quite complicate at the moment:( Stepan. |
Author: | SteSus85 [ Wed Jul 18, 2012 7:05 pm ] |
Post subject: | Re: ALGLIB and C++ |
I've solved previous trouble, at least it is compiled (I just call as "func = ClassName.ClassFunction()"). But now I have new problem, algorithm (lsfitfit) makes one step left, then step right, then it goes back to initial value of parameter and then it stops! |
Author: | Sergey.Bochkanov [ Thu Jul 19, 2012 5:47 am ] |
Post subject: | Re: ALGLIB and C++ |
Can you post your code here? I will help you to find out explanation, but I need actual code (including function being optimized). |
Author: | Sergey.Bochkanov [ Fri Jul 20, 2012 5:43 am ] |
Post subject: | Re: ALGLIB and C++ |
Are you trying to minimize function which somehow depends on integral computed with Monte-Carlo method? If so, it is very likely that optimizer stops because of noise in the function being optimized. Monte-Carlo is not exact method, different values are returned every time you run it, and these values contain a lot of noise. Conventional optimizers can't be used on such functions. Hmmm... I recomend you to google for "noisy optimization", maybe you will find method suited for your problem. |
Author: | SteSus85 [ Fri Jul 20, 2012 3:08 pm ] |
Post subject: | Re: ALGLIB and C++ |
Sergey.Bochkanov wrote: Are you trying to minimize function which somehow depends on integral computed with Monte-Carlo method? Yes, the minimized function is an integral computed by Monte Carlo. Sergey.Bochkanov wrote: Monte-Carlo is not exact method, different values are returned every time you run it, and these values contain a lot of noise. I use always the same seed for generation pseudo-random numbers for each computation. So if I compute integral two times with the same parameters on different computers I would have exactly the same value always. Sergey.Bochkanov wrote: Hmmm... I recomend you to google for "noisy optimization", maybe you will find method suited for your problem. Perhaps, I'll do it, thank you for idea. |
Author: | Sergey.Bochkanov [ Mon Jul 23, 2012 10:35 am ] |
Post subject: | Re: ALGLIB and C++ |
SteSus85 wrote: Monte-Carlo is not exact method, different values are returned every time you run it, and these values contain a lot of noise. I use always the same seed for generation pseudo-random numbers for each computation. So if I compute integral two times with the same parameters on different computers I would have exactly the same value always. The problem is in how your integral changes when you change integration area or some other parameter. "Exact" integral is smooth with respect to changes in the integrand, Monte Carlo integral is nonsmooth. I suppose that is the source of your problems. |
Author: | SteSus85 [ Mon Jul 23, 2012 9:51 pm ] |
Post subject: | Re: ALGLIB and C++ |
Sergey.Bochkanov wrote: SteSus85 wrote: Monte-Carlo is not exact method, different values are returned every time you run it, and these values contain a lot of noise. I use always the same seed for generation pseudo-random numbers for each computation. So if I compute integral two times with the same parameters on different computers I would have exactly the same value always. The problem is in how your integral changes when you change integration area or some other parameter. "Exact" integral is smooth with respect to changes in the integrand, Monte Carlo integral is nonsmooth. I suppose that is the source of your problems. Monte-Carlo integral is a sum of integrand-functions. So, if an integrand is smooth then Monte Carlo integral is also smooth. But in my case the integrand is unsmooth in certain point. So, I think you are right, unsmoothness can be a problem. I'll try to make the integrand smooth in that point! |
Page 1 of 2 | All times are UTC |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |