Mappings to & from tangent space

This example shows how to use the UQpy Grassmann class to use the logarithmic map and the exponential map

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.

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

Generate four random matrices with reduced rank corresponding to the different samples. The samples are stored in matrices.

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()
Matrix 0, Matrix 1, Matrix 2, Matrix 3

Instantiate the UQpy class Grassmann.

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()
Matrix 0, Matrix 1, Matrix 2, Matrix 3

Project \(\Psi\), the left singular eigenvectors, on the tangent space centered at \(\Psi_0\).

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()
Matrix 0, Matrix 1, Matrix 2, Matrix 3
[[ 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]]

Map the points back to the Grassmann manifold.

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()
Matrix 0, Matrix 1, Matrix 2, Matrix 3

Total running time of the script: ( 0 minutes 0.357 seconds)

Gallery generated by Sphinx-Gallery