[Question] How reverse engineering RBF-Kernel #1890 #1894
-
📚 QuestionI would like to create odd RBF-kernel which of "x-y" is converted into "x+y". # ReverseRBF kernel (start)
from gpytorch.functions import RBFCovariance
from gpytorch.kernels import Kernel
from gpytorch.settings import trace_mode
def postprocess_rbf(dist_mat):
return dist_mat.div_(-2).exp_()
class ReverseRBFKernel(Kernel):
has_lengthscale = True
def forward(self, x1, x2, diag=False, **params):
if (
x1.requires_grad
or x2.requires_grad
or (self.ard_num_dims is not None and self.ard_num_dims > 1)
or diag
or trace_mode.on()
):
x1_ = x1.div(self.lengthscale)
x2_ = x2.div(self.lengthscale)
return self.covar_dist(
-1*x1_, x2_, square_dist=True, diag=diag, dist_postprocess_func=postprocess_rbf, postprocess=True, **params
)
return RBFCovariance().apply(
-1*x1,
x2,
self.lengthscale,
lambda x1, x2: self.covar_dist(
x1, x2, square_dist=True, diag=False, dist_postprocess_func=postprocess_rbf, postprocess=False, **params
),
)
# ReverseRBF kernel (end) my-example is here : https://github.com/makinzm/UNDONE_local/blob/main/08_oputuna/gp-02.ipynb Issue : #1890 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Let Then, So the 2x2 kernel matrix would be This matrix has eigenvalues |
Beta Was this translation helpful? Give feedback.
Let
x1 = [sqrt(2)/4, sqrt(2)/4]
andx2 = [-sqrt(2)/4, -sqrt(2)/4]
, and assume a lengthscale of 1.Then,
||x1 + x1||^2 = ||x2 + x2||^2 = 1
, but||x1 + x2||^2 = ||x2 + x1||^2 = 0
.So the 2x2 kernel matrix would be
exp(-I) = [[1/e, 1], [1, 1/e]]
.This matrix has eigenvalues
1/e + 1
and1/e - 1
.1/e - 1
is negative, so the matrix isn't positive definite.