.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/representation/plot_basis_functional.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_representation_plot_basis_functional.py: Representation of functional data using a basis =============================================== .. GENERATED FROM PYTHON SOURCE LINES 6-18 .. code-block:: Python # Author: Steven Golovkine # License: MIT # Load packages import matplotlib.pyplot as plt import numpy as np from FDApy.representation import Basis, BasisFunctionalData from FDApy.representation import DenseArgvals from FDApy.visualization import plot .. GENERATED FROM PYTHON SOURCE LINES 19-20 In this section, we are showing the building blocks of the representation of functional data using a basis. To define a :class:`~FDApy.representation.BasisFunctionalData` object, we need a :class:`~FDApy.representation.Basis` object and a set of coefficients. The basis object contains the information about the basis functions and the argvals. The coefficients are the weights of the basis functions. The basis functions are evaluated at the argvals and multiplied by the coefficients to obtain the functional data. .. GENERATED FROM PYTHON SOURCE LINES 23-26 For unidimensional functional data ---------------------------------- First, we will consider unidimensional functional data. We represent a functional data using a Fourier basis. The coefficients are drawn from a normal distribution. .. GENERATED FROM PYTHON SOURCE LINES 26-39 .. code-block:: Python n_functions = 5 argvals = DenseArgvals({"input_dim_0": np.linspace(0, 1, 101)}) basis = Basis(name="fourier", n_functions=n_functions, argvals=argvals) coefs = np.random.normal(size=(3, n_functions)) data = BasisFunctionalData(basis=basis, coefficients=coefs) plot(data) plt.show() .. image-sg:: /auto_examples/representation/images/sphx_glr_plot_basis_functional_001.png :alt: plot basis functional :srcset: /auto_examples/representation/images/sphx_glr_plot_basis_functional_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 40-43 For two-dimensional functional data ----------------------------------- Second, we will consider two-dimensional functional data. We represent a functional data using a tensor product of two Fourier basis. The coefficients are drawn from a normal distribution. .. GENERATED FROM PYTHON SOURCE LINES 43-57 .. code-block:: Python name = ("fourier", "fourier") n_functions = (5, 5) argvals = DenseArgvals( {"input_dim_0": np.linspace(0, 1, 101), "input_dim_1": np.linspace(0, 1, 51)} ) basis = Basis(name=name, n_functions=n_functions, argvals=argvals) coefs = np.random.normal(size=(3, np.prod(n_functions))) data_2d = BasisFunctionalData(basis=basis, coefficients=coefs) plot(data_2d) plt.show() .. image-sg:: /auto_examples/representation/images/sphx_glr_plot_basis_functional_002.png :alt: plot basis functional :srcset: /auto_examples/representation/images/sphx_glr_plot_basis_functional_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.510 seconds) .. _sphx_glr_download_auto_examples_representation_plot_basis_functional.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_basis_functional.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_basis_functional.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_basis_functional.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_