Class KernelMatrix


  • public class KernelMatrix
    extends java.lang.Object
    Kernel matrix representation.
    Since:
    0.1
    Author:
    Simon Paradies
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) KernelMatrix.DBIDMap idmap
      Static mapping from DBIDs to indexes.
      (package private) double[][] kernel
      The kernel matrix
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static double[][] centerKernelMatrix​(KernelMatrix kernelMatrix)
      Centers the Kernel Matrix in Feature Space according to Smola et.
      static double[][] centerMatrix​(double[][] matrix)
      Centers the matrix in feature space according to Smola et Schoelkopf, Learning with Kernels p. 431 Alters the input matrix.
      double getDistance​(DBIDRef o1, DBIDRef o2)
      Returns the kernel distance between the two specified objects.
      double[][] getKernel()
      Get the kernel matrix.
      double getSimilarity​(DBIDRef id1, DBIDRef id2)
      Get the kernel similarity for the given objects.
      double getSquaredDistance​(DBIDRef id1, DBIDRef id2)
      Returns the squared kernel distance between the two specified objects.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • kernel

        double[][] kernel
        The kernel matrix
    • Constructor Detail

      • KernelMatrix

        public KernelMatrix​(PrimitiveSimilarity<? super O> kernelFunction,
                            Relation<? extends O> relation,
                            DBIDs ids)
        Provides a new kernel matrix.
        Parameters:
        kernelFunction - the kernel function used to compute the kernel matrix
        relation - the database that holds the objects
        ids - the IDs of those objects for which the kernel matrix is computed
      • KernelMatrix

        public KernelMatrix​(SimilarityQuery<? super O> kernelFunction,
                            Relation<? extends O> relation,
                            DBIDs ids)
        Provides a new kernel matrix.
        Parameters:
        kernelFunction - the kernel function used to compute the kernel matrix
        relation - the database that holds the objects
        ids - the IDs of those objects for which the kernel matrix is computed
      • KernelMatrix

        public KernelMatrix​(double[][] matrix)
        Makes a new kernel matrix from matrix (with data copying).
        Parameters:
        matrix - a matrix
    • Method Detail

      • getDistance

        public double getDistance​(DBIDRef o1,
                                  DBIDRef o2)
        Returns the kernel distance between the two specified objects.
        Parameters:
        o1 - first ObjectID
        o2 - second ObjectID
        Returns:
        the distance between the two objects
      • getKernel

        public double[][] getKernel()
        Get the kernel matrix.
        Returns:
        kernel
      • getSquaredDistance

        public double getSquaredDistance​(DBIDRef id1,
                                         DBIDRef id2)
        Returns the squared kernel distance between the two specified objects.
        Parameters:
        id1 - first ObjectID
        id2 - second ObjectID
        Returns:
        the distance between the two objects
      • centerMatrix

        public static double[][] centerMatrix​(double[][] matrix)
        Centers the matrix in feature space according to Smola et Schoelkopf, Learning with Kernels p. 431 Alters the input matrix. If you still need the original matrix, use centeredMatrix = centerKernelMatrix(uncenteredMatrix.copy()) {
        Parameters:
        matrix - the matrix to be centered
        Returns:
        centered matrix (for convenience)
      • centerKernelMatrix

        public static double[][] centerKernelMatrix​(KernelMatrix kernelMatrix)
        Centers the Kernel Matrix in Feature Space according to Smola et. Schoelkopf, Learning with Kernels p. 431 Alters the input matrix. If you still need the original matrix, use centeredMatrix = centerKernelMatrix(uncenteredMatrix.copy()) {
        Parameters:
        kernelMatrix - the kernel matrix to be centered
        Returns:
        centered kernelMatrix (for convenience)
      • getSimilarity

        public double getSimilarity​(DBIDRef id1,
                                    DBIDRef id2)
        Get the kernel similarity for the given objects.
        Parameters:
        id1 - First object
        id2 - Second object
        Returns:
        Similarity.