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);
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 件のコメント
採用された回答
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
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.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File 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!