csaps icon indicating copy to clipboard operation
csaps copied to clipboard

questions about AutoSmoothingResult

Open Bhare8972 opened this issue 1 year ago • 4 comments

To whom it may concern,

Sorry I'm using a ticket to ask a question, but I couldn't see any other way to contact y'all.

This package looks VERY interesting to me. I've been looking for a python implementation of DeBoor smoothing splines, and was afraid I'd have to implement it myself. However, I have a few questions.

First, how does AutoSmoothingResult work? What criterion does it use to find a smoothing parameter? (may I suggest the answer be put in the documentation?)

Second, scipy univariate smoothing splines have an option where essentially you set the desired chi-squared fit and the algorithm automatically adjusts the number of knots until that condition is met. Does csaps have a similar option? (except instead of adjusting knots, the smoothing paramter is adjusted ofc), that is, something like the second equation under "de Boors approach" on the page https://en.wikipedia.org/wiki/Smoothing_spline.

Thanks!

Bhare8972 avatar Jul 28 '22 08:07 Bhare8972

Hi,

The smoothing parameter is computed just like in MATLAB implementation. See: https://csaps.readthedocs.io/en/latest/formulation.html#definition

The calculation of the smoothing spline requires the solution of a linear system whose coefficient matrix has the form , with the matrices and depending on the data sites . The automatically computed smoothing parameter makes p*trace(A) equal (1 - p)*trace(B).

https://github.com/espdev/csaps/blob/b7f7cdc59e128124aac5fbdee392eea6c99936a8/csaps/_sspumv.py#L233-L244

"de Boors approach" and iterative adjusting knots algorithm are not used.

Also we can use the smoothing parameter normalization for adjusting to X scale: https://github.com/espdev/csaps/blob/b7f7cdc59e128124aac5fbdee392eea6c99936a8/csaps/_sspumv.py#L247-L261

If you want, you can suggest PR with an another implementation of auto-smoothing algorithm, and we will add it to the package as an option.

espdev avatar Jul 29 '22 09:07 espdev

Thank you for the reply.

Is there any material on how to get some intuitive understanding of what autosmooth is doing? Perhaps a research paper citation?

Someday I'll try to implement the smoothing option, and make a PR once I do. But it will be awhile.

Bhare8972 avatar Jul 29 '22 17:07 Bhare8972

Only the following description from Matlab documentation without any links and citations, unfortunately.

2022-07-30_10-23-21

Matlab implementation also has roughness weights through smoothing parameter vector. Currently, this is not implemented in csaps Python package.

espdev avatar Jul 30 '22 09:07 espdev

Thank you for your help.

Am thinking about how to implement this feature I want. It requires explicitly calculating the error measure.

Is there an easy way, inside the method _make_spline of the CubicSmoothingSpline class (at https://github.com/espdev/csaps/blob/b7f7cdc59e128124aac5fbdee392eea6c99936a8/csaps/_sspumv.py#L264)

to calculate the error measure? (I can't tell as I don't know what all the variables in _make_spline measure) Or does the spline need to be evaluated at x-locations, after creation, to calculate the error measure?

Bhare8972 avatar Aug 01 '22 14:08 Bhare8972