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

Invert interpolation integrals #282

Merged
merged 8 commits into from
Jul 6, 2024

Conversation

SouthEndMusic
Copy link
Member

@SouthEndMusic SouthEndMusic commented Jul 3, 2024

Fixes #277

Checklist

  • Appropriate tests were added
  • Any code changes were done in a way that does not break public API
  • All documentation related to code changes were updated
  • The new code follows the
    contributor guidelines, in particular the SciML Style Guide and
    COLPRAC.
  • Any new documentation only uses public API

@SouthEndMusic SouthEndMusic marked this pull request as draft July 3, 2024 21:00
@SouthEndMusic
Copy link
Member Author

Integral inversion POC:

using DataInterpolations
using Plots

t = collect(1:5)
u = [1.0, 1.0, 2.0, 4.0, 3.0]
A = LinearInterpolation(u, t)

ts = range(first(t), last(t), length = 100)
Is = DataInterpolations.integral.(Ref(A), ts)

A_intinv = DataInterpolations.invert_integral(A)
ts_ = A_intinv.(Is)

plot(ts, Is, label = "Original integral")
plot!(ts_, Is, label = "Integral inverse")

plot

It handles the edge case of the interpolation being constant perfectly 🥳

@SouthEndMusic
Copy link
Member Author

Speed boost when using cached integral values:

using DataInterpolations
using BenchmarkTools
using Random
Random.seed!(42)

N = 100
t = cumsum(rand(N))
ddu = rand(N)
du = rand(N)
u = rand(N)
A = QuinticHermiteSpline(ddu, du, u, t)

@btime DataInterpolations.integral(A, last(t))

# old: 1.320 μs (2 allocations: 32 bytes)
# new: 66.395 ns (2 allocations: 32 bytes)

@SouthEndMusic
Copy link
Member Author

@sathvikbhagavan how shall I document this new feature?

@ChrisRackauckas
Copy link
Member

Make a new docs page on it with a short tutorial and then the docstrings. And make a list of the methods which are compatible with it on there.

@SouthEndMusic
Copy link
Member Author

I'm wondering what to do with the docstrings of the LinearInterpolationIntInv and ConstantInterpolationIntInv structs. For the other interpolation methods this describes the public constructor, but I've set up my code so that users will probably always create these objects via DataInterpolations.invert_integral.

@SouthEndMusic SouthEndMusic marked this pull request as ready for review July 6, 2024 09:21
@ChrisRackauckas ChrisRackauckas merged commit 152bcbf into SciML:master Jul 6, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The inverted integral of LinearInterpolation
2 participants