Fminsearch for fitting models (unconstrained nonlinear minimization of rmse)
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi all, I'm trying to use the fminsearch function to fit a double sigmoidal models to my data. And the conditions is minimization of the root mean squared error(RMSE). I have seven parameters. At the moment, I'm using the following code.
load data
%xdata=Limb1_x; % 2424*1 vector
%ydata=Limb1_y; % 2424*1 vector
%type rmseval.mat
fun = @(v)rmseval(v,xdata,ydata);
v0= rand(1,7);
bestv = fminsearch(fun,v0);
a1=bestv(1);
a2=bestv(2);
b1=bestv(3);
b2=bestv(4);
c1=bestv(5);
c2=bestv(6);
d=bestv(7);
yfit=c1/(1+exp(-a1-b1*xdata))+c2/(1+exp(-a2-b2*xdata))+d;
figure;
plot(Limb1_x, Limb1_y, '+', 'MarkerSize', 10, 'LineWidth', 2)
hold on
plot(Limb1_x, yfit, '-')
function rmse = rmseval(v,xdata,ydata)
a1=v(1);
a2=v(2);
b1=v(3);
b2=v(4);
c1=v(5);
c2=v(6);
d=v(7);
rmse= sqrt(sum((ydata-(c1/(1+exp(-a1-b1.*xdata))+c2/(1+exp(-a2-b2.*xdata))+d).^2))/numel(xdata));
end
I don't have a good startpunkt. And the error is "Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right sideis 1-by-2424." I'm quite a newbie in optimization. There is something I'm missing? And the data is in attachments.
Thank you in advance
0 Kommentare
Akzeptierte Antwort
Matt J
am 5 Feb. 2023
rmse= sqrt(sum((ydata-(c1./(1+exp(-a1-b1.*xdata))+c2./(1+exp(-a2-b2.*xdata))+d).^2))./numel(xdata));
5 Kommentare
Matt J
am 5 Feb. 2023
Bearbeitet: Matt J
am 5 Feb. 2023
I used trial and error. One of the advantages of fminspleas, however, if that you only need guesses for four of the parameters a1,b1,a2,b2. So, if you have any prior knowledge that can inform your guess of those, that might make things easier in future curve fittings.
Weitere Antworten (0)
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!