Finding out what initial guesses the curve fitting toolbox made for curve fit
10 views (last 30 days)
Hi everyone, thank you for your time,
I am currently working on a code that inputs real-life indentation data to fit them through a curve fitting toolbox. The relevant code portion is as below:
f1 = fittype('a0+(a1-a0)*((0.491*exp(-0.908*sqrt((abs(a3)*x)/(C0^2))))+(0.509*exp(-1.679*sqrt((abs(a3)*x)/(C0^2)))))','problem','C0')
f = fit( Hx, Hy, f1, 'problem', C0, 'lower',[0,0,0])
As you can see, I have not specified starting conditions, because we work with different tissues that each have different local minima (which creates non-fits). So I am letting MatLab randomize the starting points ( coeffiecient a0,a1,a3) to get global minima.
I am currently using r2 comparison to choose the best results. What I am also interested is recording what initial values Matlab chose for a0,a1 and a3 for the better runs (higher r2) so that I can make separate codes for particular tissues with preset inital guesses.
Thank you all for your time.
Matt J on 20 Oct 2021
Edited: Matt J on 21 Oct 2021
I don't think there's anyway to dig out the initial guess generated inside fit(), but why not just specify your own random start point(s)? I can't imagine there's any advantage to letting fit() do it internally.
Also, note that your problem can be reduced to a single unknown (a3) as below. You might be able to do a simple one-dimensional parameter sweep for an accurate initial guess a3_0.
fun=@(a3) mdl(a3,Hx,Hy,C0); %1D function of a3
a3=fminsearch( fun, a3_0); %a3_0 = initial guess of a3