csaps icon indicating copy to clipboard operation
csaps copied to clipboard

Issue with the smooth parameter.

Open lucassherbrook opened this issue 2 years ago • 3 comments

What the csaps function looks like without smooth parameter:

spline = csaps(x_points, y_points)
plt.plot(x, fit)
plt.scatter(x_points, y_points)
plt.show()

spline_plot_no_smoothing

What the csaps function looks like with any non-default smoothing parameter, even if small:

spline = csaps(x_points, y_points, smooth=.05)
plt.plot(x, fit)
plt.scatter(x_points, y_points)
plt.show()

spline_plot_with_smoothing

lucassherbrook avatar Jun 12 '23 00:06 lucassherbrook

Hello @lucassherbrook,

Could you provide a sample of your real data (x_points, y_points) for checking?

The result you showed on the second plot should be with smooth=0.0 (just linear regression). See in the doc: https://csaps.readthedocs.io/en/latest/tutorial.html#bounds-of-smoothing-parameter

espdev avatar Jun 12 '23 12:06 espdev

Here is the data I inputted to csaps: spline_data.csv

It outputs linear regression for me when using any smoothing parameter (including for those outside of the [0,1] range).

lucassherbrook avatar Jun 13 '23 05:06 lucassherbrook

The X-data nonuniformity on which the spline is built is such that the value of the smoothing parameter is in a very narrow range, close to 1.

There is the value of smooth that is automatically calculated: 0.999999999727055 You can change the value to 0.999998 and you will see that the spline fits your data correctly. 2023-06-13_19-47-56

Nevertheless, this is not very convenient. You can try to use smooth normalization to avoid the problems with X-data nonuniformity and scaling.

yi = csaps(x, y, xi, smooth=0.5, normalizedsmooth=True)

2023-06-13_19-51-52

In this case the effect from the smooth parameter will be almost linear in the range from 0 to 1.

espdev avatar Jun 13 '23 18:06 espdev