forum.alglib.net

ALGLIB forum
It is currently Sat Jul 27, 2024 2:31 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: lsfit and/or minlm guidance
PostPosted: Wed May 15, 2024 9:36 pm 
Offline

Joined: Wed May 15, 2024 7:17 pm
Posts: 2
I have been having trouble getting either the lsfit or the minlm routines to get through a single iteration before terminating with code 2 (relative step is no more than EpsX). I am attempting to fit some nonstandard shaped spectroscopy peaks (standard gaussian shape convolved with a pre-defined number of exponential tails on the low energy side). The low energy tails create overlaps in the spectra that requires a fit of the whole spectrum (just a linear combination of multiple peaks) instead of a simple local fit around individual peaks. I am confident in the functions I am providing the algorithms, the plots using a parameter set of guessed values looks good, and I have been fairly successful getting accurate fits using MPFIT. I was hoping to use algorithms that were a little more robust, and thus my transition to the alglib libraries.

After reading the article on the site about scaling (https://www.alglib.net/optimization/scaling.php) and poking around this message board, I was pretty confident about how the setscale() functions performed and what you are supposed to feed them. I am now about 80% sure I am doing this incorrectly. The second part of the linked article about Uncentered Parameters led me to believe that the scale values should be set to approximately |upperbound – lowerbound| for each parameter. Is this incorrect? I am using boundary conditions, but I am not implementing any linear conditions.

I am just a lowly experimental physicist and do not possess a deep understanding of how these algorithms work. How do I know if I have appropriate values set for espx and the differentiation step? For example, I obviously have a lot of exponentials in my function, does this have any bearing on how these should be configured? Should I be using a minlmsetstpmax()? if so I have no idea what an appropriate maximum step size should be.

Unfortunately my laboratory does not allow me to publicly release anything without an extensive review process, so I am unable to post example code. However, at this point I am just looking for a little high-level guidance. I don’t think it matters for any of the questions I have asked here, but I am using the commercial version of the c# libraries.


Top
 Profile  
 
 Post subject: Re: lsfit and/or minlm guidance
PostPosted: Thu May 16, 2024 11:40 pm 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 921
Hi! Ideally, these algorithms should just work without any knowledge of the underlying math. The idea is that being a physicist is already good enough:)

However, exponential fitting is extremely difficult. No, it is EXTREMELY difficult. In particular, its success sometimes depends on algorithm implementation in a non-obvious manner. Some design decision that greatly improve robustness in many important cases turn out to degrade performance in this case. The be specific, I am a bit concerned by the fact that ALGLIB way of regularizing steps may slow down convergence on convolved problems exactly like yours. I explain it in order for you to understand that there is a possibility that you did everything right, and that is ALGLIB that needs to get better.

Now, several questions first:
* did you fail to get past the first iteration when using analytic derivatives - or numerical gradient?
* how many variables do you have?
* sometimes exponential problems get easier when you solve them with tight box constraints first (to prevent accidental escape from the initial point), and then relax constraints and re-solve. Did you try something like that?

And recommendations:
* for your case (accurate computations over inaccurate experimental data) a small differentiation step is recommended. Something proportional to sqrt(machine_epsilon), like 1E-7 or 1E-6. But not less, you do not want rounding errors to amplify.
* epsx can be chosen higher than the numerical differentiation step, like 1e-3 or 1e-4 for the beginning.


Top
 Profile  
 
 Post subject: Re: lsfit and/or minlm guidance
PostPosted: Fri May 17, 2024 12:17 pm 
Offline

Joined: Wed May 15, 2024 7:17 pm
Posts: 2
I haven’t tried implementing analytical derivatives.

The number of variables depends on how many peaks are in the spectrum and how sophisticated the peak model I’m trying to fit is. It is at least 12, usually around 20-30, and I haven’t tried anything over 40.

I will also try tightening the constraints. One of the problems I had with using MPFIT was that I would sometimes get crazy results after changing the starting values I provided by small amounts. I assumed the algorithm was just getting stuck in local minima, but maybe it was because of some of the difficulties you are alluding to.

I will test these suggestions, thank you so much for your reply and insight.


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: No registered users and 28 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