Skip to content

Commit 8c25bad

Browse files
authored
Merge pull request #591 from abhro/patch-1
Minor overhaul of markdown docs and docstrings
2 parents c7e2d45 + c86d58e commit 8c25bad

30 files changed

+653
-394
lines changed

doc/Extrapolation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ For some of these, extra care needs to be taken in higher dimensions, when decid
4141
| |
4242
----------+---------------+--------
4343
| |
44-
| | ...and here?
44+
| | ...and here?

docs/Project.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[deps]
22
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
3+
DocumenterCitations = "daee34ce-89f3-4625-b898-19384cb65244"
34
Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
45

56
[compat]
6-
Documenter = "0.27"
7+
Documenter = "1"

docs/make.jl

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
1-
using Documenter, Interpolations
1+
using Documenter
2+
using DocumenterCitations
3+
using Interpolations
4+
5+
DocMeta.setdocmeta!(
6+
Interpolations,
7+
:DocTestSetup,
8+
:(using Interpolations),
9+
recursive = true,
10+
)
11+
12+
bib = CitationBibliography(
13+
joinpath(@__DIR__, "src", "refs.bib"),
14+
style = :authoryear,
15+
)
16+
217
makedocs(
3-
sitename="Interpolations.jl",
4-
modules=[Interpolations],
5-
format=Documenter.HTML(prettyurls = get(ENV, "CI", nothing)=="true"),
6-
pages=["Home" => "index.md",
18+
sitename = "Interpolations.jl",
19+
modules = [Interpolations],
20+
format = Documenter.HTML(
21+
prettyurls = get(ENV, "CI", nothing)=="true",
22+
),
23+
pages = [
24+
"Home" => "index.md",
725
"Convenience Constructors" => "convenience-construction.md",
826
"General usage" => "interpolations.md",
927
"Interpolation algorithms" => "control.md",
@@ -13,9 +31,14 @@ pages=["Home" => "index.md",
1331
"Library" => "api.md",
1432
"News and Changes" => "NEWS.md",
1533
"Other Interpolation Packages" => "other_packages.md",
16-
],
17-
strict=true,
34+
"Bilbiography" => "bibliography.md",
35+
],
36+
warnonly = false,
37+
doctest = true,
38+
plugins = [bib],
1839
)
1940

20-
deploydocs(repo="github.com/JuliaMath/Interpolations.jl.git",
21-
push_preview=true)
41+
deploydocs(
42+
repo = "github.com/JuliaMath/Interpolations.jl.git",
43+
push_preview = true,
44+
)

docs/src/api.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
## Public API
2-
```@meta
3-
DocTestSetup= quote
4-
using Interpolations
5-
end
6-
```
72

83
```@autodocs
94
Modules = [Interpolations]
@@ -17,3 +12,9 @@ Modules = [Interpolations]
1712
Public = false
1813
Order = [:function, :type]
1914
```
15+
16+
## Bibliography
17+
```@bibliography
18+
Pages = ["api.md"]
19+
Canonical = false
20+
```

docs/src/bibliography.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Bibliography
2+
3+
```@bibliography
4+
```
5+
6+
```@bibliography
7+
*
8+
```

docs/src/chainrules.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ This enables integration with autodiff libraries like Zygote, enabling
1212
```julia
1313
x = 1:10
1414
y = sin.(x)
15-
itp = interpolate(y,BSpline(Linear()))
15+
itp = interpolate(y, BSpline(Linear()))
1616
Zygote.gradient(itp, 2)
1717
#([-0.7681774187658145],)
18-
```
18+
```

docs/src/control.md

Lines changed: 83 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,20 @@
22

33
### BSplines
44

5-
The interpolation type is described in terms of *degree* and, if necessary, *boundary conditions*. There are currently four degrees available: `Constant`, `Linear`, `Quadratic`, and `Cubic` corresponding to B-splines of degree 0, 1, 2, and 3 respectively.
6-
7-
B-splines of quadratic or higher degree require solving an equation system to obtain the interpolation coefficients, and for that you must specify a *boundary condition* that is applied to close the system. The following boundary conditions are implemented: `Flat`, `Line` (alternatively, `Natural`), `Free`, `Periodic` and `Reflect`; their mathematical implications are described in detail in their docstrings.
8-
When specifying these boundary conditions you also have to specify whether they apply at the edge grid point (`OnGrid()`)
9-
or beyond the edge point halfway to the next (fictitious) grid point (`OnCell()`).
5+
The interpolation type is described in terms of *degree* and, if necessary,
6+
*boundary conditions*. There are currently four degrees available: `Constant`,
7+
`Linear`, `Quadratic`, and `Cubic` corresponding to B-splines of degree 0, 1,
8+
2, and 3 respectively.
9+
10+
B-splines of quadratic or higher degree require solving an equation system to
11+
obtain the interpolation coefficients, and for that you must specify a
12+
*boundary condition* that is applied to close the system. The following boundary
13+
conditions are implemented: `Flat`, `Line` (alternatively, `Natural`), `Free`,
14+
`Periodic` and `Reflect`; their mathematical implications are described in
15+
detail in their docstrings.
16+
When specifying these boundary conditions you also have to specify whether they
17+
apply at the edge grid point (`OnGrid()`) or beyond the edge point halfway to
18+
the next (fictitious) grid point (`OnCell()`).
1019

1120
Some examples:
1221
```julia
@@ -30,7 +39,8 @@ v = itp(3.2, 4.1) # returns 0.9*(0.8*A[3,4]+0.2*A[4,4]) + 0.1*(0.8*A[3,5]+0.2*A
3039
# Quadratic is the lowest order that has continuous gradient
3140
itp = interpolate(A, BSpline(Quadratic(Reflect(OnCell()))))
3241

33-
# Linear interpolation in the first dimension, and no interpolation (just lookup) in the second
42+
# Linear interpolation in the first dimension, and no interpolation
43+
# (just lookup) in the second
3444
itp = interpolate(A, (BSpline(Linear()), NoInterp()))
3545
v = itp(3.65, 5) # returns 0.35*A[3,5] + 0.65*A[4,5]
3646
```
@@ -43,7 +53,15 @@ which destroys the input `A` but also does not need to allocate as much memory.
4353

4454
### Scaled BSplines
4555

46-
BSplines assume your data is uniformly spaced on the grid `1:N`, or its multidimensional equivalent. If you have data of the form `[f(x) for x in A]`, you need to tell Interpolations about the grid `A`. If `A` is not uniformly spaced, you must use gridded interpolation described below. However, if `A` is a collection of ranges or linspaces, you can use scaled BSplines. This is more efficient because the gridded algorithm does not exploit the uniform spacing. Scaled BSplines can also be used with any spline degree available for BSplines, while gridded interpolation does not currently support quadratic or cubic splines.
56+
BSplines assume your data is uniformly spaced on the grid `1:N`, or its
57+
multidimensional equivalent. If you have data of the form `[f(x) for x in A]`,
58+
you need to tell Interpolations about the grid `A`. If `A` is not uniformly
59+
spaced, you must use gridded interpolation described below. However, if `A` is a
60+
collection of ranges or linspaces, you can use scaled BSplines. This is more
61+
efficient because the gridded algorithm does not exploit the uniform spacing.
62+
Scaled BSplines can also be used with any spline degree available for BSplines,
63+
while gridded interpolation does not currently support quadratic or cubic
64+
splines.
4765

4866
Some examples,
4967
```julia
@@ -89,8 +107,8 @@ The general syntax is
89107
```julia
90108
itp = interpolate(nodes, A, options...)
91109
```
92-
where `nodes = (xnodes, ynodes, ...)` specifies the positions along
93-
each axis at which the array `A` is sampled for arbitrary ("rectangular") samplings.
110+
where `nodes = (xnodes, ynodes, ...)` specifies the positions along each axis
111+
at which the array `A` is sampled for arbitrary ("rectangular") samplings.
94112

95113
For example:
96114
```julia
@@ -101,27 +119,30 @@ itp(4,1.2) # approximately A[2,6]
101119
```
102120
One may also mix modes, by specifying a mode vector in the form of an explicit tuple:
103121
```julia
104-
itp = interpolate(nodes, A, (Gridded(Linear()),Gridded(Constant())))
122+
itp = interpolate(nodes, A, (Gridded(Linear()), Gridded(Constant())))
105123
```
106124

107125
Presently there are only three modes for gridded:
108-
```julia
109-
Gridded(Linear())
110-
```
111-
whereby a linear interpolation is applied between nodes,
112-
```julia
113-
Gridded(Constant())
114-
```
115-
whereby nearest neighbor interpolation is used on the applied axis,
116-
```julia
117-
NoInterp()
118-
```
119-
whereby the coordinate of the selected input vector MUST be located on a grid point. Requests for off grid
120-
coordinates results in the throwing of an error.
121-
122-
For [`Constant`](@ref) there are additional parameters. Use `Constant{Previous}()` in order to perform a previous
123-
neighbor interpolation. Use `Constant{Next}()` for a next neighbor interpolation.
124-
Note that rounding can be an issue, see [#473](https://github.com/JuliaMath/Interpolations.jl/issues/473).
126+
- For linear interpolation between nodes
127+
```julia
128+
Gridded(Linear())
129+
```
130+
- For nearest neighbor interpolation on the applied axis
131+
```julia
132+
Gridded(Constant())
133+
```
134+
- For no interpolation. The coordinate of the selected input vector MUST be
135+
located on a grid point. Requests for off grid coordinates results in the
136+
throwing of an error.
137+
```julia
138+
NoInterp()
139+
```
140+
141+
For [`Constant`](@ref) there are additional parameters. Use
142+
`Constant{Previous}()` in order to perform a previous neighbor interpolation.
143+
Use `Constant{Next}()` for a next neighbor interpolation.
144+
Note that rounding can be an issue, see
145+
[issue #473](https://github.com/JuliaMath/Interpolations.jl/issues/473).
125146

126147
`missing` data will naturally propagate through the interpolation,
127148
where some values will become missing. To avoid that, one can
@@ -131,22 +152,27 @@ For example:
131152
x = 1:6
132153
A = [i == 3 ? missing : i for i in x]
133154
xf = [xi for (xi,a) in zip(x, A) if !ismissing(a)]
134-
Af = [a for a in A if !ismissing(a)]
155+
Af = filter(!ismissing, A)
135156
itp = interpolate((xf, ), Af, Gridded(Linear()))
136157
```
137158

138159
In-place gridded interpolation is also possible:
139-
```julia
160+
```@example
161+
using Interpolations # hide
140162
x = 1:4
141163
y = view(rand(4), :)
142164
itp = interpolate!((x,), y, Gridded(Linear()))
143165
y .= 0
144-
@show itp(2.5) # 0
166+
itp(2.5)
145167
```
146168

147169
## Parametric splines
148170

149-
Given a set a knots with coordinates `x(t)` and `y(t)`, a parametric spline `S(t) = (x(t),y(t))` parametrized by `t in [0,1]` can be constructed with the following code adapted from a [post](http://julia-programming-language.2336112.n4.nabble.com/Parametric-splines-td37794.html#a37818) by Tomas Lycken:
171+
Given a set a knots with coordinates `x(t)` and `y(t)`, a parametric spline
172+
`S(t) = (x(t),y(t))` parametrized by `t` in `[0,1]` can be constructed with the
173+
following code adapted from a
174+
[post](http://julia-programming-language.2336112.n4.nabble.com/Parametric-splines-td37794.html#a37818)
175+
by Tomas Lycken:
150176

151177
```julia
152178
using Interpolations
@@ -156,7 +182,11 @@ x = sin.(2π*t)
156182
y = cos.(2π*t)
157183
A = hcat(x,y)
158184

159-
itp = Interpolations.scale(interpolate(A, (BSpline(Cubic(Natural(OnGrid()))), NoInterp())), t, 1:2)
185+
itp = Interpolations.scale(
186+
interpolate(A, (BSpline(Cubic(Natural(OnGrid()))), NoInterp())),
187+
t,
188+
1:2
189+
)
160190

161191
tfine = 0:.01:1
162192
xs, ys = [itp(t,1) for t in tfine], [itp(t,2) for t in tfine]
@@ -174,16 +204,27 @@ plot!(xs, ys, label="spline")
174204

175205
## Monotonic interpolation
176206

177-
When you have some one-dimensional data that is monotonic, many standard interpolation methods may give an interpolating function that it is not monotonic. Monotonic interpolation ensures that the interpolating function is also monotonic.
207+
When you have some one-dimensional data that is monotonic, many standard
208+
interpolation methods may give an interpolating function that it is not
209+
monotonic. Monotonic interpolation ensures that the interpolating function is
210+
also monotonic.
178211

179212
Here is an example of making a cumulative distribution function for some data:
180213

181214
```julia
182-
percentile_values = [0.0, 0.01, 0.1, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0, 91.0, 92.0, 93.0, 94.0, 95.0, 96.0, 97.0, 98.0, 99.0, 99.9, 99.99, 100.0];
215+
percentile_values = [
216+
0.0, 0.01, 0.1, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0,
217+
10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0,
218+
91.0, 92.0, 93.0, 94.0, 95.0, 96.0, 97.0, 98.0, 99.0,
219+
99.9, 99.99, 100.0
220+
];
183221

184222
y = sort(randn(length(percentile_values))); # some random data
185223

186-
itp_cdf = extrapolate(interpolate(y, percentile_values, SteffenMonotonicInterpolation()), Flat());
224+
itp_cdf = extrapolate(
225+
interpolate(y, percentile_values, SteffenMonotonicInterpolation()),
226+
Flat()
227+
);
187228

188229
t = -3.0:0.01:3.0 # just a range for calculating values of the interpolating function
189230

@@ -200,7 +241,11 @@ There are a few different monotonic interpolation algorithms. Some guarantee tha
200241
* [`SteffenMonotonicInterpolation`](@ref) -- it does not overshoot.
201242

202243
You can read about monotonic interpolation in the following sources:
244+
```@bibliography
245+
Pages = []
246+
Canonical = false
203247
204-
* Fritsch & Carlson (1980), "Monotone Piecewise Cubic Interpolation", doi:10.1137/0717021.
205-
* Fritsch & Butland (1984), "A Method for Constructing Local Monotone Piecewise Cubic Interpolants", doi:10.1137/0905021.
206-
* Steffen (1990), "A Simple Method for Monotonic Interpolation in One Dimension", [URL](http://adsabs.harvard.edu/abs/1990A%26A...239..443S)
248+
Fritsch1980
249+
Fritsch1984
250+
Steffen1990
251+
```

0 commit comments

Comments
 (0)