-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactors Dimension Reduction kernels to match GP kernels signatures
- Loading branch information
Showing
18 changed files
with
122 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
src/UQpy/dimension_reduction/grassmann_manifold/projections/baseclass/GrassmannProjection.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
from UQpy.surrogates.gaussian_process.GaussianProcessRegression import GaussianProcessRegression | ||
|
||
from UQpy.surrogates.gaussian_process.kernels import * | ||
from UQpy.surrogates.gaussian_process.regression_models import * | ||
from UQpy.surrogates.gaussian_process.constraints import * |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
from UQpy.utilities.kernels.baseclass import * | ||
from UQpy.utilities.kernels.euclidean_kernels import * | ||
from UQpy.utilities.kernels.grassmannian_kernels import * | ||
|
||
from UQpy.utilities.kernels.BinetCauchyKernel import BinetCauchyKernel | ||
from UQpy.utilities.kernels.grassmannian_kernels.BinetCauchyKernel import BinetCauchyKernel | ||
from UQpy.utilities.kernels.GaussianKernel import GaussianKernel | ||
from UQpy.utilities.kernels.ProjectionKernel import ProjectionKernel | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,7 @@ | ||
import itertools | ||
from abc import ABC, abstractmethod | ||
from typing import Union | ||
import scipy.spatial.distance as sd | ||
import numpy as np | ||
from abc import ABC | ||
|
||
from UQpy.utilities import GrassmannPoint | ||
from UQpy.utilities.ValidationTypes import NumpyFloatArray, Numpy2DFloatArray | ||
from UQpy.utilities.kernels.baseclass.Kernel import Kernel | ||
|
||
|
||
class EuclideanKernel(Kernel, ABC): | ||
"""This is a blueprint for Euclidean kernels implemented in the :py:mod:`kernels` module .""" | ||
|
||
def __init__(self): | ||
super().__init__() | ||
|
||
def calculate_kernel_matrix(self, points: Numpy2DFloatArray): | ||
""" | ||
Using the kernel-specific :py:meth:`.Kernel.kernel_entry` method, this function assembles the kernel matrix. | ||
:param points: Set of data points in the Euclidean space | ||
""" | ||
nargs = len(points) | ||
indices = range(nargs) | ||
pairs = list(itertools.combinations_with_replacement(indices, 2)) | ||
kernel = np.zeros((nargs, nargs)) | ||
for id_pair in range(np.shape(pairs)[0]): | ||
i = pairs[id_pair][0] | ||
j = pairs[id_pair][1] | ||
|
||
xi = points[i] | ||
xj = points[j] | ||
|
||
kernel[i, j] = self.kernel_entry(xi, xj) | ||
kernel[j, i] = kernel[i, j] | ||
|
||
self.kernel_matrix = kernel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
from UQpy.utilities.kernels.baseclass.DRKernel import Kernel | ||
from UQpy.utilities.kernels.baseclass.EuclideanKernel import EuclideanKernel | ||
from UQpy.utilities.kernels.baseclass.GrassmannianKernel import GrassmannianKernel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/UQpy/utilities/kernels/grassmannian_kernels/BinetCauchyKernel.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from typing import Tuple | ||
|
||
import numpy as np | ||
|
||
from UQpy.utilities.kernels import GrassmannianKernel | ||
|
||
|
||
class BinetCauchyKernel(GrassmannianKernel): | ||
""" | ||
A class to calculate the Binet-Cauchy kernel. | ||
""" | ||
def element_wise_operation(self, xi_j: Tuple) -> float: | ||
""" | ||
Compute the Projection kernel entry for a tuple of points on the Grassmann manifold. | ||
:param xi_j: Tuple of orthonormal matrices representing the grassmann points. | ||
""" | ||
xi, xj = xi_j | ||
r = np.dot(xi.T, xj) | ||
det = np.linalg.det(r) | ||
return det * det |
25 changes: 25 additions & 0 deletions
25
src/UQpy/utilities/kernels/grassmannian_kernels/ProjectionKernel.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from typing import Union, Tuple | ||
|
||
import numpy as np | ||
|
||
from UQpy.utilities.kernels.baseclass.GrassmannianKernel import GrassmannianKernel | ||
|
||
|
||
class ProjectionKernel(GrassmannianKernel): | ||
|
||
def __init__(self, kernel_parameter: Union[int, float] = None): | ||
""" | ||
:param kernel_parameter: Number of independent p-planes of each Grassmann point. | ||
""" | ||
super().__init__(kernel_parameter) | ||
|
||
def element_wise_operation(self, xi_j: Tuple) -> float: | ||
""" | ||
Compute the Projection kernel entry for a tuple of points on the Grassmann manifold. | ||
:param xi_j: Tuple of orthonormal matrices representing the grassmann points. | ||
""" | ||
xi, xj = xi_j | ||
r = np.dot(xi.T, xj) | ||
n = np.linalg.norm(r, "fro") | ||
return n * n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from UQpy.utilities.kernels.grassmannian_kernels.ProjectionKernel import ProjectionKernel | ||
from UQpy.utilities.kernels.grassmannian_kernels.BinetCauchyKernel import BinetCauchyKernel |
Oops, something went wrong.