Inconsistent definition of poly_degree in MultiIndexSet
Given a non-complete multi-index set to create a MultiIndexSet
, the polynomial degree is inconsistently computed.
The Issue
Here's a reproducible example for this:
import numpy as np
import minterpy as mp
# An incomplete multi-index set
xx = np.array([
[0, 0],
[1, 0],
[0, 1],
[0, 2],
[1, 3]
])
mi = mp.MultiIndexSet(xx, lp_degree=1.0)
print(mi.poly_degree) # 3
print(mp.core.utils._get_poly_degree(xx, lp_degree=1.0) # 3
assert mi.poly_degree == mp.core.utils._get_poly_degree(xx, 1)
This is because the computation of the polynomial degree as an attribute of MultiIndexSet
is simply taken as the maximum exponent (independent of the lp-degree) and
therefore not consistent with how the degree should be computed (i.e., using the internal function mp.core.utils._get_poly_degree
that depends on the lp-degree as well).
The maximum exponent as degree is only valid for lp-degree equals to inf.
This also matters because if an incomplete multi-index set is made complete (via the method make_complete()
),
then the polynomial degree of the complete set has a different polynomial degree.
print(mi.poly_degree) # 3
print(mi.make_complete().poly_degree) # 4
I consider this as an unexpected behavior as well.
Another downstream issue found during the merging of the current dev
branch to the optimiser_refac
branch is related to Grid
.
Making a Grid
complete is making the underlying multi-index complete.
But because the polynomial degree of a Grid
is the polynomial degree of the underlying multi-index set,
making a Grid
complete and changing inadvertently the polynomial degree will fail because:
A grid of <grid.poly_degree> cannot consist of indices with degree <grid.multi_index.poly_degree>
Test coverage
Creating an incomplete multi-index set (with or without making it complete afterward) is not yet covered in the current test suite.
A Solution
Use the internal utility function mp.core.utils._get_poly_degree
to compute the polynomial degree of a MultiIndexSet
.