runlmc.approx.interpolation module

runlmc.approx.interpolation.autogrid(Xs, lo, hi, m)[source]

Generate a grid from lo to hi with m points, but with sensible defaults based on Xs if any of the other parameters are None.

In particular, the defaults are chosen such that all elements in Xs fall within the grid by two elements on both sides. If a user’s values do not guarantee this property, they are changed.

Parameters:
  • Xs – list of 2-dimensional numpy design matrices, the inputs.
  • lo – optional lower bound
  • hi – optional upper bound
  • m – optional grid size
Returns:

the equally-spaced grid points, as a list for each dimension

runlmc.approx.interpolation.cubic_kernel(x)[source]

The cubic convolution kernel can be used to compute interpolation coefficients. Its definition is taken from:

Cubic Convolution Interpolation for Digital Image Processing by Robert G. Keys.

It is supported on values of absolute magnitude less than 2 and is defined as:

\[\begin{split}u(x) = \begin{cases} \frac{3}{2}\left\vert{x}\right\vert^3-\frac{5}{2}\left\vert{x} \right\vert^2+1 & 0\le \left\vert{x}\right\vert\le 1 \\ \frac{3}{2}\left\vert{x}\right\vert^3+\frac{5}{2}-4\left \vert{x}\right\vert+2 & 1 < \left\vert{x}\right\vert \le 2 \end{cases}\end{split}\]
Parameters:x (numpy.ndarray) – input array
Returns:\(u\) vectorized over x
runlmc.approx.interpolation.interp_bicubic(gridx, gridy, samples)[source]

Given an implicit two dimensional grid from the Cartesian product of gridx and gridy, with sizes m1,m2, respectively (such that each grid is an equispaced increasing sequence of values), and given n sample points (which should be 2D), this computes interpolation coefficients for a cubic interpolation on the grid.

An interpolation coefficient matrix M is then an n by m1*m2 matrix that has 16 entries per row.

For a (vectorized) twice-differentiable function f, M.dot(f(cartesian_product(gridx, gridy)).ravel()) approaches f(sample) at a rate of \(O(m^{-3})\).

Returns:the interpolation coefficient matrix
Raises:ValueError – if any conditions similar to those in interp_cubic() are violated.
runlmc.approx.interpolation.interp_cubic(grid, samples)[source]

Given a one dimensional grid grid of size m (that’s sorted) and n sample points samples, compute the interpolation coefficients for a cubic interpolation on the grid.

An interpolation coefficient matrix M is then an n by m matrix that has 4 entries per row.

For a (vectorized) twice-differentiable function f, M.dot(f(grid)) approaches f(sample) at a rate of \(O(m^{-3})\).

samples should be contained with the range of grid, but this method will create a matrix capable of handling extrapolation.

Returns:the interpolation coefficient matrix
Raises:ValueError

if any of the following hold true:

  1. grid or samples are not 1-dimensional
  2. grid size less than 4
  3. grid is not equispaced
runlmc.approx.interpolation.multi_interpolant(Xs, *inducing_grids)[source]

Creates a sparse CSR matrix interpolant across multiple inputs Xs.

Each input is mapped onto the inducing grid with a cubic interpolation, with runlmc.approx.interpolation.interp_cubic() or runlmc.approx.interpolation.interp_bicubic(), depending on the dimensionality of Xs.

This induces \(n_i\times m\) interpolation matrices \(W_i\) for the \(i\)-th element of Xs onto the inducing grid, which is shared between all Xs. Note that \(m\) is the total size of the Cartesian product of the inducing grids for each dimension of the input. This also implies that the number of inducing grid axes passed as arguments to multi_interpolant must be equal to the dimension of Xs.

Parameters:
  • Xs – list of \(n_i\)-by-\(d\) input points, where \(d\) may be either 1 or 2. In the case \(d=1\) the input matrices can be vectors.
  • inducing_grids – list 1-dimensional vector of grid points, one for each input dimension
Returns:

the rectangular block diagonal matrix of \(W_i\).