forum.alglib.net

ALGLIB forum
It is currently Wed Dec 25, 2024 2:16 pm

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  [ 3 posts ] 
Author Message
 Post subject: MinBFGS with user-provided gradient.
PostPosted: Fri Apr 28, 2017 8:43 am 
Offline

Joined: Fri Apr 28, 2017 8:36 am
Posts: 2
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


Top
 Profile  
 
 Post subject: Re: MinBFGS with user-provided gradient.
PostPosted: Fri Apr 28, 2017 10:14 am 
Offline
Site Admin

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


Top
 Profile  
 
 Post subject: Re: MinBFGS with user-provided gradient.
PostPosted: Fri Apr 28, 2017 11:16 am 
Offline

Joined: Fri Apr 28, 2017 8:36 am
Posts: 2
Yes, this works perfectly. Thank you very much!


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

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 3 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:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group