SpinW / spinw

SpinW Matlab library for spin wave calculation
http://www.spinw.org
GNU General Public License v3.0
35 stars 15 forks source link

error values from the lm option #160

Closed Yukkuri-programing closed 4 months ago

Yukkuri-programing commented 9 months ago

In fitspec.m, comments about the 'lm' fitting method as "does not work due to the binning of the spectrum. newspec_fitfun is required for this". But using this lm option, error values of fitted parameters can be obtained. Should we think that these error values are not reliable?

mducle commented 9 months ago

@Yukkuri-programing

Should we think that these error values are not reliable?

Sort of... rather the problem is two fold - 1) the fitted parameters themselves using the lm option might not be the optimal and 2) the uncertainties in the fitted parameters might be inaccurate (it could be either an under- or over-estimate, it is not easy to tell a-priori).

The main problem for SpinW with fitting TAS data is assigning the calculated modes to the measured peaks: SpinW uses a heuristic which matches calculated modes to the input measurements at each Q-point as follows:

  1. It bins the data according to the Evect parameter you specify (or using a default 500 bins) within the ENlim1 and ENlim2 range specified in the input data file.
  2. It sorts the calculated modes in order of intensity and keeps the n most intense modes where n is the number of input measured peaks at the specified Q-point.
  3. It finds the consecutive mode indices which remain after steps 1 and 2 which yield the smallest difference between the calculated energies and the input (measured) energies.

The issue is that at some values of the model parameters (e.g. exchange / SIA) the mode assignment could suddenly change - e.g. If you have a zone-centre Q-point and specify say ENlim1 as 0.2meV to ignore the elastic line but have an SIA term which above some value gives a spin gap which exceeds 0.2meV you'll go from having a mode (probably quite intense as it is the goldstone mode at the zone centre) which is ignored to not being ignored. Alternatively you could go from having a calculated mode with an energy almost in the middle between two measured peak energies; a slight change of exchange parameters would then switch from it being assigned from one measured peak to another measured peak.

When this happens (when the mode assignment suddenly changes) the R-value which is being minimised changes discontinuously (SpinW uses the weighted difference between the measured and calculated energies as the R-value).

Now, Levenberg-Marquardt (lm) algorithm is a gradient descent method and uses the derivative of the fit function (the R-value) w.r.t. the parameters (the Jacobian) to calculate the best direction to go in parameter space (the direction in which the R-value decreases best). So, for a non-continuous R-value as we have, it might not find the best local minimum.

In addition, the uncertainty in the fitted parameters is also calculated from the Jacobian. This means that if your optimum parameter is near a discontinuity in the R-value then the Jacobian will have a jump and the estimated uncertainties will be wrong (probably a large overestimate but it could also be an underestimate).


Now, I think what you might try to do is to use one of the other methods (either simplex or pso which are both gradient-free methods) first to find a good set of fitted parameters, and then use this set of fitted parameters with the lm method with a small nMax (maybe nMax=1) to try to get the uncertainties. You can try this with slight variations in the input parameters to the lm method - If you get similar fitted parameters and uncertainties for several different sets of initial parameters close together and several different values of nMax then the parameters and uncertainties are probably valid.


Note this is an almost-duplicate of this issue: https://github.com/SpinW/spinw/issues/66