Create a Multi-Index Set#
import minterpy as mp
import numpy as np
A Minterpy polynomial is defined with respect to a multi-index set; the set defines the polynomial exponents across different spatial dimensions. This guide provides an example on how-to construct a multi-index set in Minterpy using different constructors.
Currently, Minterpy supports the creation of a multi-index set via two constructors:
minterpy.MultiIndexSet.from_degree()
is used to create a complete multi-index set with a given spatial dimension, polynomial degree, and \(l_p\)-degreeminterpy.MultiIndexSet()
(the default constructor) is used to create a multi-index set with a given set of exponents and \(l_p\)-degree
From a given spatial dimension, polynomial degree, and \(l_p\)-degree#
The constructor minterpy.MultiIndexSet.from_degree()
can be used to create a complete multi-index set for a given spatial dimension, degree, and \(l_p\)-degree.
The constructor takes the following (positional) arguments:
spatial_dimension
: the number of spatial dimensions (\(m\)) of the multi-index set (must be an integer \(> 0\))poly_degree
: the polynomial degree (\(n\)) of the multi-index set (must be an integer \(\geq 0\))lp_degree
: the degree \(p\) of the \(l_p\)-norm of the multi-index set (optional but must be a positive float; if not given, a default value of \(2.0\) is used)
Note
The set constructed via from_degree()
constructor is complete in the sense that it contains all the exponents \(\boldsymbol{\alpha} = \left( \alpha_1, \ldots, \alpha_m \right) \in \mathbb{N}^m\) such that the \(l_p\)-norm \(\lVert \boldsymbol{\alpha} \rVert_{p} = (\alpha_1^{p} + \ldots + \alpha_m^{p})^{\frac{1}{p}} \leq n\) holds.
Suppose we would like to create a multi-index set of spatial dimension \(3\), polynomial degree \(2\), and the default \(l_p\)-degree:
mi = mp.MultiIndexSet.from_degree(3, 2)
The resulting multi-index set can be printed to the terminal:
print(mi)
MultiIndexSet(m=3, n=2, p=2.0)
[[0 0 0]
[1 0 0]
[2 0 0]
[0 1 0]
[1 1 0]
[0 2 0]
[0 0 1]
[1 0 1]
[0 1 1]
[1 1 1]
[0 0 2]]
Note
The string produced by calling print()
includes the number m
, n
, and p
. In Minterpy these are the symbols conventionally used to represent spatial dimension, polynomial degree, and \(l_p\)-degree, respectively.
The MultiIndexSet
instance stores the exponents in the exponents
property:
print(mi.exponents)
[[0 0 0]
[1 0 0]
[2 0 0]
[0 1 0]
[1 1 0]
[0 2 0]
[0 0 1]
[1 0 1]
[0 1 1]
[1 1 1]
[0 0 2]]
The exponents
property is a NumPy integer array with the given spatial dimension as the number of columns. The first column corresponds to the exponents of polynomial basis of the first dimension, the second column the second dimension, etc.
The number of elements of the resulting multi-index set is determined by the choice of the parameters such that the resulting set is complete. In the example above, the set contains all the exponents \(\boldsymbol{\alpha} = \left( \alpha_1, \alpha_2, \alpha_3 \right)\) such that \(\lVert \boldsymbol{\alpha} \rVert_{2.0} = \left( \alpha_1^{2.0} + \alpha_2^{2.0} + \alpha_3^{2.0} \right)^{\frac{1}{2.0}} \leq 2\).
From a given set of exponents and \(l_p\)-degree#
Alternatively, a MultiIndexSet
instance can be constructed by passing a set of exponents and the corresponding \(l_p\)-degree using the default constructor (minterpy.MultiIndexSet()
). The set of exponents must be given as a NumPy integer array.
Suppose we would like to create a multi-index set with the following exponents:
having \(l_p\)-degree of \(1.0\). Notice that from the given set of exponents, the spatial dimension of the multi-index set is \(2\).
Create and store the exponents as a NumPy integer array:
exps = np.array([[0, 0], [1, 0], [0, 1], [0, 2], [0, 3]], dtype=int)
exps
array([[0, 0],
[1, 0],
[0, 1],
[0, 2],
[0, 3]])
mi = mp.MultiIndexSet(exps, lp_degree=1.0)
Verify that the resulting MultiIndexSet
instance has the exponents as given:
print(mi)
MultiIndexSet(m=2, n=3, p=1.0)
[[0 0]
[1 0]
[0 1]
[0 2]
[0 3]]
…and the \(l_p\)-degree as given:
print(mi.lp_degree)
1.0
Notice that the resulting multi-index set has its exponents lexicographically sorted.
The spatial dimension of the multi-index set is inferred from the given exponents (i.e., the number of columns of the exponents):
print(mi.spatial_dimension)
2
The polynomial degree of the multi-index set is also inferred from the given exponents and the \(l_p\)-degree (the \(l_p\)-degree, on the other hand, cannot be inferred from the exponents and therefore must be provided):
print(mi.poly_degree)
3
The number above corresponds the smallest degree \(n\) such that the \(l_p\)-norm \(\lVert \boldsymbol{\alpha} \rVert_{p} = (\alpha_1^p + \alpha_2^p + \alpha_3^p)^{\frac{1}{p}} \leq 3 = n\) holds (with \(p\) in \(l_p\) equals to \(1.0\)).
Note
When the default constructor is used to create an instance of MultiIndexSet
, the \(l_p\)-degree is a mandatory argument. Minterpy cannot infer the \(l_p\)-degree from a given set of exponents; in other words, a multi-index set can be defined for any given set of exponents and \(l_p\)-degree (\(p \in \mathbb{R}_{>0})\).