.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/representation/plot_irregular_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_irregular_functional.py: Representation of univariate and irregular 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 IrregularFunctionalData from FDApy.representation import DenseArgvals, IrregularArgvals, IrregularValues 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 irregular functional data. To define a :class:`~FDApy.representation.IrregularFunctionalData` object, we need a set of :class:`~FDApy.representation.IrregularArgvals` (the sampling points of the curves) and a set of :class:`~FDApy.representation.IrregularValues` (the observed points of the curves). The sampling points of the data are defined as a dictionary where each entry corresponds to an observation. Each entry of the dictionary corresponds to the sampling points of one observation and is represented as a :class:`~FDApy.representation.DenseArgvals`. The values of the functional data are defined in a dictionary where each entry represents an observation as an :class:`~numpy.ndarray`. Each entry should have the same dimension has the corresponding entry in the :class:`~FDApy.representation.IrregularArgvals` dictionary. .. GENERATED FROM PYTHON SOURCE LINES 21-24 For unidimensional functional data ---------------------------------- First, we will define unidimensional irregular functional data. We represent two observations of a functional data irregularly sampled on a set of points. The first observation in sampled on :math:`20` points between :math:`0` and :math:`1` and the second observation is sampled on :math:`15` points between :math:`0.2` and :math:`0.8`. The values of the functional data is a dictionary where each entry corresponds to the observed values of one observation. .. GENERATED FROM PYTHON SOURCE LINES 24-43 .. code-block:: Python argvals = IrregularArgvals( { 0: DenseArgvals({"input_dim_0": np.linspace(0, 1, num=20)}), 1: DenseArgvals({"input_dim_0": np.linspace(0.2, 0.8, num=15)}), } ) X = IrregularValues( { 0: np.sin(2 * np.pi * argvals[0]["input_dim_0"]), 1: np.cos(2 * np.pi * argvals[1]["input_dim_0"]), } ) fdata = IrregularFunctionalData(argvals=argvals, values=X) _ = plot(fdata) .. image-sg:: /auto_examples/representation/images/sphx_glr_plot_irregular_functional_001.png :alt: plot irregular functional :srcset: /auto_examples/representation/images/sphx_glr_plot_irregular_functional_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 44-47 For two-dimensional functional data ----------------------------------- Second, we will consider two-dimensional functional data where the observations are not sampled on the same grid. We represent two observations of a functional data irregularly sampled on a set of points. The first observation is sampled on a grid of :math:`20 \times 20` sampling points and the second observation is sampled on a grid of :math:`15 \times 15` sampling points. The values of the functional data is a dictionary where each entry corresponds to the observed values of one observation. .. GENERATED FROM PYTHON SOURCE LINES 47-79 .. code-block:: Python argvals = IrregularArgvals( { 0: DenseArgvals( { "input_dim_0": np.linspace(0, 1, num=20), "input_dim_1": np.linspace(0, 1, num=20), } ), 1: DenseArgvals( { "input_dim_0": np.linspace(0.2, 0.8, num=15), "input_dim_1": np.linspace(0.2, 0.8, num=15), } ), } ) X = IrregularValues( { 0: np.outer( np.sin(argvals[0]["input_dim_0"]), np.cos(argvals[0]["input_dim_1"]) ), 1: np.outer( np.sin(-argvals[1]["input_dim_0"]), np.cos(argvals[1]["input_dim_1"]) ), } ) fdata = IrregularFunctionalData(argvals=argvals, values=X) _ = plot(fdata) .. image-sg:: /auto_examples/representation/images/sphx_glr_plot_irregular_functional_002.png :alt: plot irregular functional :srcset: /auto_examples/representation/images/sphx_glr_plot_irregular_functional_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 80-83 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 dimension in 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.349 seconds) .. _sphx_glr_download_auto_examples_representation_plot_irregular_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_irregular_functional.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_irregular_functional.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_irregular_functional.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_