Hi, I am trying perhaps something foolish but let me pose the question anyway. I am trying to fit a data whose model is an unknown sum of gaussians. I would like to try starting with one Gaussian term and increase the number of terms up until lsqcurvefit provides the best fit i.e., let lsqcurvefit decide for me the number of terms to be used and then let it fit its parameters too.
I do the following:
p0=[n zeros(1,100)]
G=lsqcurvefit(@FUN,p0,x,y)
function FUN(p0,x)
for i=1:round(p0(1))
build the expression f=[f 'f1(i)+f2(i)...
eval(string expression f)
return
Note that I have to provide some large number of zero initial parmeters even though number of parameters may be much small i.e., 20 or so (3 parameters per Gaussian term for say 7 Gaussian terms). I realize I cannot vary the number of initial parameters when it is lsqcurvefit which decides that. So I am helpless here..but it works so far.
I expect the lsqcurvefit to search for most effective 'n' i.e., number of Gassian terms which describe my data and then fit it to get the 20 parameters even though their start value is initialized to zero.
However, I see that 'n' always remains at 1 or whatever lowerbound I give to that parameter. I realized that lsqcurvefit may not be searching the integer parameter space. And moreover not sure how xtol would now behave. I am quite perplexed.
I could try comparing residual after each term and decide with my own logic to arrive at the number of terms rather than let lsqcurvefit do it for me. But I was looking at easier route and moreover I wasn't sure if my brute force idea is good or efficient.
Any suggestions here would be welcome, Thank you
0 Comments
Sign in to comment.