Curve fitting toolbox can return bogus results for 2 term exponenti... (2024)

8 次查看(过去 30 天)

显示 更早的评论

Matt Brown 2022-11-2

  • 链接

    此问题的直接链接

    https://ww2.mathworks.cn/matlabcentral/answers/1842223-curve-fitting-toolbox-can-return-bogus-results-for-2-term-exponential-functions-is-this-a-bug

  • 链接

    此问题的直接链接

    https://ww2.mathworks.cn/matlabcentral/answers/1842223-curve-fitting-toolbox-can-return-bogus-results-for-2-term-exponential-functions-is-this-a-bug

评论: Walter Roberson 2022-11-3

采纳的回答: Walter Roberson

I am fitting some test data using the curve fitting toolbox and the built in 2 term exponential form, f(x) = a*exp(b*x) + c*exp(d*x). For some reason, one of the test fits returns coeff's that cause the function to go to zero everywhere. However the curve and GOF data that is displayed does not jive with the reported results. If f(x)=0 everywhere, there is no way that R-square would be anywhere close to 1 given the original data.

Is this a bug that needs to be reported? Bad data? Please help!

Curve fitting toolbox can return bogus results for 2 term exponenti... (2)

The input vectors are as follows:

x=[0,12.5450000000000, 25.0900000000000, 54.3900000000000, 81.6900000000000, 109.090000000000, 138.790000000000, 139.090000000000, 139.090000000000, 163.890000000000, 195.390000000000, 202.390000000000]

y=[0, 0.00337831199999972, 0.688170198000000, 1.39894291200000, 2.42361711600000, 3.96215670600000, 7.38800638200000, 7.38893139600000 ,7.35868746000000, 11.7483615060000, 19.7050504080000, 23.7202546560000]

0 个评论

显示 -2更早的评论隐藏 -2更早的评论

请先登录,再进行评论。

请先登录,再回答此问题。

采纳的回答

Walter Roberson 2022-11-2

  • 链接

    此回答的直接链接

    https://ww2.mathworks.cn/matlabcentral/answers/1842223-curve-fitting-toolbox-can-return-bogus-results-for-2-term-exponential-functions-is-this-a-bug#answer_1090093

  • 链接

    此回答的直接链接

    https://ww2.mathworks.cn/matlabcentral/answers/1842223-curve-fitting-toolbox-can-return-bogus-results-for-2-term-exponential-functions-is-this-a-bug#answer_1090093

Sum of exponentials is notoriously difficult to fit.

One of the problems is that you did not put bounds on your variables. When you have a*exp(b*x) + c*exp(d*x) then a and b can change places with c and d and you would have exactly the same sum. If a and c are different signs (not at all uncommon for this kind of fitting) then when you do not put in bounds, the fitting will not be able to tell which of the two is to be positive or negative, and so the error bounds will cross the entire range, and the fit will be useless. Any time you have terms with identical forms, you need to impose constraints to have any hope of getting a useful fit.

But even then, it is quite common that one of b or d goes towards negative infinity times sign(x) so that exp(d*x) goes to 0, nearly removing the term -- or that one of the two goes towards 0, making exp(d*x) go to 1, making c into nearly an additive term. Yes, in theory you can do better mathematically, but in practice the error often increases as you move away from one of those two positions. If your starting positions do not happen to fall inside the right range, then the exponential increase in error as you move towards the peak error lead the miniizers to move further from the actual best location . Starting values are crucial for the fitting techniques that are used by the curve fitting toolbox.

I have read that there exist fitting algorithms specifically for sum of exponentials, that should do a better job, but I have not researched those algorithms. Some kind of transform has to be used, I gather.

4 个评论

显示 2更早的评论隐藏 2更早的评论

Matt Brown 2022-11-2

此评论的直接链接

https://ww2.mathworks.cn/matlabcentral/answers/1842223-curve-fitting-toolbox-can-return-bogus-results-for-2-term-exponential-functions-is-this-a-bug#comment_2444363

  • 链接

    此评论的直接链接

    https://ww2.mathworks.cn/matlabcentral/answers/1842223-curve-fitting-toolbox-can-return-bogus-results-for-2-term-exponential-functions-is-this-a-bug#comment_2444363

编辑:Matt Brown 2022-11-2

