Finding out what initial guesses the curve fitting toolbox made for curve fit
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Muhtadi Zahin
am 20 Okt. 2021
Kommentiert: Muhtadi Zahin
am 21 Okt. 2021
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.
2 Kommentare
Matt J
am 20 Okt. 2021
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.
Why would the initial values be better for future presettings than the final solutions?
Akzeptierte Antwort
Matt J
am 20 Okt. 2021
Bearbeitet: Matt J
am 21 Okt. 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
[~,coeffs]=fun(a3);
a0=coeffs(1);
a1=sum(coeffs);
function [resnorm,coeffs]=mdl(a3,x,y,C0)
x=x(:); y=y(:);
z=((0.491*exp(-0.908*sqrt((abs(a3)*x)/(C0^2))))+(0.509*exp(-1.679*sqrt((abs(a3)*x)/(C0^2)))));
opts=optimoptions('lsqlin','Display','off');
[coeffs,resnorm]=lsqlin(z.^[0,1],y,-[1,1],0,[],[],[0,-inf],[],[],opts);
end
3 Kommentare
Matt J
am 21 Okt. 2021
Bearbeitet: Matt J
am 21 Okt. 2021
I'm not sure if discounting a0 and a1 in my code will work, because I need the values of coefficients a0 and a1 to use in separate equations to find poroelastic properties.
My proposed code doesn't discount a0 and a1. It just computes them at the very end, after a3 has been fit. Fitting a3, however, requires that you minimize a function of a3 (and only a3). Therefore, you only need an initial guess for a3 and not for the other two parameters..
I am not sure how to do the 2nd option, frankly.
It's just,
f = fit( Hx, Hy, f1, 'problem', C0, 'lower',[0,0,0],'StartPoint', rand(1,3))
This is the same as what fit() does by default when 'StartPoint' is not specified manually. Obviously, you could use randn() or other random distributions if you think they would make more sense.
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!