MATLAB Answers

Fitting a Custom Sigmoid

4 ビュー (過去 30 日間)
Jane Kelleher
Jane Kelleher 2020 年 8 月 26 日
コメント済み: Alex Sha 2020 年 8 月 27 日
Hello,
I have a set of data that decays in a sigmoidal fashion. I believe it should be a good fit to a function of the form shown in the first screenshot, but when I use the Custom Fit feature in the Curvefitting App matlab gives a -Rsq so something is clearly going wrong. I have attached a screenshot of the attempted fit and result as well. I would really appreciate any advice or input as to why this may not be working and alternatives I could try.
Thank you!

  3 件のコメント

Image Analyst
Image Analyst 2020 年 8 月 26 日
OK, but you forgot to attach your data. I'll check back later for it.
Why don't I get that plot:
% Create the X coordinates from 0 to 16 every 0.25 units.
X = 0 : 0.25 : 16;
% Define coefficients and function that the X values obey.
a1 = 0.9157 % Arbitrary sample values I picked.
a2 = 0.6557
Y = a1 * exp(-a2 .* exp(X)); % Get a vector. No noise in this Y yet.
plot(X, Y, 'b.-', 'LineWidth', 2, 'MarkerSize', 20);
grid on;
Jane Kelleher
Jane Kelleher 2020 年 8 月 26 日
Hi Image Analyst,
Thanks for taking a look! If you use a very small a2, eg a2 = .001, then the plot looks as shown. I tried supplying small initial guesses for a2 in hopes to achieve this but no luck. I have attached my data as well. Would really appreciate any advice.
X: xfitting = 11.9548 12.2163 12.4557 12.6716 12.8765 13.0460 13.1972 13.3442 13.5011 13.6685 13.8478 13.9055 13.9632 14.0369 14.1113 14.1835 14.2536 14.3221 14.3893 14.4557 14.5215 14.5868 14.6518 14.7165 14.7811 14.8456 14.9100 14.9743 15.0385 15.1028 15.1670 15.2311 15.2953
Y: S_nonresistantdecline = 7.6631 7.6559 7.6296 7.5846 7.5179 7.4405 7.3509 7.2422 7.0991 6.9124 6.6719 6.5860 6.4965 6.3773 6.2533 6.1313 6.0132 5.9015 5.7971 5.7009 5.6140 5.5376 5.4724 5.4181 5.3743 5.3397 5.3130 5.2927 5.2775 5.2663 5.2581 5.2520 5.2477
Jane Kelleher
Jane Kelleher 2020 年 8 月 26 日
I also tried adding a plateau for the base, ie: a1 * exp(-a2 .* exp(X)) + a3

サインインしてコメントする。

採用された回答

Alex Sha
Alex Sha 2020 年 8 月 27 日
Hi,if the fitting function is:
1:y=a1*exp(-a2*exp(x))
Root of Mean Square Error (RMSE): 0.291990919479646
Sum of Squared Residual: 2.81353700293277
Correlation Coef. (R): 0.943693599341358
R-Square: 0.890557609437848
Adjusted R-Square: 0.883261450067038
Parameter Best Estimate
---------- -------------
a1 7.58840204504645
a2 1.16352684388827E-7
2:y=a1*exp(-a2*exp(x))+a3
Root of Mean Square Error (RMSE): 0.111213914229836
Sum of Squared Residual: 0.408161645704602
Correlation Coef. (R): 0.991993546182226
R-Square: 0.984051195667188
Adjusted R-Square: 0.982987942045001
Parameter Best Estimate
---------- -------------
a1 3.31691483854775
a2 6.92191293955397E-7
a3 4.93177045354278
3:y=a1*exp(-a2*exp(a4*x))+a3
Root of Mean Square Error (RMSE): 0.00643423581192002
Sum of Squared Residual: 0.001366179885952
Correlation Coef. (R): 0.999973308091645
R-Square: 0.999946616895747
Adjusted R-Square: 0.999943058022131
Parameter Best Estimate
---------- -------------
a1 2.46665608498939
a2 4.05630590375969E-12
a4 1.85195743324274
a3 5.25959927640292

  3 件のコメント

Jane Kelleher
Jane Kelleher 2020 年 8 月 27 日
Hi Alex,
This is so helpful, thank you! I am still having issues achieving a similar fit on my own, though. I tried both curvefit app and fitting in my code, but neither is working out. Do you by chance see a glaring mistake in my approach? I've also attached a plot of the bad fit I get. Thanks again so much- I'm quite stuck.
Bad fit:
a1 = 0.6991
a2 = 0.8909
a3 = 6.233
a4 = 0.5472
The function:
function y = sigmoidfit(x,a1,a2,a3, a4)
y = a1 * exp(-a2*exp(a4.*x))+a3
end
_________________________________________________________________
%The fit:
fout = fittype( "sigmoidfit(x, a1, a2, a3, a4)", 'independent', {'x'}, 'coefficient', {'a1','a2','a3', 'a4'} )
%options = fitoptions(fout);
%options.StartPoint = [2.46665608498939, .0000000000004, 1.85195743324274, 5.25959927640292];
result = fit(xfitting(:),S_nonresistantdecline(:),fout)
figure;
plot(result, xfitting(:),S_nonresistantdecline(:))
Jane Kelleher
Jane Kelleher 2020 年 8 月 27 日
Nevermind, got it working- thank you very much!!
Alex Sha
Alex Sha 2020 年 8 月 27 日
Hi, Jane, the above results posted are obtained from another software of "1stOpt". For the fitting function of "y=a1*exp(-a2*exp(a4*x))+a3", it looks simple, but seems to be very difficulty for Matlab, either cftool or lsqcurvefit/nlinfit, to get proper outcomes.

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by