You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/control.md
+83-38Lines changed: 83 additions & 38 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,11 +2,20 @@
2
2
3
3
### BSplines
4
4
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
v =itp(3.65, 5) # returns 0.35*A[3,5] + 0.65*A[4,5]
36
46
```
@@ -43,7 +53,15 @@ which destroys the input `A` but also does not need to allocate as much memory.
43
53
44
54
### Scaled BSplines
45
55
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.
47
65
48
66
Some examples,
49
67
```julia
@@ -89,8 +107,8 @@ The general syntax is
89
107
```julia
90
108
itp =interpolate(nodes, A, options...)
91
109
```
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.
94
112
95
113
For example:
96
114
```julia
@@ -101,27 +119,30 @@ itp(4,1.2) # approximately A[2,6]
101
119
```
102
120
One may also mix modes, by specifying a mode vector in the form of an explicit tuple:
103
121
```julia
104
-
itp =interpolate(nodes, A, (Gridded(Linear()),Gridded(Constant())))
122
+
itp =interpolate(nodes, A, (Gridded(Linear()),Gridded(Constant())))
105
123
```
106
124
107
125
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.
`missing` data will naturally propagate through the interpolation,
127
148
where some values will become missing. To avoid that, one can
@@ -131,22 +152,27 @@ For example:
131
152
x =1:6
132
153
A = [i ==3?missing: i for i in x]
133
154
xf = [xi for (xi,a) inzip(x, A) if!ismissing(a)]
134
-
Af =[a for a in A if!ismissing(a)]
155
+
Af =filter(!ismissing, A)
135
156
itp =interpolate((xf, ), Af, Gridded(Linear()))
136
157
```
137
158
138
159
In-place gridded interpolation is also possible:
139
-
```julia
160
+
```@example
161
+
using Interpolations # hide
140
162
x = 1:4
141
163
y = view(rand(4), :)
142
164
itp = interpolate!((x,), y, Gridded(Linear()))
143
165
y .= 0
144
-
@showitp(2.5)# 0
166
+
itp(2.5)
145
167
```
146
168
147
169
## Parametric splines
148
170
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
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.
178
211
179
212
Here is an example of making a cumulative distribution function for some data:
0 commit comments