phytorch.interpolate¶
Classes for univariate and multidimensional interpolation. Batched, of course.
Splines¶
- class phytorch.interpolate.splines.Spline¶
Interpolating univariate spline.
- x0¶
locations of the knots along the last dimension. Must be sorted!
- Type:
Tensor(batch_shape..., N)
- batch_shape¶
= x0.shape[:-1]: batch shape of the knots- Type:
torch.Size
- Y0(y0)¶
Right-hand side of all constraint equations in the appropriate order.
- coeffs(y0)¶
Coefficients for the interpolating polynomials.
- evaluate(x, y0)¶
Evaluate the spline (that interpolates
y0fromx0) atx.- Parameters:
x (
Tensor(batch..., M)) – Points at which interpolation is to be performed. Can have a last dimension of arbitrary length. The rest need to broadcast with thebatch_shape.y0 (
Tensor(batch..., npoints)) – Values of the interpolated function. Must broadcast withx0.
- Returns:
The spline which passes through
(x0, y0)evaluated atx.- Return type:
Tensor(batch..., M)
- pick_coeffs(x, y0)¶
Coefficients of the interpolating polynomials, corresponding to each point in
x.- Parameters:
x (
Tensor(batch..., M)) – Points at which interpolation is to be performed. Can have a last dimension of arbitrary length. The rest need to broadcast with thebatch_shape.y0 (
Tensor(batch..., npoints)) – Values of the interpolated function. Must broadcast withx0.
- Returns:
Coefficients (in the first dimension) corresponding to the particular polynomial that covers each point in
x. The spline can then be evaluated by usingpolyval:polyval(Spline(x0).pick_coeffs(x, y0), x)
which is exactly the code of
evaluate.- Return type:
Tensor(nvarsp, batch..., M)
- pick_poly(x)¶
Index of the polynomial that each element of
xcorresponds to.- Parameters:
x (
Tensor(batch..., M)) – Points at which interpolation is to be performed. Can have a last dimension of arbitrary length. The rest need to broadcast with thebatch_shape.- Returns:
LongTensorof the (broadcasted) shape ofxwhich indexes into the polynomials that comprise the spline. Points outside the range ofx0’s are extrapolated, i.e. assigned to the boundary polynomials.- Return type:
Tensor(additional_batch..., batch_shape..., M)
- weights(x)¶
Weights that directly combine \(\{y_{0, i}\}\) into \(y(x)\).
- Parameters:
x (
Tensor(batch..., M)) – Points at which interpolation is to be performed. Can have a last dimension of arbitrary length. The rest need to broadcast with thebatch_shape.- Returns:
Weights (in the last dimension) that multiply a given \(y_0\) to give \(y(x)\) at each given
x. This leads to an alternative way to evaluate the spline:\[y(x) = w(x_0, x)^T y_0.\]- Return type:
Tensor(batch..., M, npoints)
- class phytorch.interpolate.splines.SplineNd¶
N-dimensional spline as the product of univariate
Splines.- Parameters:
x0s –
[(batch_shape_1..., npoints_1), (batch_shape_2..., npoints_2)), ...]knots in each dimension. The batch shapes should broadcast.degree – degree of the spline. Passed to the univariate
Splines.
- grid_shape¶
shape of the grid:
(npoints_1, npoints_2, ...)- Type:
torch.Size
- batch_shape¶
broadcasted
batch_shapeof all the 1D grids.- Type:
torch.Size
- evaluate(y0, *xs)¶
Evaluate the n-dimensional spline as a multilinear “product” of 1-dim splines:
\[y(x_1, x_2, ...) = \sum_{i=1, j=1, \ldots}^{N_1, N_2, \ldots} y_{0, ij\ldots} w_{1,i}(x_1) w_{2,i}(x_2) \ldots\]- Parameters:
y0 (
Tensor(batch..., npoints_1, npoints_2, ...)) – Values of the interpolated function as a grid in the lastndimdimensions. The rest must broadcast withbatch_shapeand with the batch shapes ofxs.xs –
[(batch..., M), (batch..., M), ...]Coordinates of the points where the spline is to be evaluated. Last dimension must match, and the batch dimensions must broadcast among each other, withy0, and withbatch_shape.
- Returns:
The spline evaluated at
xs = (x_1, x_2, ...).- Return type:
Tensor(batch..., M)