Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into stable_quadratic_…
Browse files Browse the repository at this point in the history
…spline
  • Loading branch information
SouthEndMusic committed Nov 12, 2024
1 parent 8498a29 commit 2cca631
Show file tree
Hide file tree
Showing 21 changed files with 724 additions and 149 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CompatHelper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
CompatHelper:
runs-on: ubuntu-latest
steps:
- uses: julia-actions/setup-julia@780022b48dfc0c2c6b94cfee6a9284850107d037
- uses: julia-actions/setup-julia@9b79636afcfb07ab02c256cede01fe2db6ba808c
with:
version: 1.3
- name: Pkg.add("CompatHelper")
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/Downgrade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ jobs:
group:
- Core
version:
- '1'
- '1.10'
os:
- ubuntu-latest
- macos-latest
- windows-latest
steps:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v2.3.0
- uses: julia-actions/setup-julia@v2.6.0
with:
version: ${{ matrix.version }}
- uses: julia-actions/julia-downgrade-compat@v1
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/Invalidations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ jobs:
evaluate-invalidations:
name: "Evaluate Invalidations"
uses: "SciML/.github/.github/workflows/invalidations.yml@v1"
with:
julia-version: "1.10"
2 changes: 1 addition & 1 deletion .github/workflows/TagBot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
if: github.event_name == 'workflow_dispatch' || github.actor == 'JuliaTagBot'
runs-on: ubuntu-latest
steps:
- uses: JuliaRegistries/TagBot@aa5545ecce2ae3b2cd7d3a8a0a286ec6bf25838f
- uses: JuliaRegistries/TagBot@29c35fccdd29270e3560ede0c1b77b4b6e12abce
with:
token: ${{ secrets.GITHUB_TOKEN }}
# Edit the following line to reflect the actual name of the GitHub Secret containing your private key
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/Tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,16 @@ jobs:
strategy:
fail-fast: false
matrix:
version:
- "1"
- "lts"
- "pre"
os:
- "ubuntu-latest"
- "macos-latest"
- "windows-latest"
uses: "SciML/.github/.github/workflows/tests.yml@v1"
with:
julia-version: "${{ matrix.version }}"
os: "${{ matrix.os }}"
secrets: "inherit"
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "DataInterpolations"
uuid = "82cc6244-b520-54b8-b5a6-8a565e85f1d0"
version = "6.1.0"
version = "6.5.2"

[deps]
FindFirstFunctions = "64ca27bc-2ba2-4a57-88aa-44e436879224"
Expand Down Expand Up @@ -39,7 +39,7 @@ Reexport = "1"
RegularizationTools = "0.6"
SafeTestsets = "0.1"
StableRNGs = "1"
Symbolics = "5.29"
Symbolics = "5.29, 6"
Test = "1"
Zygote = "0.6.70"
julia = "1.10"
Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

