.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/dimension_reduction/grassmann/plot_grassmann_log_exp.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_dimension_reduction_grassmann_plot_grassmann_log_exp.py: Mappings to & from tangent space ================================== This example shows how to use the UQpy Grassmann class to use the logarithmic map and the exponential map .. GENERATED FROM PYTHON SOURCE LINES 10-12 Import the necessary libraries. Here we import standard libraries such as numpy and matplotlib, but also need to import the Grassmann class from UQpy implemented in the DimensionReduction module. .. GENERATED FROM PYTHON SOURCE LINES 15-22 .. code-block:: default import matplotlib.pyplot as plt import numpy as np from UQpy.dimension_reduction import GrassmannOperations from UQpy.dimension_reduction.grassmann_manifold.projections.SVDProjection import SVDProjection .. GENERATED FROM PYTHON SOURCE LINES 23-25 Generate four random matrices with reduced rank corresponding to the different samples. The samples are stored in `matrices`. .. GENERATED FROM PYTHON SOURCE LINES 28-57 .. code-block:: default D1 = 6 r0 = 2 # rank sample 0 r1 = 3 # rank sample 1 r2 = 4 # rank sample 2 r3 = 3 # rank sample 2 np.random.seed(1111) # For reproducibility. # Solutions: original space. Sol0 = np.dot(np.random.rand(D1, r0), np.random.rand(r0, D1)) Sol1 = np.dot(np.random.rand(D1, r1), np.random.rand(r1, D1)) Sol2 = np.dot(np.random.rand(D1, r2), np.random.rand(r2, D1)) Sol3 = np.dot(np.random.rand(D1, r3), np.random.rand(r3, D1)) # Creating a list of matrices. matrices = [Sol0, Sol1, Sol2, Sol3] # Plot the matrices fig, (ax1, ax2, ax3, ax4) = plt.subplots(1, 4) ax1.title.set_text('Matrix 0') ax1.imshow(Sol0) ax2.title.set_text('Matrix 1') ax2.imshow(Sol1) ax3.title.set_text('Matrix 2') ax3.imshow(Sol2) ax4.title.set_text('Matrix 3') ax4.imshow(Sol3) plt.show() .. image-sg:: /auto_examples/dimension_reduction/grassmann/images/sphx_glr_plot_grassmann_log_exp_001.png :alt: Matrix 0, Matrix 1, Matrix 2, Matrix 3 :srcset: /auto_examples/dimension_reduction/grassmann/images/sphx_glr_plot_grassmann_log_exp_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 58-59 Instantiate the UQpy class Grassmann. .. GENERATED FROM PYTHON SOURCE LINES 62-77 .. code-block:: default manifold_projection = SVDProjection(matrices, p="max") # Plot the points on the Grassmann manifold defined by the left singular eigenvectors. fig, (ax1, ax2, ax3, ax4) = plt.subplots(1, 4) ax1.title.set_text('Matrix 0') ax1.imshow(manifold_projection.u[0].data) ax2.title.set_text('Matrix 1') ax2.imshow(manifold_projection.u[0].data) ax3.title.set_text('Matrix 2') ax3.imshow(manifold_projection.u[0].data) ax4.title.set_text('Matrix 3') ax4.imshow(manifold_projection.u[0].data) plt.show() .. image-sg:: /auto_examples/dimension_reduction/grassmann/images/sphx_glr_plot_grassmann_log_exp_002.png :alt: Matrix 0, Matrix 1, Matrix 2, Matrix 3 :srcset: /auto_examples/dimension_reduction/grassmann/images/sphx_glr_plot_grassmann_log_exp_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 78-79 Project :math:`\Psi`, the left singular eigenvectors, on the tangent space centered at :math:`\Psi_0`. .. GENERATED FROM PYTHON SOURCE LINES 82-103 .. code-block:: default points_tangent = GrassmannOperations.log_map(grassmann_points=manifold_projection.u, reference_point=manifold_projection.u[0]) print(points_tangent[0]) print(points_tangent[1]) print(points_tangent[2]) print(points_tangent[3]) # Plot the matrices fig, (ax1, ax2, ax3, ax4) = plt.subplots(1, 4) ax1.title.set_text('Matrix 0') ax1.imshow(points_tangent[0]) ax2.title.set_text('Matrix 1') ax2.imshow(points_tangent[1]) ax3.title.set_text('Matrix 2') ax3.imshow(points_tangent[2]) ax4.title.set_text('Matrix 3') ax4.imshow(points_tangent[3]) plt.show() .. image-sg:: /auto_examples/dimension_reduction/grassmann/images/sphx_glr_plot_grassmann_log_exp_003.png :alt: Matrix 0, Matrix 1, Matrix 2, Matrix 3 :srcset: /auto_examples/dimension_reduction/grassmann/images/sphx_glr_plot_grassmann_log_exp_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none [[ 4.44089210e-16 -3.33066907e-16 9.32529760e-32 -2.77555756e-17] [-4.84362670e-32 1.61320124e-31 2.22044605e-16 -4.92812640e-32] [ 2.77555756e-17 -5.55111512e-17 -1.38777878e-16 -3.81639165e-17] [ 5.55111512e-17 -4.16333634e-17 -2.77555756e-16 -1.11022302e-16] [ 1.11022302e-16 -5.55111512e-17 -1.66533454e-16 1.11022302e-16] [ 1.11022302e-16 -5.55111512e-17 -3.88578059e-16 -7.63278329e-17]] [[-0.00356937 0.03135083 -0.05771847 0.00237597] [ 0.01741479 -0.28975468 0.54980075 0.11381392] [ 0.10384695 -0.48607997 0.84398376 -0.45969562] [-0.01109928 0.3171612 -0.61016186 -0.19399538] [ 0.00188616 0.10302842 -0.20397277 -0.11089361] [-0.03277415 -0.22870161 0.48278374 0.49537601]] [[-0.01248918 -0.03404874 0.03382148 0.04441854] [ 0.11463677 0.29686231 -0.32694232 -0.2932605 ] [ 0.19610641 0.58343179 -0.47968446 -1.053919 ] [-0.12507465 -0.31582661 0.3652045 0.26104234] [-0.04035058 -0.09630879 0.12369612 0.0434478 ] [ 0.08811558 0.18106297 -0.30092505 0.1188072 ]] [[ 0.01078907 0.04320251 0.00795957 -0.00917463] [-0.10961148 -0.5508007 0.06152557 0.06419726] [-0.13646121 -0.1979701 -0.54413979 0.20639862] [ 0.12503825 0.68035971 -0.13641218 -0.05973846] [ 0.04410731 0.27443542 -0.09194715 -0.01214282] [-0.11607213 -0.88728766 0.45206533 -0.01085307]] .. GENERATED FROM PYTHON SOURCE LINES 104-105 Map the points back to the Grassmann manifold. .. GENERATED FROM PYTHON SOURCE LINES 108-122 .. code-block:: default points_grassmann = GrassmannOperations.exp_map(tangent_points=points_tangent, reference_point=manifold_projection.u[0]) # Plot the matrices fig, (ax1, ax2, ax3, ax4) = plt.subplots(1, 4) ax1.title.set_text('Matrix 0') ax1.imshow(points_grassmann[0].data) ax2.title.set_text('Matrix 1') ax2.imshow(points_grassmann[1].data) ax3.title.set_text('Matrix 2') ax3.imshow(points_grassmann[2].data) ax4.title.set_text('Matrix 3') ax4.imshow(points_grassmann[3].data) plt.show() .. image-sg:: /auto_examples/dimension_reduction/grassmann/images/sphx_glr_plot_grassmann_log_exp_004.png :alt: Matrix 0, Matrix 1, Matrix 2, Matrix 3 :srcset: /auto_examples/dimension_reduction/grassmann/images/sphx_glr_plot_grassmann_log_exp_004.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.357 seconds) .. _sphx_glr_download_auto_examples_dimension_reduction_grassmann_plot_grassmann_log_exp.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/SURGroup/UQpy/master?urlpath=lab/tree/notebooks/auto_examples/dimension_reduction/grassmann/plot_grassmann_log_exp.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_grassmann_log_exp.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_grassmann_log_exp.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_