-
Notifications
You must be signed in to change notification settings - Fork 109
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
Feature wishlist #5
Comments
Looks good! One point I'm not sure about is why you separate boundary conditions from extrapolation behavior; it basically seems like one follows from the other. |
One more topic of importance: efficient multi-valued interpolation (e.g., timholy/Grid.jl#44). Obviously this will just "drop out" for people who use Arrays of My current thinking is that this is a case where it's best to wait for Julia to support fixed-size arrays efficiently, and not try to hack around this in Interpolations.jl. In the meantime, people who need that can use Grid. As a close facsimile, we could conceivably support arrays of tuples. |
Multi-valued interpolation is important indeed, but I'm more and more leaning toward supporting this simply by duck typing, and forcing the user to use other tools to get their data in an appropriate shape. As we've said previously somewhere, we currently only demand that the data type supports multiplication with floats and addition (i.e. are basically vectors in some vector space...), and I would argue that reshaping data that is in some other form (i.e. an image in an Re: bc/extrap separation, there are basically two reasons: one is that they are basically independent in the implementation, so it seems like a bad idea to couple them more than necessary in the API, and the other is that we have a couple of extrapolation behaviors that don't map nicely to boundary conditions (e.g. |
that's basically what I'm saying, too. (Your version is clearer, though.) Re the boundary conditions: got it. Carry on 😄. |
The wishlist is promising ! |
Typical boundary conditions used for cubic splines are:
|
@TheBB Thanks for the input! I think the natural boundary conditions will be identical to a linear BC, since the way to implement the latter is also to set the second derivative to zero at the boundary. I'll update the wishlist with the other two. |
I have some of a theorical/implementation question: |
@kzapfe PyCall/PyPlot are of a very specific type of Julia packages - they're both wrappers for code in other languages that have had much more time than Julia to evolve and mature. Thus, comparison to pure Julia packages like Interpolations.jl isn't quite "fair" to either type of package. Since PyPlot is built specifically for showing things on-screen, it's maybe not so surprising that it focuses its efforts on 2D. Did you have any other packages with the same limitations in mind? It's also a much larger problem to write general code that works in any number of dimensions than to write for just one case, so if you only need 1D and 2D there's no reason to build something more general. That said, you can probably find a lot of good interpolation code in various languages that already has been/would be easy enough to wrap in Julia and that does what you need. My ambition with this library is to, eventually, eliminate the need for calling out to other languages, at least if you don't need something very specific - but part of the reason for building it is to have an excuse to practice Julia programming :) |
This looks great - thanks for all your work! I'm looking at a task that would require barycentric Lagrange interpolation, which might fit here. Is anyone already working on this? |
@abahm Not that I know of. If you feel up to it, a PR is always welcome :) The API should probably be something like that for gridded interpolation, e.g. |
I'm going to try to get my hands dirty with cubic splines! I might reach out for help if I get stuck, hope you don't mind. |
Also, as I go would you be OK with me trying my best to add docstrings to currently undocumented functions? That would help me learn what everything does. |
@spencerlyon2 Great! I'm really excited about this project :) Docstrings are great (we have already discussed moving most of the documentation into them, and away from the Readme, see #46) - but you might also find the documentation in My main concerns with this library is that the API stays consistent, and keeps leaving room for incorporating new interpolation schemes, and that we ensure that the composability that we have between the current implementations of b-splines, extrapolation and scaling, is kept for other schemes as well. Together with Tim's focus on squeezing out every single ounce of performance I really think we've found a sweet spot :) I have the ambition of helping you shape your contributions to fit well into this framework. I'm telling you this to make it clear from the start that I do value your contributions - and then I hope you'll have some patience if I'm nit-picky sometimes in my code review... ;) Feel free to file issues with questions whenever you need it - we'll do our best to answer them promptly. |
Yeah, this sounds fantastic. Do shout for help if you find any of the metaprogramming-heavy stuff confusing. |
Is there a way of performing cubic spline interpolation on a non-uniform grid with this package? If no, is there a specific reason? It seems to me that the generalization from uniform grid to a non-uniform should be independent of the uniform interpolation scheme. My workaround so far looks like function itp_nonuniform(val::Real, itp_uniform, x, y)
i = 2
while val > x[i]
i += 1
end
λ = (val - x[i-1])/(x[i] - x[i-1])
itp_uniform[i - 1 + λ]
end
itp_nonuniform(vals::AbstractVector, itp_uniform, x, y) =
broadcast(val -> itp_nonuniform(val, itp_uniform, x, y), vals) Some illustration using Interpolations, Plots
N = 40
xmax = 2*round(π, 4)
x = xmax * [0; sort(rand(N-2)); 1]
y = sin.(x)
itp_uniform = interpolate(y, BSpline(Cubic(Natural())), OnGrid())
scatter(x, y, label="true")
vals = linspace(0, xmax, 5*N)
plot!(vals, itp_nonuniform(vals, itp_uniform, x, y), label="interp") EDIT: I probably should've read #131 before my comment. My workaround is most likely doing something different than gridded cubic spline interpolation. |
One thing that would be nice to have is also sinc interpolation. |
i wish this package include smooth splines too. recently i tried to convert some R code to Julia which uses R smooth.spline function. The Dierckx.jl can do smooth spline, but the only parameters is a smoothness. R version accept degree of freedoms which is very useful to control not only smoothness but also the complexity of the spline. right now i am using RCall, but hope to replace the hack some day. another thought is why not use callable overload to sugar coat the interpolation. Dierckx.jl makes the splines callable, so instead of |
I'll second @babaq's wish/need for a smoothing functionality. I will admit though, that it is arguable if smoothing an interpolating object is within the scope of what an interpolating library does. The main objection I can think of is that once you smooth the interpolation it isn't interpolating between the data points any more. The fact remains though that people come looking for some smoothing functionality when interpolating. As the main interpolation package for Julia, I think there should be some information about smoothing the interpolation/data:
|
@gerlero Should monotonic, i.e. https://github.com/gerlero/PCHIPInterpolation.jl be on the list here? I used PCHIP from SciPy at the time when I needed it (and extrapolation) and it wasn't then available in Julia (when porting from MATLAB). Maybe it makes sense to add that package as a dependency (I believe its BSD license may be compatible with MIT here), not to reimplement. If not add it as a forth alternative in the README? |
No. Please create a new issue. |
I rather just added a doc to README #493, at least for now. Did you for sure mean to close since 2 of the tasks not yet completed? |
Necroposting on an 8-year old issue where most of the participants have moved on is simply not helpful. For the current maintainers it is also very hard to find and track. |
Now that basic functionality is in place, we need to extend what we have with more cases, to make the library feature complete. That's a good case for a wishlist =) This issue is intended to keep track of overall progress toward feature parity with (interpolation parts of) Grid.jl - actual implementation details can be discussed in separate issues.
Boundary condtions (assuming a grid on
1:n
)Flat
, i.e.f'(x=1) = f'(x=n) = 0
(WIP features (so far: Flat BC, Constant extrap) #8)Line
(orNatural
), i.e.f''(x=1) = f''(x=n) = 0
(More boundary conditions for quadratic B-splines #9)Tangent
, i.e. with specified derivatives at the edges (Flat
is essentiallyTangent(0,0)
)Reflect
, i.e. all continuous derivatives are 0 at the edge, to preserve continuity properties when extrapolating (Added in Reflecting BC for quadratic itp #20)Periodic
, i.e. function value and all derivatives are equal at both edges; withOnGrid
, the data should include both cell boundaries (andA[1]==A[end]
), while withOnCell
this assumption is not necessary (but ratherA[-.5] == A[end+.5]
) (More boundary conditions for quadratic B-splines #9)Free
, i.e. with extra continuous derivatives close to the edges, to close the system. (For e.g. cubic splines, which have continuous second derivatives, the third derivatives are also continuous at the second-to-last boundaries). (More boundary conditions for quadratic B-splines #9)Extrapolation behaviors
Constant
, i.e. return the value at the closest data point (WIP features (so far: Flat BC, Constant extrap) #8)Linear
(Linear extrapolation #23)Quadratic
etc, valid up to the same degree as the interpolation. When the same degree, just continue the outermost polynomial; when lower degree, construct an extrapolation polynomial with as many continuous derivatives as necessary for a smooth transition. For example, linear extrapolation of a quadratic interpolation object, would have continuous value and first derivative (which conveniently specifies the extrapolation uniquely...).Periodic
, i.e.f(x + T) = f(x)
for a function with periodT
(More boundary conditions for quadratic B-splines #9)Reflec
, i.e.f(end - 1 + T/3) = f(end - T/3 + 1)
(More boundary conditions for quadratic B-splines #9)Interpolation degrees
Other functionality
gradient(itp::Quadratic, x)
orhessian(itp::Cubic, x)
. (Gradient fixed in Gradient evaluation #18, higher orders will be added when higher order interpolations are added...)itp[1:.1:10]
) (Vector-valued evaluation #24, Restrict scalar indexing to Numbers #54, Improve testing #55)CoordInterpGrid
inGrid.jl
solves) (Something equivalent to CoordInterpGrid #25, RFC: Scaling of interpolation objects (fixes #25) #47)The text was updated successfully, but these errors were encountered: