minterpy.interpolation#

A top-level module with interfaces to conveniently create interpolants.

The main purpose of Minterpy is to interpolate given functions provided as Python Callables. This top-level module provides a convenient function named interpolate, which outputs a Callable of the type Interpolant. This represents the given function as a multidimensional (Newton) polynomial.

Moreover, it is also possible to construct an Interpolator instance. This object precomputes and caches all the necessary ingredients for the interpolation of any functions.

Function / Class

Description

interpolate

Interpolate a given function

Interpolant

Class that represents an interpolated function

Interpolator

Class that represents interpolators for given functions

minterpy.interpolation.interpolate(func, spatial_dimension, poly_degree, lp_degree=DEFAULT_LP_DEG, bounds=None)[source]#

Interpolate a function using a complete multi-index set polynomial.

Parameters:
  • func (Callable) – The function to interpolate. It must accept as the first argument a numpy.ndarray with shape (k, m), where k is the number of evaluation points and m is the spatial dimension. The function returns a numpy.ndarray with shape (k, ) for scalar outputs and (k, d) for vector outputs, where d is the output dimension.

  • spatial_dimension (int) – The dimension of the interpolator.

  • poly_degree (int) – The degree of the interpolating polynomial.

  • lp_degree (float, optional) – The degree \(p\) of the \(l_p\)-norm used to define the (multivariate) polynomial degree.

  • bounds (array_like, optional) – The bounds of the domain space, an array of shape (m, 2), where m is the spatial dimension. Each row corresponds to the lower and upper bounds of the domain in the corresponding dimension. If not provided, the bounds are assumed to be \([-1, 1]^m\).

Returns:

The interpolant of func with respect to the lexicographically complete multi-index set \(\mathcal{A}_{m, n, p}\) where \(m\) is spatial_dimension, \(n\) is poly_degree, and \(p\) is lp_degree.

Return type:

Interpolant

class minterpy.interpolation.Interpolant(func, interpolator)[source]#

A class representing the result of an interpolation of a given function.

An instance of this class is a callable that interpolates a given function. It serves as an intermediate layer between function approximation and the corresponding interpolating polynomial representation; it can be used without any in-depth knowledge of the underlying polynomial representation.

Parameters:
  • func (Callable) – The function to interpolate. It must accept as the first argument a numpy.ndarray with shape (k, m), where k is the number of evaluation points and m is the spatial dimension. The function returns a numpy.ndarray with shape (k, ) for scalar outputs and (k, d) for vector outputs, where d is the output dimension.

  • interpolator (Interpolator) – The underlying setting for the interpolation.

Properties

lp_degree

\(p\) of \(l_p\)-norm used to define the multi-index set.

multi_index

The multi-index set defining the interpolating polynomial.

poly_degree

The degree of the interpolating polynomial.

spatial_dimension

The dimension of the interpolator.

Methods

from_degree(func, spatial_dimension, ...[, ...])

Create an interpolant with respect to a complete multi-index set.

to_canonical()

Return the interpolant as a polynomial in the canonical basis.

to_chebyshev()

Return the interpolant as a polynomial in the Chebyshev basis.

to_lagrange()

Return the interpolant as a polynomial in the Lagrange basis.

to_newton()

Return the interpolant as a polynomial in the Newton basis.

classmethod from_degree(func, spatial_dimension, poly_degree, lp_degree, bounds=None)[source]#

Create an interpolant with respect to a complete multi-index set.

Parameters:
  • func (Callable) – The function to interpolate. It must accept as the first argument a numpy.ndarray with shape (k, m), where k is the number of evaluation points and m is the spatial dimension. The function returns a numpy.ndarray with shape (k, ) for scalar outputs and (k, d) for vector outputs, where d is the output dimension.

  • spatial_dimension (int) – The dimension of the interpolator.

  • poly_degree (int) – The degree of the interpolating polynomial.

  • lp_degree (float) – The degree \(p\) of the \(l_p\)-norm used to define the (multivariate) polynomial degree.

  • bounds (array_like, optional) – The bounds of the domain space, an array of shape (m, 2), where m is the spatial dimension. Each row corresponds to the lower and upper bounds of the domain in the corresponding dimension. If not provided, the bounds are assumed to be \([-1, 1]^m\).

Returns:

An instance of interpolant of func using an interpolating polynomial with respect to complete multi-index set.

Return type:

Interpolant

Notes

  • spatial_dimension (\(m\)), poly_degree (\(n\)), lp_degree (\(p\)) are used to construct the lexicographically complete multi-index set \(\mathcal{A}_{m, n, p}\).

property spatial_dimension: int#

The dimension of the interpolator.

property poly_degree: int#

