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 a given function |
|
Class that represents an interpolated function |
|
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.ndarraywith shape(k, m), wherekis the number of evaluation points andmis the spatial dimension. The function returns anumpy.ndarraywith shape(k, )for scalar outputs and(k, d)for vector outputs, wheredis 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), wheremis 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
funcwith respect to the lexicographically complete multi-index set \(\mathcal{A}_{m, n, p}\) where \(m\) isspatial_dimension, \(n\) ispoly_degree, and \(p\) islp_degree.- Return type:
- 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.ndarraywith shape(k, m), wherekis the number of evaluation points andmis the spatial dimension. The function returns anumpy.ndarraywith shape(k, )for scalar outputs and(k, d)for vector outputs, wheredis the output dimension.interpolator (Interpolator) – The underlying setting for the interpolation.
Properties
\(p\) of \(l_p\)-norm used to define the multi-index set.
The multi-index set defining the interpolating polynomial.
The degree of the interpolating polynomial.
The dimension of the interpolator.
Methods
from_degree(func, spatial_dimension, ...[, ...])Create an interpolant with respect to a complete multi-index set.
Return the interpolant as a polynomial in the canonical basis.
Return the interpolant as a polynomial in the Chebyshev basis.
Return the interpolant as a polynomial in the Lagrange basis.
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.ndarraywith shape(k, m), wherekis the number of evaluation points andmis the spatial dimension. The function returns anumpy.ndarraywith shape(k, )for scalar outputs and(k, d)for vector outputs, wheredis 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), wheremis 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
funcusing an interpolating polynomial with respect to complete multi-index set.- Return type:
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 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:
- to_lagrange()[source]#
Return the interpolant as a polynomial in the Lagrange basis.
- Returns:
The interpolating polynomial represented in the Lagrange basis.
- Return type:
- 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:
- 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:
- __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)wherekis the number of query points andmis 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:
- 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), wheremis 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\) ispoly_degree, and \(p\) is thelp_degree.- Type:
Properties
The domain of the interpolating polynomial.
\(p\) of \(l_p\)-norm used to define the multi-index set.
The degree of the interpolating polynomial (and multi-index set).
The dimension of the interpolator.
Methods
interpolate_values(func_values)Interpolate a given array of values at the unisolvent nodes.
- __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.ndarraywith shape(k, m), wherekis the number of evaluation points andmis the spatial dimension. The function returns anumpy.ndarraywith shape(k, )for scalar outputs and(k, d)for vector outputs, wheredis the output dimension.- Returns:
An interpolating polynomial of the function
funcin the Newton basis. The interpolating polynomial is constructed according to the underlying multi-index set and interpolation grid.- Return type:
- 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
funcin the Newton basis. The interpolating polynomial is constructed according to the underlying multi-index set and interpolation grid.- Return type:
- Raises:
InterpolationError – If anything goes wrong with the interpolation.