def test_domain_in_list_bspline(self): """Test the evaluation of FDataBasis""" for bspline in (BSpline(domain_range=[(0, 1)], nbasis=5, order=3), BSpline(domain_range=((0, 1),), nbasis=5, order=3), BSpline(domain_range=np.array((0, 1)), nbasis=5, order=3), BSpline(domain_range=np.array([(0, 1)]), nbasis=5, order=3) ): coefficients = [[0.00078238, 0.48857741, 0.63971985, 0.23, 0.33], [0.01778079, 0.73440271, 0.20148638, 0.54, 0.12]] f = FDataBasis(bspline, coefficients) t = np.linspace(0, 1, 4) res = np.array([[0.001, 0.564, 0.435, 0.33], [0.018, 0.468, 0.371, 0.12]]) np.testing.assert_array_almost_equal(f(t).round(3), res) np.testing.assert_array_almost_equal(f.evaluate(t).round(3), res) # Check error with np.testing.assert_raises(ValueError): BSpline(domain_range=[(0, 1), (0, 1)])
def test_evaluation_simple_monomial(self): """Test the evaluation of FDataBasis""" monomial = Monomial(domain_range=(0, 1), n_basis=3) coefficients = [[1, 2, 3], [0.5, 1.4, 1.3]] f = FDataBasis(monomial, coefficients) t = np.linspace(0, 1, 4) res = np.array([[1., 2., 3.667, 6.], [0.5, 1.111, 2.011, 3.2]]) np.testing.assert_array_almost_equal(f(t).round(3), res) np.testing.assert_array_almost_equal(f.evaluate(t).round(3), res)
def test_evaluation_simple_bspline(self): """Test the evaluation of FDataBasis""" bspline = BSpline(domain_range=(0, 1), nbasis=5, order=3) coefficients = [[0.00078238, 0.48857741, 0.63971985, 0.23, 0.33], [0.01778079, 0.73440271, 0.20148638, 0.54, 0.12]] f = FDataBasis(bspline, coefficients) t = np.linspace(0, 1, 4) res = np.array([[0.001, 0.564, 0.435, 0.33], [0.018, 0.468, 0.371, 0.12]]) np.testing.assert_array_almost_equal(f(t).round(3), res) np.testing.assert_array_almost_equal(f.evaluate(t).round(3), res)
def test_evaluation_simple_fourier(self): """Test the evaluation of FDataBasis""" fourier = Fourier(domain_range=(0, 1), nbasis=3) coefficients = np.array([[0.00078238, 0.48857741, 0.63971985], [0.01778079, 0.73440271, 0.20148638]]) f = FDataBasis(fourier, coefficients) t = np.linspace(0, 1, 4) res = np.array([0.905482867989282, 0.146814813180645, -1.04995054116993, 0.905482867989282, 0.302725561229459, 0.774764356993855, -1.02414754822331, 0.302725561229459] ).reshape((2, 4)).round(3) np.testing.assert_array_almost_equal(f(t).round(3), res) np.testing.assert_array_almost_equal(f.evaluate(t).round(3), res)
def test_evaluation_simple_bspline(self): """Test the evaluation of FDataBasis""" bspline = BSpline(domain_range=(0, 2), n_basis=5) coefficients = np.array([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]]) f = FDataBasis(bspline, coefficients) t = np.linspace(0, 2, 11) # Results in R package fda res = np.array( [[1, 1.54, 1.99, 2.37, 2.7, 3, 3.3, 3.63, 4.01, 4.46, 5], [6, 6.54, 6.99, 7.37, 7.7, 8, 8.3, 8.63, 9.01, 9.46, 10]])[..., np.newaxis] np.testing.assert_array_almost_equal(f(t).round(2), res) np.testing.assert_array_almost_equal(f.evaluate(t).round(2), res)
def test_domain_in_list_monomial(self): """Test the evaluation of FDataBasis""" for monomial in (Monomial(domain_range=[(0, 1)], n_basis=3), Monomial(domain_range=((0, 1), ), n_basis=3), Monomial(domain_range=np.array((0, 1)), n_basis=3), Monomial(domain_range=np.array([(0, 1)]), n_basis=3)): coefficients = [[1, 2, 3], [0.5, 1.4, 1.3]] f = FDataBasis(monomial, coefficients) t = np.linspace(0, 1, 4) res = np.array([[1., 2., 3.667, 6.], [0.5, 1.111, 2.011, 3.2]]) np.testing.assert_array_almost_equal(f(t).round(3), res) np.testing.assert_array_almost_equal(f.evaluate(t).round(3), res)
def test_domain_in_list_fourier(self): """Test the evaluation of FDataBasis""" for fourier in (Fourier(domain_range=[(0, 1)], nbasis=3), Fourier(domain_range=((0, 1),), nbasis=3), Fourier(domain_range=np.array((0, 1)), nbasis=3), Fourier(domain_range=np.array([(0, 1)]), nbasis=3)): coefficients = np.array([[0.00078238, 0.48857741, 0.63971985], [0.01778079, 0.73440271, 0.20148638]]) f = FDataBasis(fourier, coefficients) t = np.linspace(0, 1, 4) res = np.array([0.905, 0.147, -1.05, 0.905, 0.303, 0.775, -1.024, 0.303]).reshape((2, 4)) np.testing.assert_array_almost_equal(f(t).round(3), res) np.testing.assert_array_almost_equal(f.evaluate(t).round(3), res)
def test_evaluation_simple_fourier(self): """Test the evaluation of FDataBasis""" fourier = Fourier(domain_range=(0, 2), n_basis=5) coefficients = np.array([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]]) f = FDataBasis(fourier, coefficients) t = np.linspace(0, 2, 11) # Results in R package fda res = np.array([[ 8.71, 9.66, 1.84, -4.71, -2.80, 2.71, 2.45, -3.82, -6.66, -0.30, 8.71 ], [ 22.24, 26.48, 10.57, -4.95, -3.58, 6.24, 5.31, -7.69, -13.32, 1.13, 22.24 ]])[..., np.newaxis] np.testing.assert_array_almost_equal(f(t).round(2), res) np.testing.assert_array_almost_equal(f.evaluate(t).round(2), res)
def test_evaluation_simple_monomial(self): """Test the evaluation of FDataBasis""" monomial = Monomial(domain_range=(0, 2), n_basis=5) coefficients = np.array([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]]) f = FDataBasis(monomial, coefficients) t = np.linspace(0, 2, 11) # Results in R package fda res = np.array([[ 1.00, 1.56, 2.66, 4.79, 8.62, 15.00, 25.00, 39.86, 61.03, 90.14, 129.00 ], [ 6.00, 7.81, 10.91, 16.32, 25.42, 40.00, 62.21, 94.59, 140.08, 201.98, 284.00 ]])[..., np.newaxis] np.testing.assert_array_almost_equal(f(t).round(2), res) np.testing.assert_array_almost_equal(f.evaluate(t).round(2), res)