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

MinBFGS with user-provided gradient.
http://forum.alglib.net/viewtopic.php?f=2&t=3800
Page 1 of 1

Author:  amris [ Fri Apr 28, 2017 8:43 am ]
Post subject:  MinBFGS with user-provided gradient.

Hello everyone

I'm having some trouble with the minBFGS optimization routine where i pass my own gradient. The problem is that the optimization exits with code 4 after the first iteration. I've debugged the problem, at it seems like the state.innerobj.g array is 0. My quess is then that for some reason, the gradient that i'm updating inside the function "OptimizationFunction_AD_grad" is not passed in to the state of the algorithm.

I've copied my code for initiating the optimization problem and the optimization function itself (the callback).

http://textuploader.com/drgps

The gradient that is calculated in the function (grad) looks fine and is non-zero, so i cannot figure out, what goes wrong.

Does anyone have an idea of what is wrong based on the code i've uploaded?

Best

Author:  Sergey.Bochkanov [ Fri Apr 28, 2017 10:14 am ]
Post subject:  Re: MinBFGS with user-provided gradient.

Hi! The problem is that you overwrite grad parameter with a reference to another instance of double[] array. But how can optimizer find out this reference? It has no way of knowing about it.

The idea is that optimizer pre-allocated for you 1D array grad and gave you a reference; you should update its content, i.e. repeatedly initialize grad[i] with values.

Does it solve your problem?

Author:  amris [ Fri Apr 28, 2017 11:16 am ]
Post subject:  Re: MinBFGS with user-provided gradient.

Yes, this works perfectly. Thank you very much!

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