Fit data to a simple 3 parameters exponential curve
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Charles
am 11 Mär. 2014
Kommentiert: Charles
am 13 Mär. 2014
Hello ! I'm trying to fit a signal (y) as a function of the time (x) using this custom curve : y=a+b*exp(-c/x); I'm looking for the c value which is around 0.005. However, the levenberg=marquardt algorithm find false values even if a & b are fixed parameters.. If you have some explanations..
time:https://www.dropbox.com/s/9jt2wsfhu63fjb1/time.mat
signal:https://www.dropbox.com/s/rjxs5a6wg1e66pk/T1recovery.mat
thank you very much !
charles
5 Kommentare
John D'Errico
am 12 Mär. 2014
Bearbeitet: John D'Errico
am 12 Mär. 2014
I see your question about why the curve fitting TB fails. Read my answer, as it suggests at least part of the reason for that failure - the model simply does not fit if you try to shoehorn it onto your data. Only if you exclude the first part of the series does it fit even decently. Even then, a change of model improves things as I show.
Akzeptierte Antwort
John D'Errico
am 12 Mär. 2014
Bearbeitet: John D'Errico
am 12 Mär. 2014
I'm sorry, but I had to laugh out loud when I plotted the data after looking at the model form you posed. The two are simply not compatible.
There is a slope discontinuity in your curve, which simply does not happen in that model. Perhaps you intend to fit only the portion of your curve AFTER that point. So then why supply all of the curve?
plot(time,signal,'o')
xlabel time
ylabel signal

If I discard the first 14 data points in that curve, then it has some possibility to fit the model you pose. So lets try fminspleas here:
flist={1, @(c,x) exp(-c./x(:))};
[c,ab]=fminspleas(flist,.005, time(15:end), signal(15:end))
c =
77.619
ab =
-13077
21637
See that the discontinuity happens at about time = 150.
time(15)
ans =
150
Now look at the fit. I'll add the discarded points to the plot, but in red.
ezplot(@(x) ab(1) + ab(2)*exp(-c./x),[150,1000])
hold on
plot(time(1:14),signal(1:14),'r+',time(15:end),signal(15:end),'go')
axis('auto')
xlabel time
ylabel signal

I would argue there may be some lack of fit, although I do not know if that degree of model failure is significant. Only you can judge the seriousness of it, since only you know what you will do with the model, and how good is the data.
flist={1, @(c,x) exp(-c*x(:))};
[c,ab]=fminspleas(flist,.005, time(15:end), signal(15:end))
c =
0.0048042
ab =
6822.7
-13890
ezplot(@(x) ab(1) + ab(2)*exp(-c*x),[150,1000])
hold on
plot(time(1:14),signal(1:14),'r+',time(15:end),signal(15:end),'go')
axis('auto')
xlabel time
ylabel signal

See that this VERY arbitrary change of model seems actually to fit a bit better.
This brings up an important point. Very often those who build such models do so just because they picked some functional form that they hope fits the data, not from any physical expectations that the form indeed represents the data. When this is the case, we might choose to look around for a better form, although I often argue that this is the time for a spline fit, since there was no real reason for that arbitrary choice. (If you have avoided a spline fit because splines may sometimes not behave in a monotone fashion, or have some desired shape, then you have not found my SLM toolbox.)
This is not to say that it is ALWAYS right to use a spline. For example, if your goal is to do some extrapolation, a nonlinear model, IF it is a good fit, may extrapolate rather better than spline. And certain models (what I call metaphorical models) may be able to provide some amount of physical intuition about the process under study. Or you might be able to describe the curve in terms of some of the model parameters, if they make sense in context of your problem. For example, if the model has a rate parameter in it, estimation of that parameter may help you describe the curve. Or perhaps a toe or shoulder point may be good descriptors of the curve. (Film speed and contrast parameters are often derived from just such models, that fit the curve reasonably well while also providing descriptive parameters of the process.)
Weitere Antworten (1)
Matt J
am 11 Mär. 2014
Bearbeitet: Matt J
am 12 Mär. 2014
FMINSPLEAS would work well for this problem
flist={1, @(c,x) exp(-c./x(:))};
[c,ab]=fminspleas(flist,.005, time, signal);
a=ab(1);
b=ab(2);
4 Kommentare
John D'Errico
am 12 Mär. 2014
Upvoted because of the good choice of tool suggested. :) I added a response with some plots, but nothing really extra beyond scrapping the first 14 data points.
A good point to make is that fminspleas, because it uses a partitioned least squares, is much more robust as a solver since it is solving only a ONE variable nonlinear problem.
Siehe auch
Kategorien
Mehr zu Get Started with Curve Fitting Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!