def test_fdatabasis_derivative_monomial(self): monomial = FDataBasis(Monomial(nbasis=8), [1, 5, 8, 9, 7, 8, 4, 5]) monomial2 = FDataBasis(Monomial(nbasis=5), [[4, 9, 7, 4, 3], [1, 7, 9, 8, 5], [4, 6, 6, 6, 8]]) np.testing.assert_equal(monomial.derivative(), FDataBasis(Monomial(nbasis=7), [5, 16, 27, 28, 40, 24, 35])) np.testing.assert_equal(monomial.derivative(order=0), monomial) np.testing.assert_equal(monomial.derivative(order=6), FDataBasis(Monomial(nbasis=2), [2880, 25200])) np.testing.assert_equal(monomial2.derivative(), FDataBasis(Monomial(nbasis=4), [[9, 14, 12, 12], [7, 18, 24, 20], [6, 12, 18, 32]])) np.testing.assert_equal(monomial2.derivative(order=0), monomial2) np.testing.assert_equal(monomial2.derivative(order=3), FDataBasis(Monomial(nbasis=2), [[24, 72], [48, 120], [36, 192]]))
def test_fdatabasis_derivative_constant(self): constant = FDataBasis(Constant(), [[1], [2], [3], [4]]) self.assertTrue(constant.derivative().equals( FDataBasis(Constant(), [[0], [0], [0], [0]]))) self.assertTrue( constant.derivative(order=0).equals( FDataBasis(Constant(), [[1], [2], [3], [4]])))
def test_fdatabasis_derivative_bspline(self): bspline = FDataBasis(BSpline(n_basis=8), [1, 5, 8, 9, 7, 8, 4, 5]) bspline2 = FDataBasis( BSpline(n_basis=5), [[4, 9, 7, 4, 3], [1, 7, 9, 8, 5], [4, 6, 6, 6, 8]]) bs0 = bspline.derivative(order=0) bs1 = bspline.derivative() bs2 = bspline.derivative(order=2) np.testing.assert_equal(bs1.basis, BSpline(n_basis=7, order=3)) np.testing.assert_almost_equal( bs1.coefficients, np.atleast_2d([60, 22.5, 5, -10, 5, -30, 15])) np.testing.assert_equal(bs0, bspline) np.testing.assert_equal(bs2.basis, BSpline(n_basis=6, order=2)) np.testing.assert_almost_equal( bs2.coefficients, np.atleast_2d([-375, -87.5, -75, 75, -175, 450])) bs0 = bspline2.derivative(order=0) bs1 = bspline2.derivative() bs2 = bspline2.derivative(order=2) np.testing.assert_equal(bs1.basis, BSpline(n_basis=4, order=3)) np.testing.assert_almost_equal( bs1.coefficients, [[30, -6, -9, -6], [36, 6, -3, -18], [12, 0, 0, 12]]) np.testing.assert_equal(bs0, bspline2) np.testing.assert_equal(bs2.basis, BSpline(n_basis=3, order=2)) np.testing.assert_almost_equal( bs2.coefficients, [[-144, -6, 12], [-120, -18, -60], [-48, 0, 48]])
def test_evaluation_derivative_monomial(self): """Test the evaluation of the derivative of a 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) f_deriv = f.derivative() np.testing.assert_array_almost_equal( f_deriv(t).round(3), np.array([[2., 4., 6., 8.], [1.4, 2.267, 3.133, 4.]])[..., np.newaxis])
def test_evaluation_derivative_bspline(self): """Test the evaluation of the derivative of a FDataBasis""" bspline = BSpline(domain_range=(0, 1), n_basis=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) f_deriv = f.derivative() np.testing.assert_array_almost_equal( f_deriv(t).round(3), np.array([[2.927, 0.453, -1.229, 0.6], [4.3, -1.599, 1.016, -2.52]])[..., np.newaxis])
def test_evaluation_derivative_fourier(self): """Test the evaluation of the derivative of a FDataBasis""" fourier = Fourier(domain_range=(0, 1), n_basis=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([ 4.34138447771721, -7.09352774867064, 2.75214327095343, 4.34138447771721, 6.52573053999253, -4.81336320468984, -1.7123673353027, 6.52573053999253 ]).reshape((2, 4, 1)).round(3) f_deriv = f.derivative() np.testing.assert_array_almost_equal(f_deriv(t).round(3), res)
def test_fdatabasis_derivative_fourier(self): fourier = FDataBasis(Fourier(n_basis=7), [1, 5, 8, 9, 8, 4, 5]) fourier2 = FDataBasis( Fourier(n_basis=5), [[4, 9, 7, 4, 3], [1, 7, 9, 8, 5], [4, 6, 6, 6, 8]]) fou0 = fourier.derivative(order=0) fou1 = fourier.derivative() fou2 = fourier.derivative(order=2) np.testing.assert_equal(fou1.basis, fourier.basis) np.testing.assert_almost_equal( fou1.coefficients.round(5), np.atleast_2d([ 0, -50.26548, 31.41593, -100.53096, 113.09734, -94.24778, 75.39822 ])) np.testing.assert_equal(fou0, fourier) np.testing.assert_equal(fou2.basis, fourier.basis) np.testing.assert_almost_equal( fou2.coefficients.round(5), np.atleast_2d([ 0, -197.39209, -315.82734, -1421.22303, -1263.30936, -1421.22303, -1776.52879 ])) fou0 = fourier2.derivative(order=0) fou1 = fourier2.derivative() fou2 = fourier2.derivative(order=2) np.testing.assert_equal(fou1.basis, fourier2.basis) np.testing.assert_almost_equal( fou1.coefficients.round(5), [[0, -43.98230, 56.54867, -37.69911, 50.26548], [0, -56.54867, 43.98230, -62.83185, 100.53096], [0, -37.69911, 37.69911, -100.53096, 75.39822]]) np.testing.assert_equal(fou0, fourier2) np.testing.assert_equal(fou2.basis, fourier2.basis) np.testing.assert_almost_equal( fou2.coefficients.round(5), [[0, -355.30576, -276.34892, -631.65468, -473.74101], [0, -276.34892, -355.30576, -1263.30936, -789.56835], [0, -236.87051, -236.87051, -947.48202, -1263.30936]])