kernels.py
def forward(self, X: Tensor, Y: Tensor = None) -> Tensor:
        """
        Computes the kernel matrix for some observation matrices X and Y.
        :param X: d x N matrix
        :param Y: d x M matrix. If not specified, it is assumed to be X.
        :return: N x M kernel matrix
        """
        if Y is None:
            Y = X
        N = X.shape[1] if len(X.shape) > 1 else 1
        M = Y.shape[1] if len(Y.shape) > 1 else 1

        def my_cdist(x1, x2):
            """
            Computes a matrix of the norm of the difference.
            """
            x1 = torch.t(x1)
            x2 = torch.t(x2)
            x1_norm = x1.pow(2).sum(dim=-1, keepdim=True)
            x2_norm = x2.pow(2).sum(dim=-1, keepdim=True)
            res = torch.addmm(x2_norm.transpose(-2, -1), x1, x2.transpose(-2, -1), alpha=-2).add_(x1_norm)
            res = res.clamp_min_(1e-30).sqrt_()
            return res

        D = my_cdist(X,Y)

        return torch.exp(- torch.pow(D, 2) / (2 * self.sigma2))

        Computes the kernel matrix for some observation matrices X and Y.
        :param X: d x N matrix
        :param Y: d x M matrix. If not specified, it is assumed to be X.
        :return: N x M kernel matrix
        
Computes the kernel matrix for some observation matrices X and Y.
Computes the kernel matrix for some observation matrices X and Y .
def forward(self, X: Tensor, Y: Tensor = None) -> Tensor:
        if Y is None:
            Y = X
        N = X.shape[1] if len(X.shape) > 1 else 1
        M = Y.shape[1] if len(Y.shape) > 1 else 1
        def my_cdist(x1, x2):
            x1 = torch.t(x1)
            x2 = torch.t(x2)
            x1_norm = x1.pow(2).sum(dim=-1, keepdim=True)
            x2_norm = x2.pow(2).sum(dim=-1, keepdim=True)
            res = torch.addmm(x2_norm.transpose(-2, -1), x1, x2.transpose(-2, -1), alpha=-2).add_(x1_norm)
            res = res.clamp_min_(1e-30).sqrt_()
            return res
        D = my_cdist(X,Y)
        return torch.exp(- torch.pow(D, 2) / (2 * self.sigma2))
def forward ( self , X : Tensor , Y : Tensor = None ) -> Tensor : if Y is None : Y = X N = X . shape [ 1 ] if len ( X . shape ) > 1 else 1 M = Y . shape [ 1 ] if len ( Y . shape ) > 1 else 1 def my_cdist ( x1 , x2 ) : """
            Computes a matrix of the norm of the difference.
            """ x1 = torch . t ( x1 ) x2 = torch . t ( x2 ) x1_norm = x1 . pow ( 2 ) . sum ( dim = - 1 , keepdim = True ) x2_norm = x2 . pow ( 2 ) . sum ( dim = - 1 , keepdim = True ) res = torch . addmm ( x2_norm . transpose ( - 2 , - 1 ) , x1 , x2 . transpose ( - 2 , - 1 ) , alpha = - 2 ) . add_ ( x1_norm ) res = res . clamp_min_ ( 1e-30 ) . sqrt_ ( ) return res D = my_cdist ( X , Y ) return torch . exp ( - torch . pow ( D , 2 ) / ( 2 * self . sigma2 ) )
Computes the kernel matrix for some observation matrices X and Y.
Computes the kernel matrix for some observation matrices X and Y .
"""
        Computes the kernel matrix for some observation matrices X and Y.
        :param X: d x N matrix
        :param Y: d x M matrix. If not specified, it is assumed to be X.
        :return: N x M kernel matrix
        """ """
            Computes a matrix of the norm of the difference.
            """
N x M kernel matrix
N x M kernel matrix
self
X
Tensor
d x N matrix
d x N matrix
Y
Tensor
d x M matrix. If not specified, it is assumed to be X.
d x M matrix . If not specified it is assumed to be X .