def test_from_data_qr(self): t = np.linspace(0, 1, 5) x = np.sin(2 * np.pi * t) + np.cos(2 * np.pi * t) basis = BSpline((0, 1), n_basis=5) np.testing.assert_array_almost_equal( FDataBasis.from_data(x, t, basis, method='qr').coefficients.round(2), np.array([[1., 2.78, -3., -0.78, 1.]]))
def test_from_data_qr(self): t = np.linspace(0, 1, 5) x = np.sin(2 * np.pi * t) + np.cos(2 * np.pi * t) basis = BSpline((0, 1), nbasis=5) np.testing.assert_array_almost_equal( FDataBasis.from_data(x, t, basis, smoothness_parameter=10, penalty_degree=2, method='qr' ).coefficients.round(2), np.array([[0.60, 0.47, 0.20, -0.07, -0.20]]) )
def test_monomial_smoothing(self): # It does not have much sense to apply smoothing in this basic case # where the fit is very good but its just for testing purposes t = np.linspace(0, 1, 5) x = np.sin(2 * np.pi * t) + np.cos(2 * np.pi * t) basis = Monomial(nbasis=4) fd = FDataBasis.from_data(x, t, basis, penalty_degree=2, smoothness_parameter=1) # These results where extracted from the R package fda np.testing.assert_array_almost_equal( fd.coefficients.round(2), np.array([[0.61, -0.88, 0.06, 0.02]]))