[![ColPrac: Contributor's Guide on Collaborative Practices for Community Packages](https://img.shields.io/badge/ColPrac-Contributor%27s%20Guide-blueviolet)](https://github.com/SciML/ColPrac)
[![SciML Code Style](https://img.shields.io/static/v1?label=code%20style&message=SciML&color=9558b2&labelColor=389826)](https://github.com/SciML/SciMLStyle)
[![DOI](https://joss.theoj.org/papers/10.21105/joss.06917/status.svg)](https://doi.org/10.21105/joss.06917)

DataInterpolations.jl is a library for performing interpolations of one-dimensional data. By
"data interpolations" we mean techniques for interpolating possibly noisy data, and thus
Expand Down Expand Up @@ -93,3 +94,22 @@ The series types defined are:
- `:quintic_hermite_spline`

By and large, these accept the same keywords as their function counterparts.

## Citing

If you use this software in your work, please cite:

```bib
@article{Bhagavan2024,
doi = {10.21105/joss.06917},
url = {https://doi.org/10.21105/joss.06917},
year = {2024},
publisher = {The Open Journal},
volume = {9},
number = {101},
pages = {6917},
author = {Sathvik Bhagavan and Bart de Koning and Shubham Maddhashiya and Christopher Rackauckas},
title = {DataInterpolations.jl: Fast Interpolations of 1D data},
journal = {Journal of Open Source Software}
}
```
2 changes: 1 addition & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ OrdinaryDiffEq = "6"
Plots = "1"
RegularizationTools = "0.6"
StableRNGs = "1"
Symbolics = "5.29"
Symbolics = "5.29, 6.0"
19 changes: 19 additions & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,25 @@ The series types defined are:

By and large, these accept the same keywords as their function counterparts.

## Citing

If you use this software in your work, please cite:

```bib
@article{Bhagavan2024,
doi = {10.21105/joss.06917},
url = {https://doi.org/10.21105/joss.06917},
year = {2024},
publisher = {The Open Journal},
volume = {9},
number = {101},
pages = {6917},
author = {Sathvik Bhagavan and Bart de Koning and Shubham Maddhashiya and Christopher Rackauckas},
title = {DataInterpolations.jl: Fast Interpolations of 1D data},
journal = {Journal of Open Source Software}
}
```

## Contributing

- Please refer to the
Expand Down
45 changes: 35 additions & 10 deletions ext/DataInterpolationsChainRulesCoreExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,27 @@ if isdefined(Base, :get_extension)
LinearInterpolation, QuadraticInterpolation,
LagrangeInterpolation, AkimaInterpolation,
BSplineInterpolation, BSplineApprox, get_idx, get_parameters,
_quad_interp_indices
_quad_interp_indices, munge_data
using ChainRulesCore
else
using ..DataInterpolations: _interpolate, derivative, AbstractInterpolation,
LinearInterpolation, QuadraticInterpolation,
LagrangeInterpolation, AkimaInterpolation,
BSplineInterpolation, BSplineApprox, get_parameters,
_quad_interp_indices
_quad_interp_indices, munge_data
using ..ChainRulesCore
end

function ChainRulesCore.rrule(::typeof(munge_data), u, t)
u_out, t_out = munge_data(u, t)

# For now modifications by munge_data not supported
@assert (u == u_out && t == t_out)

munge_data_pullback = Δ -> (NoTangent(), Δ[1], Δ[2])
(u_out, t_out), munge_data_pullback
end

function ChainRulesCore.rrule(
::Type{LinearInterpolation}, u, t, I, p, extrapolate, cache_parameters)
A = LinearInterpolation(u, t, I, p, extrapolate, cache_parameters)
Expand Down Expand Up @@ -51,26 +61,37 @@ function ChainRulesCore.rrule(
end

function u_tangent(A::LinearInterpolation, t, Δ)
out = zero(A.u)
out = zero.(A.u)
idx = get_idx(A, t, A.iguesser)
t_factor = (t - A.t[idx]) / (A.t[idx + 1] - A.t[idx])
out[idx] = Δ * (one(eltype(out)) - t_factor)
out[idx + 1] = Δ * t_factor
if eltype(out) <: Number
out[idx] = Δ * (one(eltype(out)) - t_factor)
out[idx + 1] = Δ * t_factor
else
@. out[idx] = Δ * (true - t_factor)
@. out[idx + 1] = Δ * t_factor
end
out
end

function u_tangent(A::QuadraticInterpolation, t, Δ)
out = zero(A.u)
out = zero.(A.u)
i₀, i₁, i₂ = _quad_interp_indices(A, t, A.iguesser)
t₀ = A.t[i₀]
t₁ = A.t[i₁]
t₂ = A.t[i₂]
Δt₀ = t₁ - t₀
Δt₁ = t₂ - t₁
Δt₂ = t₂ - t₀
out[i₀] = Δ * (t - A.t[i₁]) * (t - A.t[i₂]) / (Δt₀ * Δt₂)
out[i₁] = -Δ * (t - A.t[i₀]) * (t - A.t[i₂]) / (Δt₀ * Δt₁)
out[i₂] = Δ * (t - A.t[i₀]) * (t - A.t[i₁]) / (Δt₂ * Δt₁)
if eltype(out) <: Number
out[i₀] = Δ * (t - A.t[i₁]) * (t - A.t[i₂]) / (Δt₀ * Δt₂)
out[i₁] = -Δ * (t - A.t[i₀]) * (t - A.t[i₂]) / (Δt₀ * Δt₁)
out[i₂] = Δ * (t - A.t[i₀]) * (t - A.t[i₁]) / (Δt₂ * Δt₁)
else
@. out[i₀] = Δ * (t - A.t[i₁]) * (t - A.t[i₂]) / (Δt₀ * Δt₂)
@. out[i₁] = -Δ * (t - A.t[i₀]) * (t - A.t[i₂]) / (Δt₀ * Δt₁)
@. out[i₂] = Δ * (t - A.t[i₀]) * (t - A.t[i₁]) / (Δt₂ * Δt₁)
end
out
end

Expand All @@ -90,7 +111,7 @@ function ChainRulesCore.rrule(::typeof(_interpolate),
t::Number)
deriv = derivative(A, t)
function interpolate_pullback(Δ)
(NoTangent(), Tangent{typeof(A)}(; u = u_tangent(A, t, Δ)), deriv * Δ)
(NoTangent(), Tangent{typeof(A)}(; u = u_tangent(A, t, Δ)), sum(deriv .* Δ))
end
return _interpolate(A, t), interpolate_pullback
end
Expand All @@ -100,4 +121,8 @@ function ChainRulesCore.frule((_, _, Δt), ::typeof(_interpolate), A::AbstractIn
return _interpolate(A, t), derivative(A, t) * Δt
end

function ChainRulesCore.frule((_, Δt), A::AbstractInterpolation, t::Number)
return A(t), derivative(A, t) * Δt
end

end # module
28 changes: 16 additions & 12 deletions joss/paper.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,35 @@ authors:
orcid: 0000-0003-0785-3586
corresponding: true
affiliation: 1
- name: Christopher Rackauckas
orcid: 0000-0001-5850-0663
affiliation: "1, 2, 3"
- name: Shubham Maddhashiya
affiliation: 3
- name: Bart de Koning
orcid: 0009-0005-6134-6608
affiliation: 4
affiliation: 2
- name: Shubham Maddhashiya
affiliation: 3
- name: Christopher Rackauckas
orcid: 0000-0001-5850-0663
affiliation: "1, 3, 4"
affiliations:
- name: JuliaHub
index: 1
- name: Massachusetts Institute of Technology
- name: Deltares
index: 2
- name: Pumas-AI
index: 3
- name: Deltares
- name: Massachusetts Institute of Technology
index: 4
date: 6 June 2024
bibliography: paper.bib
---

# Summary

Interpolations are used to estimate values between known data points using an approximate continuous function.DataInterpolations.jl is a Julia [@Bezanson2017] package containing 1D implementations of some of the most commonly used interpolation functions. These include:
Interpolations are used to estimate values between known data points using an approximate continuous function. DataInterpolations.jl is a Julia [@Bezanson2017] package containing 1D implementations of some of the most commonly used interpolation functions. These include:

- Constant Interpolation
- Linear Interpolation
- Quadratic Interpolation
- Lagrange Interpolation [@lagrange]
- Lagrange Interpolation [@lagrange1898lectures]
- Quadratic Splines
- Cubic Splines [@Schoenberg1988]
- Akima Splines [@10.1145/321607.321609]
Expand All @@ -46,15 +46,19 @@ Interpolations are used to estimate values between known data points using an ap
- B-Splines [@Curry1988] [@DEBOOR197250]
- Regression based B-Splines

and a continually growing list. Along with these, the package also has methods to fit parameterized curves with the data points and Tikhonov regularization [@Tikhonov1943OnTS] [@amt-14-7909-2021] for obtaining smooth curves. The package also provides functionality to compute integrals and derivatives upto second order for those interpolations methods. It is also automatic differentiation friendly. It can also be used symbolically with Symbolics.jl [@gowda2021high] and plugged into models defined using ModelingToolkit.jl [@ma2021modelingtoolkit].
and a continually growing list. Along with these, the package also has methods to fit parameterized curves with the data points and Tikhonov regularization [@Tikhonov1943OnTS] [@amt-14-7909-2021] for obtaining smooth curves. The package also provides functionality to compute integrals and derivatives upto second order for those interpolations methods. It is also automatic differentiation friendly. It can also be used symbolically with Symbolics.jl [@10.1145/3511528.3511535] and plugged into models defined using ModelingToolkit.jl [@ma2021modelingtoolkit].

# Statement of need

Interpolations are a very important component of many modeling workflows. Often, sampled or measured inputs need to be transformed into continuous functions or smooth curves for simulation purposes. In many scientific machine learning workflows, interpolating data is essential to learn continuous models. DataInterpolations.jl can be used for facilitating these types of workflows. Several interpolation packages already exist in Julia, such as [Interpolations.jl](https://juliamath.github.io/Interpolations.jl/stable/), which primarily specializes in B-Splines and uniformly spaced data with some support for irregularly spaced data. In contrast, DataInterpolations.jl does not assume any specific structure in the data, offering greater flexibility for diverse datasets. [Interpolations.jl](https://juliamath.github.io/Interpolations.jl/stable/) also doesn't offer methods like Quadratic Interpolation, Lagrange Interpolation, Hermite Splines etc. [BasicInterpolators.jl](https://github.com/markmbaum/BasicInterpolators.jl) is more similar to DataInterpolations.jl, although it doesn't offer methods like B-Splines. Rest of the interpolation packages focus on particular methods like [BSplineKit.jl](https://github.com/jipolanco/BSplineKit.jl) for B-Splines, [FastChebInterp.jl](https://github.com/JuliaMath/FastChebInterp.jl) for Chebyshev interpolation, [PCHIPInterpolation](https://github.com/gerlero/PCHIPInterpolation.jl) for PCHIP interpolation etc. Additionally, DataInterpolations.jl includes many novel techniques for accelerating the interpolation searches with specialized caching, quasi-linear guessing, and more to improve the performance algorithmically, beyond the simple computational optimizations. In summary, DataInterpolations.jl is more generic from other packages and offers many fast interpolation methods for arbitrarily spaced 1D data, all within a consistent and simple interface.

# Example

The following tutorials in the documentation [1](https://docs.sciml.ai/DataInterpolations/stable/methods/) provides how to define each of the interpolation methods and compute the value at any point. [2](https://docs.sciml.ai/DataInterpolations/stable/interface/) provides explanation for using the interface and interpolated objects for evaluating at any point, computing the derivative at any point and computing the integral between any two points. [3](https://docs.sciml.ai/DataInterpolations/stable/symbolics/) provides how to use interpolation objects with Symbolics.jl and ModelingToolkit.jl.
The following tutorials are provided in the documentation:

- [Tutorial 1](https://docs.sciml.ai/DataInterpolations/stable/methods/) provides how to define each of the interpolation methods and compute the value at any point.
- [Tutorial 2](https://docs.sciml.ai/DataInterpolations/stable/interface/) provides explanation for using the interface and interpolated objects for evaluating at any point, computing the derivative at any point and computing the integral between any two points.
- [Tutorial 3](https://docs.sciml.ai/DataInterpolations/stable/symbolics/) provides how to use interpolation objects with Symbolics.jl and ModelingToolkit.jl.

A simple demonstration here:

Expand Down
17 changes: 10 additions & 7 deletions src/DataInterpolations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module DataInterpolations

### Interface Functionality

abstract type AbstractInterpolation{T} end
abstract type AbstractInterpolation{T, N} end

using LinearAlgebra, RecipesBase
using PrettyTables
Expand Down Expand Up @@ -92,8 +92,8 @@ export LinearInterpolation, QuadraticInterpolation, LagrangeInterpolation,

# added for RegularizationSmooth, JJS 11/27/21
### Regularization data smoothing and interpolation
struct RegularizationSmooth{uType, tType, T, T2, ITP <: AbstractInterpolation{T}} <:
AbstractInterpolation{T}
struct RegularizationSmooth{uType, tType, T, T2, N, ITP <: AbstractInterpolation{T, N}} <:
AbstractInterpolation{T, N}
u::uType
::uType
t::tType
Expand All @@ -116,7 +116,8 @@ struct RegularizationSmooth{uType, tType, T, T2, ITP <: AbstractInterpolation{T}
alg,
Aitp,
extrapolate)
new{typeof(u), typeof(t), eltype(u), typeof(λ), typeof(Aitp)}(
N = get_output_dim(u)
new{typeof(u), typeof(t), eltype(u), typeof(λ), N, typeof(Aitp)}(
u,
û,
t,
Expand All @@ -143,8 +144,9 @@ struct CurvefitCache{
lbType,
algType,
pminType,
T
} <: AbstractInterpolation{T}
T,
N
} <: AbstractInterpolation{T, N}
u::uType
t::tType
m::mType # model type
Expand All @@ -155,9 +157,10 @@ struct CurvefitCache{
pmin::pminType # optimized params
extrapolate::Bool
function CurvefitCache(u, t, m, p0, ub, lb, alg, pmin, extrapolate)
N = get_output_dim(u)
new{typeof(u), typeof(t), typeof(m),
typeof(p0), typeof(ub), typeof(lb),
typeof(alg), typeof(pmin), eltype(u)}(u,
typeof(alg), typeof(pmin), eltype(u), N}(u,
t,
m,
p0,
Expand Down
Loading

0 comments on commit 2cca631

Please sign in to comment.