.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/representation/plot_dense_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_dense_functional.py: Representation of univariate and dense functional data ====================================================== .. GENERATED FROM PYTHON SOURCE LINES 6-17 .. code-block:: Python # Author: Steven Golovkine # License: MIT # Load packages import numpy as np from FDApy import DenseFunctionalData from FDApy.representation import DenseArgvals, DenseValues from FDApy.visualization import plot .. GENERATED FROM PYTHON SOURCE LINES 18-19 In this section, we are showing the building blocks of the representation of univariate and dense functional data. To define a :class:`~FDApy.representation.DenseFunctionalData` object, we need a set of :class:`~FDApy.representation.DenseArgvals` (the sampling points of the curves) and a set of :class:`~FDApy.representation.DenseValues` (the observed points of the curves). The sampling points of the functional data are defined as a dictionary where each entry is a one-dimensional numpy :class:`~numpy.ndarray` that represents an input dimension (one entry corresponds to curves, two entries correspond to surface, ...). The shape of the array of the first dimension would be :math:`(m_1,)`, the shape of the array of the second dimension would be :math:`(m_2,)` and so on. Curves will thus be sampled on :math:`m_1` points, surface will be sampled on :math:`m_1 \times m_2`, etc. The values of the functional data are defined as an :class:`~numpy.ndarray`. The shape of the array is :math:`(n, m_1, m_2, \dots)` where :math:`n` is the number of curves in the sample. .. GENERATED FROM PYTHON SOURCE LINES 21-24 For unidimensional functional data ---------------------------------- First, we will consider unidimensional dense functional data. We represent two observations of a functional data regularly sampled on a hundred points between :math:`0` and :math:`\pi`. The shape of the array of the values is :math:`(2, 100)`. The first dimension corresponds to the number of curves and the second dimension corresponds to the input dimension. .. GENERATED FROM PYTHON SOURCE LINES 24-35 .. code-block:: Python argvals = np.linspace(0, np.pi, num=100) X = np.array([np.sin(2 * np.pi * argvals), np.cos(2 * np.pi * argvals)]) fdata = DenseFunctionalData( argvals=DenseArgvals({"input_dim_0": argvals}), values=DenseValues(X) ) _ = plot(fdata) .. image-sg:: /auto_examples/representation/images/sphx_glr_plot_dense_functional_001.png :alt: plot dense functional :srcset: /auto_examples/representation/images/sphx_glr_plot_dense_functional_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 36-39 For two-dimensional functional data ----------------------------------- Second, we will consider two-dimensional dense functional data. We represent two observations of a functional data regularly sampled on a hundred points between :math:`0` and :math:`\pi` for each dimension. The shape of the array of the values is :math:`(2, 100, 100)`. The first dimension corresponds to the number of curves, the second dimension corresponds to the first input dimension and the third dimension corresponds to the second input dimension. .. GENERATED FROM PYTHON SOURCE LINES 39-55 .. code-block:: Python argvals = np.linspace(0, np.pi, num=100) X = np.array( [ np.outer(np.sin(argvals), np.cos(argvals)), np.outer(np.sin(-argvals), np.cos(argvals)), ] ) fdata = DenseFunctionalData( argvals=DenseArgvals({"input_dim_0": argvals, "input_dim_1": argvals}), values=DenseValues(X), ) _ = plot(fdata) .. image-sg:: /auto_examples/representation/images/sphx_glr_plot_dense_functional_002.png :alt: plot dense functional :srcset: /auto_examples/representation/images/sphx_glr_plot_dense_functional_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 56-59 For higher-dimensional functional data -------------------------------------- It is possible to define functional data with more than two dimensions. All you have to do is to add more entries in the dictionary of the argvals and another dimension in the values array. However, no plotting function is available for data with more than two dimensions. .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.743 seconds) .. _sphx_glr_download_auto_examples_representation_plot_dense_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_dense_functional.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_dense_functional.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_dense_functional.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_