-
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 Gaussian process kernels to abstract from hyperparameters
- Loading branch information
Showing
5 changed files
with
110 additions
and
84 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
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,15 +1,18 @@ | ||
from typing import Union | ||
|
||
from UQpy.surrogates.gaussian_process.kernels.baseclass.Kernel import * | ||
|
||
|
||
class RBF(Kernel): | ||
def c(self, x, s, params): | ||
def __init__(self, kernel_parameter: Union[int, float] = 1.0): | ||
super().__init__(kernel_parameter) | ||
|
||
def calculate_kernel_matrix(self, x, s): | ||
""" | ||
This method compute the RBF kernel on sample points 'x' and 's'. | ||
:params x: An array containing input samples. | ||
:params s: An array containing input samples. | ||
:params params: A list/array of hyperparameters containing length scales and the process variance. | ||
:params x: An array containing training points. | ||
:params s: An array containing input points. | ||
""" | ||
stack = Kernel.check_samples_and_return_stack(x/params[:-1], s/params[:-1]) | ||
k = params[-1] ** 2 * np.exp(np.sum(-0.5 * (stack ** 2), axis=2)) | ||
return k | ||
stack = Kernel.check_samples_and_return_stack(x / self.kernel_parameter, s / self.kernel_parameter) | ||
return np.exp(np.sum(-0.5 * (stack ** 2), axis=2)) |
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
Oops, something went wrong.