Bug 455808

Summary: xyFitCurve not showing expected best-fit line to an upside down U shape data when using 2nd degree polynomial fit.
Product: [Applications] LabPlot2 Reporter: Larry <ljbeach>
Component: generalAssignee: Alexander Semke <alexander.semke>
Status: RESOLVED INTENTIONAL    
Severity: normal    
Priority: NOR    
Version First Reported In: 2.9.0   
Target Milestone: ---   
Platform: Microsoft Windows   
OS: Microsoft Windows   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:
Attachments: Shows unexpected best-fit curve
attachment-3689-0.html
attachment-4614-0.html
attachment-4829-0.html

Description Larry 2022-06-22 20:09:55 UTC
Created attachment 150065 [details]
Shows unexpected best-fit curve

SUMMARY
***
Unable to produce a best-fit curve to a negative polynomial shape data (upside down U shape).
***
Data:
50, 10.9
40, 12.4
30, 18.9
20, 25.5
10, 27.4
0, 28.8
-10, 27.9
-20, 23.4
-30, 21.6
-40, 16.8
-50, 12.9

STEPS TO REPRODUCE
1. File>New>Spreadsheet
2. Enter data
3. Select columns
4. Right-Click, Analyze and Plot Data
5. Change xy-curve to show points instead of line
6. Change xy-fitCurve to Basic Functions; Polynomial; Degree 2

OBSERVED RESULT


EXPECTED RESULT


SOFTWARE/OS VERSIONS
Windows: 
macOS: 
Linux/KDE Plasma: 
(available in About System)
KDE Plasma Version: 
KDE Frameworks Version: 
Qt Version: 

ADDITIONAL INFORMATION
Comment 1 Alexander Semke 2022-06-22 20:22:40 UTC
(In reply to Larry from comment #0)
> Created attachment 150065 [details]
> Shows unexpected best-fit curve
> 
> SUMMARY
> ***
> Unable to produce a best-fit curve to a negative polynomial shape data
> (upside down U shape).
> ***
> Data:
> 50, 10.9
> 40, 12.4
> 30, 18.9
> 20, 25.5
> 10, 27.4
> 0, 28.8
> -10, 27.9
> -20, 23.4
> -30, 21.6
> -40, 16.8
> -50, 12.9

The initial start values for the parameters seem to block the algorithm to converge to the proper solution. Since you have this upside-down parabola like data, just set the start value for the second parameter, i.e. for c1 to -1 and try to re-fit again. You get the proper fit to your data with it.

Does it also work for you with c1 = -1?
Comment 2 Larry 2022-06-22 20:27:53 UTC
Created attachment 150068 [details]
attachment-3689-0.html

When I change C1 to -1, I do get a negative best fit curve, but it fits to -2500 along the Y axis where the actual data point is 12.9.














---- On Wed, 22 Jun 2022 13:22:40 -0700 Alexander Semke <bugzilla_noreply@kde.org> wrote ---



https://bugs.kde.org/show_bug.cgi?id=455808 
 
--- Comment #1 from Alexander Semke <mailto:alexander.semke@web.de> --- 
(In reply to Larry from comment #0) 
> Created attachment 150065 [details] 
> Shows unexpected best-fit curve 
> 
> SUMMARY 
> *** 
> Unable to produce a best-fit curve to a negative polynomial shape data 
> (upside down U shape). 
> *** 
> Data: 
> 50, 10.9 
> 40, 12.4 
> 30, 18.9 
> 20, 25.5 
> 10, 27.4 
> 0, 28.8 
> -10, 27.9 
> -20, 23.4 
> -30, 21.6 
> -40, 16.8 
> -50, 12.9 
 
The initial start values for the parameters seem to block the algorithm to 
converge to the proper solution. Since you have this upside-down parabola like 
data, just set the start value for the second parameter, i.e. for c1 to -1 and 
try to re-fit again. You get the proper fit to your data with it. 
 
Does it also work for you with c1 = -1?
Comment 3 Larry 2022-06-22 20:34:25 UTC
Created attachment 150069 [details]
attachment-4614-0.html

Sorry, minor correct to last e-mail:  if I change C2 to -1 I get an upside down parabola for the best fit, but the values are in the -2500 range instead of 12 and do not fit my data.



Changing C1 to -1 changes the best fit curve very little.



Larry











---- On Wed, 22 Jun 2022 13:22:40 -0700 Alexander Semke <bugzilla_noreply@kde.org> wrote ---



https://bugs.kde.org/show_bug.cgi?id=455808 
 
--- Comment #1 from Alexander Semke <mailto:alexander.semke@web.de> --- 
(In reply to Larry from comment #0) 
> Created attachment 150065 [details] 
> Shows unexpected best-fit curve 
> 
> SUMMARY 
> *** 
> Unable to produce a best-fit curve to a negative polynomial shape data 
> (upside down U shape). 
> *** 
> Data: 
> 50, 10.9 
> 40, 12.4 
> 30, 18.9 
> 20, 25.5 
> 10, 27.4 
> 0, 28.8 
> -10, 27.9 
> -20, 23.4 
> -30, 21.6 
> -40, 16.8 
> -50, 12.9 
 
The initial start values for the parameters seem to block the algorithm to 
converge to the proper solution. Since you have this upside-down parabola like 
data, just set the start value for the second parameter, i.e. for c1 to -1 and 
try to re-fit again. You get the proper fit to your data with it. 
 
Does it also work for you with c1 = -1?
Comment 4 Larry 2022-06-22 20:36:56 UTC
Created attachment 150070 [details]
attachment-4829-0.html

Got it!



I didn't realize I had to press the "Fit" button just below the Parameters.



Larry













---- On Wed, 22 Jun 2022 13:22:40 -0700 Alexander Semke <bugzilla_noreply@kde.org> wrote ---



https://bugs.kde.org/show_bug.cgi?id=455808 
 
--- Comment #1 from Alexander Semke <mailto:alexander.semke@web.de> --- 
(In reply to Larry from comment #0) 
> Created attachment 150065 [details] 
> Shows unexpected best-fit curve 
> 
> SUMMARY 
> *** 
> Unable to produce a best-fit curve to a negative polynomial shape data 
> (upside down U shape). 
> *** 
> Data: 
> 50, 10.9 
> 40, 12.4 
> 30, 18.9 
> 20, 25.5 
> 10, 27.4 
> 0, 28.8 
> -10, 27.9 
> -20, 23.4 
> -30, 21.6 
> -40, 16.8 
> -50, 12.9 
 
The initial start values for the parameters seem to block the algorithm to 
converge to the proper solution. Since you have this upside-down parabola like 
data, just set the start value for the second parameter, i.e. for c1 to -1 and 
try to re-fit again. You get the proper fit to your data with it. 
 
Does it also work for you with c1 = -1?
Comment 5 Alexander Semke 2022-06-22 20:44:44 UTC
(In reply to Larry from comment #4)
> Got it!
> I didn't realize I had to press the "Fit" button just below the Parameters.

Yes, you need to re-fit. Without doing it you just see a "preview" of the result produced by some auto-detection logic which is not working well with this data for some reasons. We'll check and improve it. But you should get the correct results by clicking on the Fit button, even with the start value 1 for c_0, c_1 and c2.