From 1a044b3c41182c4cbd889f528b8d6f58d62e8173 Mon Sep 17 00:00:00 2001 From: Dimitris Tsapetis Date: Wed, 6 Apr 2022 12:06:25 -0400 Subject: [PATCH] Adds optimize_parameters method in the Kernel baseclass. --- docs/source/utilities/kernels/euclidean_kernels.rst | 2 +- src/UQpy/utilities/kernels/GaussianKernel.py | 8 ++++---- src/UQpy/utilities/kernels/baseclass/Kernel.py | 12 ++++++++++++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/docs/source/utilities/kernels/euclidean_kernels.rst b/docs/source/utilities/kernels/euclidean_kernels.rst index 79912ee14..81c2249dd 100644 --- a/docs/source/utilities/kernels/euclidean_kernels.rst +++ b/docs/source/utilities/kernels/euclidean_kernels.rst @@ -24,7 +24,7 @@ Methods ~~~~~~~~~ .. autoclass:: UQpy.utilities.kernels.GaussianKernel - :members: optimize_epsilon + :members: optimize_parameters Attributes ~~~~~~~~~~ diff --git a/src/UQpy/utilities/kernels/GaussianKernel.py b/src/UQpy/utilities/kernels/GaussianKernel.py index 67256d3e7..7a6de9d93 100644 --- a/src/UQpy/utilities/kernels/GaussianKernel.py +++ b/src/UQpy/utilities/kernels/GaussianKernel.py @@ -27,10 +27,10 @@ def _kernel_entry(self, xi, xj): def kernel_function(self, distance_pairs): return np.exp(-sd.squareform(distance_pairs) / (4 * self.epsilon)) - def optimize_epsilon(self, data: np.ndarray, tolerance: float, - n_nearest_neighbors: int, - n_cutoff_samples: int, - random_state: RandomStateType): + def optimize_parameters(self, data: np.ndarray, tolerance: float, + n_nearest_neighbors: int, + n_cutoff_samples: int, + random_state: RandomStateType): """ :param data: Cloud of data points. diff --git a/src/UQpy/utilities/kernels/baseclass/Kernel.py b/src/UQpy/utilities/kernels/baseclass/Kernel.py index 8148f57b3..9e62ac96a 100644 --- a/src/UQpy/utilities/kernels/baseclass/Kernel.py +++ b/src/UQpy/utilities/kernels/baseclass/Kernel.py @@ -18,6 +18,18 @@ def __init__(self): def calculate_kernel_matrix(self, points: Union[list, NumpyFloatArray]): pass + def optimize_parameters(self, data, **kwargs_optimization): + """ + This serves as a blueprint function in case a kernel provides the ability to optimize its parameters. In that + case, the implemented kernel will provide an implementation of this method, that computes the optimized + parameters and stores their values in the kernel's attributes. + + :param data: Set of data points. + :param kwargs_optimization: Keyword arguments containing any extra parameters needed to perform the optimization + of the kernel parameters. + """ + pass + @abstractmethod def _kernel_entry(self, xi, xj): """