The degree of the interpolating polynomial.

property lp_degree: float#

\(p\) of \(l_p\)-norm used to define the multi-index set.

property multi_index: MultiIndexSet#

The multi-index set defining the interpolating polynomial.

to_newton()[source]#

Return the interpolant as a polynomial in the Newton basis.

Returns:

The interpolating polynomial represented in the Newton basis.

Return type:

NewtonPolynomial

to_lagrange()[source]#

Return the interpolant as a polynomial in the Lagrange basis.

Returns:

The interpolating polynomial represented in the Lagrange basis.

Return type:

LagrangePolynomial

to_canonical()[source]#

Return the interpolant as a polynomial in the canonical basis.

Returns:

The interpolating polynomial represented in the canonical (monomial) basis.

Return type:

CanonicalPolynomial

to_chebyshev()[source]#

Return the interpolant as a polynomial in the Chebyshev basis.

Returns:

The interpolating polynomial represented in the Chebyshev basis (of the first kind).

Return type:

ChebyshevPolynomial

__call__(xx, **kwargs)[source]#

Evaluate the interpolant on a given array of points.

Parameters:
  • xx (array_like) – Query points to evaluate. Can be a scalar, list, or numpy array. The points will be standardized to a two-dimensional array of shape (k, m) where k is the number of query points and m is the spatial dimension of the polynomial.

  • **kwargs – Additional keyword-only arguments that change the behavior of the underlying evaluation (see the concrete implementation of the interpolating polynomial).

Returns:

The values of the polynomial evaluated at query points.

Return type:

numpy.ndarray

class minterpy.interpolation.Interpolator(spatial_dimension, poly_degree, lp_degree, bounds=attr_dict['_bounds'].default)[source]#

The class for constructing polynomial interpolant.

The class contains all the relevant parts for constructing a polynomial interpolant in the Newton basis of a given callable. The instance of this class is a callable; passing a function to it will return an interpolating polynomial.

With an instance of this class, one can construct interpolants of the same underlying polynomial for different functions.

Parameters:
  • spatial_dimension (int) – The dimension of the interpolator.

  • poly_degree (int) – The degree of the interpolating polynomial.

  • lp_degree (float) – The degree \(p\) of the \(l_p\)-norm used to define the (multivariate) polynomial degree.

  • bounds (array_like, optional) – The bounds of the domain space, an array of shape (m, 2), where m is the spatial dimension. Each row corresponds to the lower and upper bounds of the domain in the corresponding dimension. If not provided, the bounds are assumed to be \([-1, 1]^m\).

multi_index#

The multi-index set used to define the interpolating polynomial, a lexicographically complete multi-index set, i.e., \(\mathcal{A}_{m, n, p}\), where \(m\) is spatial_dimension, \(n\) is poly_degree, and \(p\) is the lp_degree.

Type:

MultiIndexSet

grid#

The underlying interpolation grid with the domain defined by bounds.

Type:

Grid

Properties

domain

The domain of the interpolating polynomial.

lp_degree

\(p\) of \(l_p\)-norm used to define the multi-index set.

poly_degree

The degree of the interpolating polynomial (and multi-index set).

spatial_dimension

The dimension of the interpolator.

Methods

interpolate_values(func_values)

Interpolate a given array of values at the unisolvent nodes.

property spatial_dimension: int#

The dimension of the interpolator.

property poly_degree: int#

The degree of the interpolating polynomial (and multi-index set).

property lp_degree: float#

\(p\) of \(l_p\)-norm used to define the multi-index set.

property domain: Domain#

The domain of the interpolating polynomial.

__call__(func)[source]#

Interpolate a given function and return an interpolating polynomial.

Parameters:

func (Callable) – The function to interpolate. It must accept as the first argument a numpy.ndarray with shape (k, m), where k is the number of evaluation points and m is the spatial dimension. The function returns a numpy.ndarray with shape (k, ) for scalar outputs and (k, d) for vector outputs, where d is the output dimension.

Returns:

An interpolating polynomial of the function func in the Newton basis. The interpolating polynomial is constructed according to the underlying multi-index set and interpolation grid.

Return type:

NewtonPolynomial

Raises:

InterpolationError – If anything goes wrong with the interpolation.

interpolate_values(func_values)[source]#

Interpolate a given array of values at the unisolvent nodes.

Parameters:

func_values (array_like) – The function values at the unisolvent nodes (i.e., the Lagrange coefficients of the interpolating polynomial).

Returns:

An interpolating polynomial of the function func in the Newton basis. The interpolating polynomial is constructed according to the underlying multi-index set and interpolation grid.

Return type:

NewtonPolynomial

Raises:

InterpolationError – If anything goes wrong with the interpolation.