.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_composition.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 or to run this example in your browser via Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_plot_composition.py: Function composition ==================== This example shows the composition of multidimensional FDataGrids. .. GENERATED FROM PYTHON SOURCE LINES 7-18 .. code-block:: Python # Author: Pablo Marcos Manchón # License: MIT # sphinx_gallery_thumbnail_number = 3 import numpy as np from mpl_toolkits.mplot3d import axes3d import skfda .. GENERATED FROM PYTHON SOURCE LINES 19-37 Function composition can be applied to our data once is in functional form using the method :func:`~skfda.representation.FData.compose`. Let :math:`f: X \rightarrow Y` and :math:`g: Y \rightarrow Z`, the composition will produce a third function :math:`g \circ f: X \rightarrow Z` which maps :math:`x \in X` to :math:`g(f(x))` [1]. In :ref:`sphx_glr_auto_examples_plot_landmark_registration.py` it is shown the simplest case, where it is used to apply a transformation of the time scale of unidimensional data to register its features. The following example shows the basic usage applied to a surface and a curve, although the method will work for data with arbitrary dimensions to. Firstly we will create a data object containing a surface :math:`g: \mathbb{R}^2 \rightarrow \mathbb{R}`. Constructs example surface .. GENERATED FROM PYTHON SOURCE LINES 37-46 .. code-block:: Python X, Y, Z = axes3d.get_test_data(1.2) data_matrix = [Z.T] grid_points = [X[0, :], Y[:, 0]] g = skfda.FDataGrid(data_matrix, grid_points) # Plots the surface g.plot() .. image-sg:: /auto_examples/images/sphx_glr_plot_composition_001.png :alt: plot composition :srcset: /auto_examples/images/sphx_glr_plot_composition_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none
.. GENERATED FROM PYTHON SOURCE LINES 47-52 We will create a parametric curve :math:`f(t)=(10 \, \cos(t), 10 \, sin(t))`. The result of the composition, :math:`g \circ f:\mathbb{R} \rightarrow \mathbb{R}` will be another functional object with the values of :math:`g` along the path given by :math:`f`. .. GENERATED FROM PYTHON SOURCE LINES 52-65 .. code-block:: Python # Creation of circunference in parametric form t = np.linspace(0, 2 * np.pi, 100) data_matrix = [10 * np.array([np.cos(t), np.sin(t)]).T] f = skfda.FDataGrid(data_matrix, t) # Composition of function gof = g.compose(f) gof.plot() .. image-sg:: /auto_examples/images/sphx_glr_plot_composition_002.png :alt: plot composition :srcset: /auto_examples/images/sphx_glr_plot_composition_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none
.. GENERATED FROM PYTHON SOURCE LINES 66-68 In the following chart it is plotted the curve :math:`(10 \, \cos(t), 10 \, sin(t), g \circ f (t))` and the surface. .. GENERATED FROM PYTHON SOURCE LINES 68-78 .. code-block:: Python # Plots surface fig = g.plot(alpha=0.8) # Plots path along the surface path = f(t)[0] fig.axes[0].plot(path[:, 0], path[:, 1], gof(t)[0, ..., 0], color="orange") fig .. image-sg:: /auto_examples/images/sphx_glr_plot_composition_003.png :alt: plot composition :srcset: /auto_examples/images/sphx_glr_plot_composition_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none
.. GENERATED FROM PYTHON SOURCE LINES 79-81 [1] Function composition `https://en.wikipedia.org/wiki/Function_composition `_. .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.496 seconds) .. _sphx_glr_download_auto_examples_plot_composition.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/GAA-UAM/scikit-fda/develop?filepath=examples/plot_composition.py :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_composition.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_composition.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_