Fminsearch for fitting models (unconstrained nonlinear minimization of rmse)

조회 수: 4 (최근 30일)
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

채택된 답변

Matt J
Matt J 2023년 2월 5일
rmse= sqrt(sum((ydata-(c1./(1+exp(-a1-b1.*xdata))+c2./(1+exp(-a2-b2.*xdata))+d).^2))./numel(xdata));
  댓글 수: 5
Matt J
Matt J 2023년 2월 5일
편집: Matt J 2023년 2월 5일
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 2023년 2월 5일
Thank you very much! Your answer is very helpful for me!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by