DDS does not work for lp-degree less than 1.0
It appears DDS does not work for lp-degree less than 1.0. Here's a reproducible example that shows the evaluation of a canonical polynomial does not coincide with the evaluation of the corresponding Newton polynomial:
import numpy as np
import minterpy as mp
mi = mp.MultiIndexSet.from_degree(2, 3, 0.5) # No interaction between the two variables
def fun(xx):
"""Polynomial test function where there is no interaction between variables."""
return 10 + 1 * xx[:,0] + 2 * xx[:,0]**2 + 3 * xx[:,0]**3 + 1 * xx[:,1] + 2 * xx[:,1]**2 + 3 * xx[:,1]**3
xx_test = -1 + 2 * np.random.rand(1000, 2)
can_poly = mp.CanonicalPolynomial(mi, coeffs=np.array([10., 1., 2., 3., 1., 2., 3.]))
nwt_poly = mp.CanonicalToNewton(can_poly)()
# This assertion is successful
assert np.allclose(can_poly(xx_test), fun(xx_test))
# But this assertion will fail
assert np.allclose(nwt_poly(xx_test), can_poly(xx_test))
Or exemplified another way, the Newton polynomial evaluation on the unisolvent nodes does not coincide with the Lagrange coefficients:
# or if we create a Lagrange polynomial first
grd = mp.Grid(mi)
lag_poly = mp.LagrangePolynomial(mi, fun(grd.unisolvent_nodes))
nwt_poly = mp.LagrangeToNewton(lag_poly)()
# This assertion will also fail (the Newton polynomial evaluation on the unisolvent nodes does not coincide with the Lagrange polynomial coefficients, which is troubling)
assert np.allclose(nwt_poly(grd.unisolvent_nodes), lag_poly.coeffs)
# nwt_poly eval : array([14. , 6. , 9.375 , 7.625 , 22. , 16.3046875, 20.1015625]),
# lag_poly coeffs: array([14. , 6. , 9.375, 7.625, 22. , 15.625, 17.375]))
This error can also be captured by including any lp-degree of less than 1.0 in the test fixture lp_degree
in the conftest.py
file.
In the applied metamodeling literature, lp-degree of less than 1.0 is known as the hyperbolic truncation scheme. It is of interest in many engineering models as these models often exhibit sparsity-of-effects where high-degree interactions between input variables are not observed. For such models, we might get away with a more compact polynomial model.
As far as I understand things, there is no reason for DDS to not work in this case as the resulting multi-index is still downward close.
After a preliminary investigation, I think I know what's the problem. There seems to be a problem with the current implementation of tree construction. I'm already working on a solution for this and currently testing its performance. The merge request for a fix is coming in few days.