Why M_Covar is missing when doing global fit?

I use global fit package to fit a set of data. The y waves are EDC5,EDC6,EDC7..., the x waves are the calculated x scaling. The mask wave is the wave mask. My fit function is user-defined function PINEMnewfit. I used Igor debug. The error is M_covar is missing. Why global fit package doesn't work for this case? The Igor file is in the attachment. My Igor version is 8. Thanks.

Experiment.pxp (758.75 KB)

First, your fit runs forever on my session, so I assume your fit function contains an error or the fit is otherwise not well defined, even when I do a single fit. Does this ever converge on your PC? If yes, then I also recommend investing some time into speed optimization (for example, getting rid of the do-while loops).

Anyway, I assume you abort the fit at some point, which triggers these errors you mentioned. Because the fit does not complete, some output waves do not exist such as M_covar. So the bug is that this was not properly checked in the code. This has been fixed. You should contact the user support via email directly to receive a new version. However, this will not help the fit, only fix the error messages when the fit is aborted.

In reply to by chozo

Thanks a lot. Indeed I abort the fit halfway. I just need to wait till the fit is complete and then there is no error report. The reason there is loop in j is that the fit fucntion contains convolution. Also I changed the increment of j from 0.05 to 0.1.

Great. Just in case you want to speed up / optimize this fit: May I ask what the mathematical model for this fit is? There are many ways to do a convolution in Igor, and I think using something MatrixOP or FFT would extremely increase the performance and or accuracy.

In reply to by chozo

The physical problem I am trying to fit is PINEM (photon induced near field electron microscopy) spectra. The mathematical model is formula S20 in the attachment. And when writting the convolution in the integral form explicitly it is formula S21. It contains Bessel function of the first kind Jk. The reason why I don't use convolve function in Igor is because it is time (a parameter in the fitting function) that invovles in the convolution. The independent variable in the fitting function is just energy but not time. I don' t know how to use convolve for such a situation so I do the convolution in time manually.

PINEMformula1.png (20.36 KB) PINEMformula2.png (26.54 KB)

Thanks for sharing the equation. I haven't looked too closely but it seems that this is a convolution with a Gaussian, right? This should be doable by preparing a Gaussian wave and then use Convolve. I don't see a problem that the convolution is in the time domain. Maybe someone better knowledgeable in the math could also devise a neat way using FFT and iFFT. Here is a simple implementation of a Gaussian convolution as a start:

function ConvolveGauss(wave in, variable width)
    if (width == 0 || numtype(width) != 0)
        return 0
    endif
   
    variable pnt, dx  = DimDelta(in,0), size = DimSize(in,0)
    width = abs(width/dx)/sqrt(2)       // normalized by x scaling and convert to Gauss 'width'
    pnt = round(max(abs(10*width),11))  // create a wave 10 times the width (5 sigma on each side)
    pnt = min(pnt, 2*numpnts(in)+1)     // doesn't have to be larger than 2x the input data
    pnt = pnt+!mod(pnt, 2)              // force odd size

    Make/FREE/D/N=(pnt) GaussWave  
    GaussWave = Gauss(x, (pnt-1)/2, width)
    variable A = sum(GaussWave)
    if (A > 1)
        GaussWave /= A
    endif
   
    Make/FREE/D/N=(2*pnt+size) temp = in[0]
    temp[pnt,size+pnt-1] = in[p-pnt]
    temp[size+pnt,size+2*pnt-1] = in[size-1]
    MatrixOP/Free temp = replaceNaNs(temp,0)
   
    Convolve/A GaussWave temp
    in[0,size-1] = temp[p+pnt]
end

 

A key part of the problem is that to use Convolve in a fitting function, you need to use an all-at-once formatted fitting function. For more information: DisplayHelpTopic "All-At-Once Fitting Functions"

Copy that command, paste it into Igor's command line and press Enter.