Yes, I was going to try setting bounds on these and see if I could fix it. I am in an early exploratory phase just trying out different fits to a larger data set and just sort of stumbled into this issue. However, my real concern here (which I guess I didn't make very clear based on the other comment) was that the toolbox returns coefficients which cause f(x) to work out to zero but then plots and displays stats for a different non-zero curve.

Scroll all the way to the right in my screenshot and you will see what I mean. a=-c and b=d so that f(x)=a*exp(b*x)+c*exp(d*x) is actually a*exp(b*x)- a*exp(b*x)=0.

Walter Roberson 2022-11-2

此评论的直接链接

https://ww2.mathworks.cn/matlabcentral/answers/1842223-curve-fitting-toolbox-can-return-bogus-results-for-2-term-exponential-functions-is-this-a-bug#comment_2444393

  • 链接

    此评论的直接链接

    https://ww2.mathworks.cn/matlabcentral/answers/1842223-curve-fitting-toolbox-can-return-bogus-results-for-2-term-exponential-functions-is-this-a-bug#comment_2444393

Well, what you know is that they came out the same to four decimal places . You would have to use coefficients() of the fit object to see more decimal places.

Matt Brown 2022-11-3

此评论的直接链接

https://ww2.mathworks.cn/matlabcentral/answers/1842223-curve-fitting-toolbox-can-return-bogus-results-for-2-term-exponential-functions-is-this-a-bug#comment_2444483

  • 链接

    此评论的直接链接

    https://ww2.mathworks.cn/matlabcentral/answers/1842223-curve-fitting-toolbox-can-return-bogus-results-for-2-term-exponential-functions-is-this-a-bug#comment_2444483

I think you nailed it on that comment. I was only working in the toolbox and hadn't exported any fitobjects to check coefficients. I figured I would go check and when I re-ran the fit, I got a slightly different result. The a and c coefficients on the second attempt are 2 orders of magnitude less and do show some disagreement in the last decimal. I assume the same is true of b and d.

I wonder, is there a way to change the number format of the results window in cftool? It's a little annoying to not have any (obvious) control over that inside the toolbox.

Thanks for your help!

Walter Roberson 2022-11-3

此评论的直接链接

https://ww2.mathworks.cn/matlabcentral/answers/1842223-curve-fitting-toolbox-can-return-bogus-results-for-2-term-exponential-functions-is-this-a-bug#comment_2444768

  • 链接

    此评论的直接链接

    https://ww2.mathworks.cn/matlabcentral/answers/1842223-curve-fitting-toolbox-can-return-bogus-results-for-2-term-exponential-functions-is-this-a-bug#comment_2444768

Sorry, there is not much control over the provided apps. Sometimes if you dig into the source code for long enough you can come up with a usable code change, but most of the time it is a change in code that is needed, not a change in some setting. (Occasionally if you dig harder still, it is possible to figure out how to dig into the internals far enough to change some settings without changing the source code.)

请先登录,再进行评论。

更多回答(1 个)

John D'Errico 2022-11-2

  • 链接

    此回答的直接链接

    https://ww2.mathworks.cn/matlabcentral/answers/1842223-curve-fitting-toolbox-can-return-bogus-results-for-2-term-exponential-functions-is-this-a-bug#answer_1090068

  • 链接

    此回答的直接链接

    https://ww2.mathworks.cn/matlabcentral/answers/1842223-curve-fitting-toolbox-can-return-bogus-results-for-2-term-exponential-functions-is-this-a-bug#answer_1090068

编辑:John D'Errico 2022-11-2

Is it bug? NO.

Is it due to poor starting values? Almost always, yes. At least, unless the curve is simply not well fit by a two term exponential.

You have a dozen data points, and you want to fit 4 parameters? Using exponentials? And you want to see good results? Sigh.

x=[0,12.5450000000000, 25.0900000000000, 54.3900000000000, 81.6900000000000, 109.090000000000, 138.790000000000, 139.090000000000, 139.090000000000, 163.890000000000, 195.390000000000, 202.390000000000];

y=[0, 0.00337831199999972, 0.688170198000000, 1.39894291200000, 2.42361711600000, 3.96215670600000, 7.38800638200000, 7.38893139600000 ,7.35868746000000, 11.7483615060000, 19.7050504080000, 23.7202546560000];

numel(x)

ans = 12

plot(x,y,'o')

Curve fitting toolbox can return bogus results for 2 term exponenti... (9)

When I look at that curve, I might bet that a single exponential will fit entirely reasonably. As such, if this next plot is a straight line, then it will be.

semilogy(x,y,'o')

Curve fitting toolbox can return bogus results for 2 term exponenti... (10)

So except for the VERY first data point, it virtually IS a straight line. And that means to fit a second term in that exponential fit, you have only ONE piece of data, maybe two, to support estimating that pair of coefficients.

Should you be even remotely surprised the two term fit looks strange to you, in the sense that one of those exponentials seemed to be nonsense? NO!!!!!

[mdl1,G1] = fit(x',y','exp1')

mdl1 =

General model Exp1: mdl1(x) = a*exp(b*x) Coefficients (with 95% confidence bounds): a = 0.5475 (0.441, 0.654) b = 0.01853 (0.0175, 0.01957)

G1 = struct with fields:

sse: 1.8182 rsquare: 0.9973 dfe: 10 adjrsquare: 0.9970 rmse: 0.4264

mdl1

mdl1 =

General model Exp1: mdl1(x) = a*exp(b*x) Coefficients (with 95% confidence bounds): a = 0.5475 (0.441, 0.654) b = 0.01853 (0.0175, 0.01957)

G1

G1 = struct with fields:

sse: 1.8182 rsquare: 0.9973 dfe: 10 adjrsquare: 0.9970 rmse: 0.4264

plot(mdl1,x,y,'ro')

Curve fitting toolbox can return bogus results for 2 term exponenti... (11)

So am I even REMOTELY surprised that R^2 is very near 1? WHY? THE FIT LOOKS QUITE GOOD, even for a 1-term exponential. Far too many people seem to be ruled by R^2. In my opinion, R^2 is slightly more valuable than a pile of rubbish, but not by a lot. If the curve appears to fit well when you plot it, don't worry about R^2.

This is not a bug in the curve fitting toolbox. It is a problem in your understanding of modeling and curve fitting. Can we try to fit a 2 term exponential? POSSIBLY. But ONLY if we use good starting values would there be much chance. And even then, again, you have WAY too little data. At least we have decent starting vlaues for the main term in the model, so I will use them, and then guess at the other term. (I tried a couple of times before I was satisfied with the results.) Your data is pretty much useless for that model, yet your expectations are really high. Double sigh.

[mdl2,G2] = fit(x',y','exp2','start',[0.54 0.018,-0.1,-0.01])

mdl2 =

General model Exp2: mdl2(x) = a*exp(b*x) + c*exp(d*x) Coefficients (with 95% confidence bounds): a = 0.5936 (0.4233, 0.7638) b = 0.01812 (0.01667, 0.01956) c = -0.6606 (-1.324, 0.002361) d = -0.01838 (-0.07988, 0.04312)

G2 = struct with fields:

sse: 1.0043 rsquare: 0.9985 dfe: 8 adjrsquare: 0.9979 rmse: 0.3543

plot(mdl2,x,y,'ro')

Curve fitting toolbox can return bogus results for 2 term exponenti... (12)

Is that result meaningful? I doubt it is worth much, since that second exponential term is literally based on about 1 data point. Note the width of the confidence bounds on parameters c and d. Do you see that even the sign of that second rate parameter is in question?

Why is it that everytime someone sees something they don't understand, it must be a bug? This just requires experience in curve fitting.

2 个评论

显示 无隐藏 无

Matt Brown 2022-11-2

此评论的直接链接

https://ww2.mathworks.cn/matlabcentral/answers/1842223-curve-fitting-toolbox-can-return-bogus-results-for-2-term-exponential-functions-is-this-a-bug#comment_2444353

  • 链接

    此评论的直接链接

    https://ww2.mathworks.cn/matlabcentral/answers/1842223-curve-fitting-toolbox-can-return-bogus-results-for-2-term-exponential-functions-is-this-a-bug#comment_2444353

编辑:Matt Brown 2022-11-2

Sigh? With all due respect, you don't have the context nor did you speak to my question. The issue I noted was that the curve that was plotted and for which statistics (R-square) were reported was not the curve defined by the coefficients that were returned by the toolbox. There is a discrepancy when you say f(x) works out to zero then show a curve that is not zero. This is what I thought was a bug. How would poor starting values result in this mathematically? I don't follow. If I missed this in your reply, I apologize. It was so long, and frankly rude, that I just gave up on it. You spent a lot of energy telling me why my understanding is wrong without the perspective necessary to offer that advice.

The fit you show looks fine, but the one I show in my screenshot has a=-c and b=d so that f(x)=a*exp(b*x)+c*exp(d*x) is actually a*exp(b*x)- a*exp(b*x)=0.

As it turns out I have a decent understanding of curve fitting and the limitations of fitting small data sets to functions with multiple coefficients. Unfortunately, I have hundreds of similar curves of data (most of which have 2x to 3x the points) to which I have to find fits which share the same form. I am in an exploratory phase, trying out different things to see what works and what doesn't and was seemingly faced with a contradiction when f(x)=0 was not zero in the plot. I just happened to be on the 2-term exponential when this issue arose. I have tried many different forms, both built into the toolbox and custom forms, including 1-term exponentials, and my personal favorite at this stage f(x)=exp(a*x)+b*x-1. It isn't perfect and it presented its own buggy issues which is why I was trying the built in 2-term exponential. (That’s a story for a different thread).

Matt Brown 2022-11-2

此评论的直接链接

https://ww2.mathworks.cn/matlabcentral/answers/1842223-curve-fitting-toolbox-can-return-bogus-results-for-2-term-exponential-functions-is-this-a-bug#comment_2444368

  • 链接

    此评论的直接链接

    https://ww2.mathworks.cn/matlabcentral/answers/1842223-curve-fitting-toolbox-can-return-bogus-results-for-2-term-exponential-functions-is-this-a-bug#comment_2444368

After re-reading my original question, I see that I could have made the issue more clear. I apologize for any confusion that sprang from that.

请先登录,再进行评论。

请先登录,再回答此问题。

另请参阅

类别

Signal ProcessingSignal Processing ToolboxTransforms, Correlation, and ModelingSignal ModelingLinear Predictive Coding

Help CenterFile Exchange 中查找有关 Linear Predictive Coding 的更多信息

标签

  • curve fitting toolbox
  • bug

产品

  • Curve Fitting Toolbox

版本

R2022a

Community Treasure Hunt

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

Start Hunting!

发生错误

由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。


Translated by Curve fitting toolbox can return bogus results for 2 term exponenti... (15)

Curve fitting toolbox can return bogus results for 2 term exponenti... (16)

选择网站

选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:

您也可以从以下列表中选择网站:

美洲

欧洲

亚太

联系您当地的办事处

Curve fitting toolbox can return bogus results for 2 term exponenti... (2024)

References

Top Articles
Pediatric Surgery: What to Expect
Top 10 Best Pillager Outpost Seeds to Use in Minecraft
Spasa Parish
The Machine 2023 Showtimes Near Habersham Hills Cinemas
Gilbert Public Schools Infinite Campus
Rentals for rent in Maastricht
159R Bus Schedule Pdf
11 Best Sites Like The Chive For Funny Pictures and Memes
Finger Lakes 1 Police Beat
Craigslist Pets Huntsville Alabama
Paulette Goddard | American Actress, Modern Times, Charlie Chaplin
Red Dead Redemption 2 Legendary Fish Locations Guide (“A Fisher of Fish”)
What's the Difference Between Halal and Haram Meat & Food?
Rugged Gentleman Barber Shop Martinsburg Wv
Jennifer Lenzini Leaving Ktiv
Havasu Lake residents boiling over water quality as EPA assumes oversight
Justified - Streams, Episodenguide und News zur Serie
Epay. Medstarhealth.org
Olde Kegg Bar & Grill Portage Menu
Half Inning In Which The Home Team Bats Crossword
Amazing Lash Bay Colony
Cato's Dozen Crossword
Cyclefish 2023
What’s Closing at Disney World? A Complete Guide
New from Simply So Good - Cherry Apricot Slab Pie
modelo julia - PLAYBOARD
Poker News Views Gossip
Abby's Caribbean Cafe
Joanna Gaines Reveals Who Bought the 'Fixer Upper' Lake House and Her Favorite Features of the Milestone Project
Pull And Pay Middletown Ohio
Navy Qrs Supervisor Answers
Trade Chart Dave Richard
Sweeterthanolives
How to get tink dissipator coil? - Dish De
Lincoln Financial Field Section 110
1084 Sadie Ridge Road, Clermont, FL 34715 - MLS# O6240905 - Coldwell Banker
Kino am Raschplatz - Vorschau
Classic Buttermilk Pancakes
Pick N Pull Near Me [Locator Map + Guide + FAQ]
'I want to be the oldest Miss Universe winner - at 31'
Gun Mayhem Watchdocumentaries
Ice Hockey Dboard
Infinity Pool Showtimes Near Maya Cinemas Bakersfield
Dermpathdiagnostics Com Pay Invoice
A look back at the history of the Capital One Tower
Alvin Isd Ixl
Maria Butina Bikini
Busted Newspaper Zapata Tx
Rubrankings Austin
2045 Union Ave SE, Grand Rapids, MI 49507 | Estately 🧡 | MLS# 24048395
Upgrading Fedora Linux to a New Release
Latest Posts
Article information

Author: Aracelis Kilback

Last Updated:

Views: 6724

Rating: 4.3 / 5 (44 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Aracelis Kilback

Birthday: 1994-11-22

Address: Apt. 895 30151 Green Plain, Lake Mariela, RI 98141

Phone: +5992291857476

Job: Legal Officer

Hobby: LARPing, role-playing games, Slacklining, Reading, Inline skating, Brazilian jiu-jitsu, Dance

Introduction: My name is Aracelis Kilback, I am a nice, gentle, agreeable, joyous, attractive, combative, gifted person who loves writing and wants to share my knowledge and understanding with you.