Skip to content

Commit b11bdd5

Browse files
author
Tomas Lycken
committed
Merge pull request #103 from tlycken/improve-docs
Improve docs
2 parents 21e5a2f + b03616a commit b11bdd5

File tree

10 files changed

+256
-400
lines changed

10 files changed

+256
-400
lines changed

doc/latex/Interpolations.bbl

Lines changed: 0 additions & 57 deletions
This file was deleted.

doc/latex/Interpolations.bib

Lines changed: 0 additions & 13 deletions
This file was deleted.

doc/latex/Interpolations.pdf

-279 KB
Binary file not shown.

doc/latex/Interpolations.tex

Lines changed: 0 additions & 283 deletions
This file was deleted.

doc/latex/figures/periodic-data.pdf

-5.93 KB
Binary file not shown.

src/b-splines/constant.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,41 @@
11
immutable Constant <: Degree{0} end
22

3+
"""
4+
Constant b-splines are *nearest-neighbor* interpolations, and effectively
5+
return `A[round(Int,x)]` when interpolating
6+
"""
7+
Constant
8+
9+
"""
10+
`define_indices_d` for a constant b-spline calculates `ix_d = round(Int,x_d)`
11+
"""
312
function define_indices_d(::Type{BSpline{Constant}}, d, pad)
413
symix, symx = symbol("ix_",d), symbol("x_",d)
514
:($symix = clamp(round(Int, $symx), 1, size(itp, $d)))
615
end
716

17+
"""
18+
`coefficients` for a constant b-spline simply sets `c_d = 1` for compatibility
19+
with the general b-spline framework
20+
"""
821
function coefficients(::Type{BSpline{Constant}}, N, d)
922
sym, symx = symbol("c_",d), symbol("x_",d)
1023
:($sym = 1)
1124
end
1225

26+
"""
27+
`gradient_coefficients` for a constant b-spline simply sets `c_d = 0` for
28+
compatibility with the general b-spline framework
29+
"""
1330
function gradient_coefficients(::Type{BSpline{Constant}}, d)
1431
sym, symx = symbol("c_",d), symbol("x_",d)
1532
:($sym = 0)
1633
end
1734

35+
"""
36+
`hessian_coefficients` for a constant b-spline simply sets `c_d = 0` for
37+
compatibility with the general b-spline framework
38+
"""
1839
function hessian_coefficients(::Type{BSpline{Constant}}, d)
1940
sym = symbol("c_",d)
2041
:($sym = 0)

src/b-splines/cubic.jl

