Skip to content

Commit

Permalink
Updates sum and product kernels example code.
Browse files Browse the repository at this point in the history
  • Loading branch information
dimtsap committed Apr 7, 2022
1 parent 164f072 commit 75d8f25
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions docs/source/utilities/kernels/sum_product_kernels.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,30 @@ example.
Example sum and product Grassmannian kernels
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

>>> import numpy as np
>>> from UQpy.dimension_reduction.grassmann_manifold.projections.SVDProjection import SVDProjection
>>> from UQpy.utilities.kernels.ProjectionKernel import ProjectionKernel
>>>
>>> D1 = 6
>>> r0 = 2 # rank sample 0
>>> r1 = 3 # rank sample 1
>>> r2 = 4 # rank sample 2
>>> r3 = 3 # rank sample 2
>>>
>>> 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 solutions.
>>> Solutions = [Sol0, Sol1, Sol2, Sol3]
>>> from UQpy.dimension_reduction.grassmann_manifold.GrassmannOperations import Grassmann
>>> manifold_projection = SvdProjection(Solutions, p="max")
>>> manifold_projection = SVDProjection(Solutions, p="max")
>>> kernel = ProjectionKernel()
>>>
>>> kernel_psi = kernel.calculate_kernel_matrix(manifold_projection.u)
>>> kernel_phi = kernel.calculate_kernel_matrix(manifold_projection.v)
>>> kernel.calculate_kernel_matrix(manifold_projection.u)
>>> kernel_psi = kernel.kernel_matrix
>>>
>>> kernel.calculate_kernel_matrix(manifold_projection.v)
>>> kernel_phi = kernel.kernel_matrix
>>>
>>> sum_kernel = kernel_psi + kernel_phi
>>> product_kernel = kernel_psi * kernel_phi

0 comments on commit 75d8f25

Please sign in to comment.