Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: interpolate.make_lsq_spline: add boundary conditions #20747

Open
ev-br opened this issue May 19, 2024 · 2 comments
Open

ENH: interpolate.make_lsq_spline: add boundary conditions #20747

ev-br opened this issue May 19, 2024 · 2 comments
Labels
enhancement A new feature or improvement scipy.interpolate

Comments

@ev-br
Copy link
Member

ev-br commented May 19, 2024

Is your feature request related to a problem? Please describe.

Add an option to specify boundary conditions to make_lsq_spline. A first useful step would be to allow specifying the values at the boundaries, see https://stackoverflow.com/questions/78482220/fixing-boundary-values-on-a-spline.

The SO answer has a prototype implementation and a link to the math description. Basically, the design matrix needs a small tweak to account for the targer values at x[0] and x[-1].

Describe the solution you'd like.

Thinking out loud about the UI: The first thought is it should probably mirror that of make_interp_spline:

>>> l, r = [(0, y0)], [(0, y1)]
make_lsq_spline(x, y, bc_type=(l,r))

would fix the "zeroth derivative" (i.e., the function value) at x[0] to be y0 and the value at x[-1] to be y1. Higher derivatives should raise NotImplemented until, well, implemented.
This is a somewhat awkward, as it's designed for make_interp_spline which needs way more flexibility.

We can instead opt for something simpler, like bc_type=(y0, y1). If/when there's a request for higher derivatives, we'll need to be able to tell a single value y0 (which can be an array if y.ndim > 1) from a sequence of pairs (order, value). Which is not nice.

So probably the pragmatic thing is to add a separate keyword, clamp_values=(y0, y1) or some such.

Describe alternatives you've considered.

The SO question has an implementation in the userspace. It has several issues: 1) it uses full matrices (could use banded linalg), 2) it constructs and solves the normal equations to solve the LSQ problem (should preferably use QR or SVD), and 3) getting the spline basis is a little awkward.

None of these is a blocker, so all in all this is medium-prio enhancement request.

Additional context (e.g. screenshots, GIFs)

No response

@ev-br ev-br added enhancement A new feature or improvement scipy.interpolate labels May 19, 2024
@lucascolley lucascolley changed the title ENH: add boundary conditions to make_lsq_spline ENH: interpolate.make_lsq_spline: add boundary conditions May 23, 2024
@Searchingdays
Copy link

Doesn't the knots satisfying the Schoenberg Whitney conditions in make_lsq_spline take care of the boundary conditions ? So a separate bc_type is not needed perhaps?

@ev-br
Copy link
Member Author

ev-br commented May 28, 2024

No. S-W condition ensures that the LSQ problem is well-posed (that the design matrix has full rank, basically).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A new feature or improvement scipy.interpolate
Projects
None yet
Development

No branches or pull requests

2 participants