Fminsearch for fitting models (unconstrained nonlinear minimization of rmse)

4 vues (au cours des 30 derniers jours)
Wenquan
Wenquan le 5 Fév 2023
Commenté : Wenquan le 5 Fév 2023
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);
Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 1-by-2424.

Error in fminsearch (line 201)
fv(:,1) = funfcn(x,varargin{:});
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

Réponse acceptée

Matt J
Matt J le 5 Fév 2023
rmse= sqrt(sum((ydata-(c1./(1+exp(-a1-b1.*xdata))+c2./(1+exp(-a2-b2.*xdata))+d).^2))./numel(xdata));
  5 commentaires
Matt J
Matt J le 5 Fév 2023
Modifié(e) : Matt J le 5 Fév 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.
Wenquan
Wenquan le 5 Fév 2023
Thank you very much! Your answer is very helpful for me!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Get Started with Curve Fitting Toolbox dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by