Lines changed: 64 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ Cubic{BC<:Flag}(::BC) = Cubic{BC}()
55
Assuming uniform knots with spacing 1, the `i`th piece of cubic spline
66
implemented here is defined as follows.
77
8-
y_i(x) = ϕm p(x-i) + ϕ q(x-i) + ϕp q(1- (x-i)) + ϕpp p(1 - (x-i))
8+
y_i(x) = cm p(x-i) + c q(x-i) + cp q(1- (x-i)) + cpp p(1 - (x-i))
99
1010
where
1111
12-
p() = 1/6 * (1-)^3
13-
q() = 2/3 - ^2 + 1/2 ^3
12+
p(δx) = 1/6 * (1-δx)^3
13+
q(δx) = 2/3 - δx^2 + 1/2 δx^3
1414
15-
and the values `ϕX` for `X {m, _, p, pp}` are the pre-filtered coefficients.
15+
and the values `cX` for `X {m, _, p, pp}` are the pre-filtered coefficients.
1616
1717
For future reference, this expands out to the following polynomial:
1818
@@ -24,6 +24,11 @@ When we derive boundary conditions we will use derivatives `y_0'(x)` and
2424
"""
2525
Cubic
2626

27+
"""
28+
`define_indices_d` for a cubic b-spline calculates `ix_d = floor(x_d)` and
29+
`fx_d = x_d - ix_d` (corresponding to `i` `and `δx` in the docstring for
30+
`Cubic`), as well as auxiliary quantities `ixm_d`, `ixp_d` and `ixpp_d`
31+
"""
2732
function define_indices_d{BC}(::Type{BSpline{Cubic{BC}}}, d, pad)
2833
symix, symixm, symixp = symbol("ix_",d), symbol("ixm_",d), symbol("ixp_",d)
2934
symixpp, symx, symfx = symbol("ixpp_",d), symbol("x_",d), symbol("fx_",d)
@@ -39,6 +44,14 @@ function define_indices_d{BC}(::Type{BSpline{Cubic{BC}}}, d, pad)
3944
end
4045
end
4146

47+
"""
48+
`define_indices_d` for a cubic, periodic b-spline calculates `ix_d = floor(x_d)`
49+
and `fx_d = x_d - ix_d` (corresponding to `i` and `δx` in the docstring entry
50+
for `Cubic`), as well as auxiliary quantities `ixm_d`, `ixp_d` and `ixpp_d`.
51+
52+
If any `ixX_d` for `x ∈ {m, p, pp}` (note: not `c_d`) should fall outside of
53+
the data interval, they wrap around.
54+
"""
4255
function define_indices_d(::Type{BSpline{Cubic{Periodic}}}, d, pad)
4356
symix, symixm, symixp = symbol("ix_",d), symbol("ixm_",d), symbol("ixp_",d)
4457
symixpp, symx, symfx = symbol("ixpp_",d), symbol("x_",d), symbol("fx_",d)
@@ -55,15 +68,16 @@ padding{BC<:Flag}(::Type{BSpline{Cubic{BC}}}) = Val{1}()
5568
padding(::Type{BSpline{Cubic{Periodic}}}) = Val{0}()
5669

5770
"""
58-
In this function we assume that `fx_d = x-ix_d` and we produce `cX_d` for
59-
`X ⋹ {m, _, p, pp}` such that
71+
In `coefficients` for a cubic b-spline we assume that `fx_d = x-ix_d`
72+
and we define `cX_d` for `X ⋹ {m, _, p, pp}` such that
6073
6174
cm_d = p(fx_d)
6275
c_d = q(fx_d)
6376
cp_d = q(1-fx_d)
6477
cpp_d = p(1-fx_d)
6578
66-
where `p` and `q` are defined in the docstring entry for `Cubic`.
79+
where `p` and `q` are defined in the docstring entry for `Cubic`, and
80+
`fx_d` in the docstring entry for `define_indices_d`.
6781
"""
6882
function coefficients{C<:Cubic}(::Type{BSpline{C}}, N, d)
6983
symm, sym = symbol("cm_",d), symbol("c_",d)
@@ -82,15 +96,16 @@ function coefficients{C<:Cubic}(::Type{BSpline{C}}, N, d)
8296
end
8397

8498
"""
85-
In this function we assume that `fx_d = x-ix_d` and we produce `cX_d` for
86-
`X ⋹ {m, _, p, pp}` such that
99+
In `gradient_coefficients` for a cubic b-spline we assume that `fx_d = x-ix_d`
100+
and we define `cX_d` for `X ⋹ {m, _, p, pp}` such that
87101
88102
cm_d = p'(fx_d)
89103
c_d = q'(fx_d)
90104
cp_d = q'(1-fx_d)
91105
cpp_d = p'(1-fx_d)
92106
93-
where `p` and `q` are defined in the docstring for `Cubic`.
107+
where `p` and `q` are defined in the docstring entry for `Cubic`, and
108+
`fx_d` in the docstring entry for `define_indices_d`.
94109
"""
95110
function gradient_coefficients{C<:Cubic}(::Type{BSpline{C}}, d)
96111
symm, sym, symp, sympp = symbol("cm_",d), symbol("c_",d), symbol("cp_",d), symbol("cpp_",d)
@@ -147,6 +162,14 @@ end
147162
# Prefiltering #
148163
# ------------ #
149164

165+
"""
166+
`Cubic`: continuity in function value, first and second derivatives yields
167+
168+
2/3 1/6
169+
1/6 2/3 1/6
170+
1/6 2/3 1/6
171+
⋱ ⋱ ⋱
172+
"""
150173
function inner_system_diags{T,C<:Cubic}(::Type{T}, n::Int, ::Type{C})
151174
du = fill(convert(T, SimpleRatio(1, 6)), n-1)
152175
d = fill(convert(T, SimpleRatio(2, 3)), n)
@@ -155,8 +178,8 @@ function inner_system_diags{T,C<:Cubic}(::Type{T}, n::Int, ::Type{C})
155178
end
156179

157180
"""
158-
`Flat` `OnGrid` amounts to setting `y_0'(x) = 0` at `x = 0`. Applying this
159-
condition gives:
181+
`Cubic{Flat}` `OnGrid` amounts to setting `y_1'(x) = 0` at `x = 1`.
182+
Applying this condition yields
160183
161184
-cm + cp = 0
162185
"""
@@ -173,10 +196,18 @@ function prefiltering_system{T,TC}(::Type{T}, ::Type{TC}, n::Int,
173196
end
174197

175198
"""
176-
`Flat` `OnCell` amounts to setting `y_0'(x) = 0` at `x = -1/2`. Applying this
177-
condition gives:
199+
`Cubic{Flat}`, `OnCell` amounts to setting `y_1'(x) = 0` at `x = 1/2`.
200+
Applying this condition yields
201+
202+
-9/8 cm + 11/8 c - 3/8 cp + 1/8 cpp = 0
203+
204+
or, equivalently,
178205
179206
-9 cm + 11 c -3 cp + 1 cpp = 0
207+
208+
(Note that we use `y_1'(x)` although it is strictly not valid in this domain; if we
209+
were to use `y_0'(x)` we would have to introduce new coefficients, so that would not
210+
close the system. Instead, we extend the outermost polynomial for an extra half-cell.)
180211
"""
181212
function prefiltering_system{T,TC}(::Type{T}, ::Type{TC}, n::Int,
182213
::Type{Cubic{Flat}}, ::Type{OnCell})
@@ -198,10 +229,14 @@ function prefiltering_system{T,TC}(::Type{T}, ::Type{TC}, n::Int,
198229
end
199230

200231
"""
201-
`Line` `OnCell` amounts to setting `y_0''(x) = 0` at `x = -1/2`. Applying this
202-
condition gives:
232+
`Cubic{Line}` `OnCell` amounts to setting `y_1''(x) = 0` at `x = 1/2`.
233+
Applying this condition yields
203234
204235
3 cm -7 c + 5 cp -1 cpp = 0
236+
237+
(Note that we use `y_1'(x)` although it is strictly not valid in this domain; if we
238+
were to use `y_0'(x)` we would have to introduce new coefficients, so that would not
239+
close the system. Instead, we extend the outermost polynomial for an extra half-cell.)
205240
"""
206241
function prefiltering_system{T,TC}(::Type{T}, ::Type{TC}, n::Int,
207242
::Type{Cubic{Line}}, ::Type{OnCell})
@@ -223,13 +258,10 @@ function prefiltering_system{T,TC}(::Type{T}, ::Type{TC}, n::Int,
223258
end
224259

225260
"""
226-
`Line` `OnGrid` amounts to setting `y_0''(x) = 0` at `x = 0`. Applying this
261+
`Cubic{Line}` `OnGrid` amounts to setting `y_1''(x) = 0` at `x = 1`. Applying this
227262
condition gives:
228263
229-
1 cm -2 c + 1 cp = 0 = 0
230-
231-
This is the same system as `Quadratic{Line}`, `OnGrid` so we reuse the
232-
implementation
264+
1 cm -2 c + 1 cp = 0
233265
"""
234266
function prefiltering_system{T,TC}(::Type{T}, ::Type{TC}, n::Int,
235267
::Type{Cubic{Line}}, ::Type{OnGrid})
@@ -247,6 +279,14 @@ function prefiltering_system{T,TC}(::Type{T}, ::Type{TC}, n::Int,
247279
Woodbury(lufact!(Tridiagonal(dl, d, du), Val{false}), specs...), zeros(TC, n)
248280
end
249281

282+
"""
283+
`Cubic{Periodic}` `OnGrid` closes the system by looking at the coefficients themselves
284+
as periodic, yielding
285+
286+
c0 = c(N+1)
287+
288+
where `N` is the number of data points.
289+
"""
250290
function prefiltering_system{T,TC,GT<:GridType}(::Type{T}, ::Type{TC}, n::Int,
251291
::Type{Cubic{Periodic}}, ::Type{GT})
252292
dl, d, du = inner_system_diags(T,n,Cubic{Periodic})
@@ -260,14 +300,11 @@ function prefiltering_system{T,TC,GT<:GridType}(::Type{T}, ::Type{TC}, n::Int,
260300
end
261301

262302
"""
263-
The free boundary condition for either `OnGrid` or `OnCell` makes sure the
264-
interpoland has a continuous third derivative at the second-to-outermost cell
265-
boundary: `y_0'''(1) = y_1'''(1)` and `y_{n-1}'''(n) = y_n'''(n)`. Applying this
266-
condition gives:
303+
`Cubic{Free}` `OnGrid` and `Cubic{Free}` `OnCell` amount to requiring an extra
304+
continuous derivative at the second-to-last cell boundary; this means
305+
`y_1'''(2) = y_2'''(2)`, yielding
267306
268307
1 cm -3 c + 3 cp -1 cpp = 0
269-
270-
This is the same system as `Quadratic{Free}` so we reuse the implementation
271308
"""
272309
function prefiltering_system{T,TC,GT<:GridType}(::Type{T}, ::Type{TC}, n::Int,
273310
::Type{Cubic{Free}}, ::Type{GT})

src/b-splines/linear.jl

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,31 @@
11
immutable Linear <: Degree{1} end
22

3+
"""
4+
Assuming uniform knots with spacing 1, the `i`th peice of linear b-spline
5+
implemented here is defined as follows.
6+
7+
y_i(x) = c p(x) + cp p(1-x)
8+
9+
where
10+
11+
p(δx) = x
12+
13+
and the values `cX` for `X ∈ {_, p}` are the coefficients.
14+
15+
Linear b-splines are naturally interpolating, and require no prefiltering;
16+
there is therefore no need for boundary conditions to be provided.
17+
18+
Also, although the implementation is slightly different in order to re-use
19+
the framework built for general b-splines, the resulting interpolant is just
20+
a piecewise linear function connecting each pair of neighboring data points.
21+
"""
22+
Linear
23+
24+
"""
25+
`define_indices_d` for a linear b-spline calculates `ix_d = floor(x_d)` and
26+
`fx_d = x_d - ix_d` (corresponding to `i` and `δx` in the docstring for
27+
`Linear`), as well as the auxiliary quantity `ixp_d`
28+
"""
329
function define_indices_d(::Type{BSpline{Linear}}, d, pad)
430
symix, symixp, symfx, symx = symbol("ix_",d), symbol("ixp_",d), symbol("fx_",d), symbol("x_",d)
531
quote
@@ -9,6 +35,16 @@ function define_indices_d(::Type{BSpline{Linear}}, d, pad)
935
end
1036
end
1137

38+
"""
39+
In `coefficients` for a linear b-spline we assume that `fx_d = x-ix-d` and
40+
we define `cX_d` for `X ∈ {_, p}` such that
41+
42+
c_d = p(fx_d)
43+
cp_d = p(1-fx_d)
44+
45+
where `p` is defined in the docstring entry for `Linear` and `fx_d` in the
46+
docstring entry for `define_indices_d`.
47+
"""
1248
function coefficients(::Type{BSpline{Linear}}, N, d)
1349
sym, symp, symfx = symbol("c_",d), symbol("cp_",d), symbol("fx_",d)
1450
quote
@@ -17,6 +53,16 @@ function coefficients(::Type{BSpline{Linear}}, N, d)
1753
end
1854
end
1955

56+
"""
57+
In `gradient_coefficients` for a linear b-spline we assume that `fx_d = x-ix_d`
58+
and we define `cX_d` for `X ⋹ {_, p}` such that
59+
60+
c_d = p'(fx_d)
61+
cp_d = p'(1-fx_d)
62+
63+
where `p` is defined in the docstring entry for `Linear`, and `fx_d` in the
64+
docstring entry for `define_indices_d`.
65+
"""
2066
function gradient_coefficients(::Type{BSpline{Linear}}, d)
2167
sym, symp, symfx = symbol("c_",d), symbol("cp_",d), symbol("fx_",d)
2268
quote
@@ -25,6 +71,16 @@ function gradient_coefficients(::Type{BSpline{Linear}}, d)
2571
end
2672
end
2773

74+
"""
75+
In `hessian_coefficients` for a linear b-spline we assume that `fx_d = x-ix_d`
76+
and we define `cX_d` for `X ⋹ {_, p}` such that
77+
78+
c_d = p''(fx_d)
79+
cp_d = p''(1-fx_d)
80+
81+
where `p` is defined in the docstring entry for `Linear`, and `fx_d` in the
82+
docstring entry for `define_indices_d`. (These are both ≡ 0.)
83+
"""
2884
function hessian_coefficients(::Type{BSpline{Linear}}, d)
2985
sym, symp = symbol("c_",d), symbol("cp_",d)
3086
quote

0 commit comments

Comments
 (0)