Basic Examples (3)
Calculate the kernel similarity between two vectors:
Calculate the kernel similarity between two matrices:
Calculate the kernel self-similarity of a matrix:
Options (4)
Use the "KernelType" option to modify the kernel function:
Use the "BiasParameter" option to modify the bias value used in the kernel function:
Use the "GammaValue" option to specify the gamma parameter used in the kernel function:
Lower gamma values make the kernel less sensitive to distance, producing similarity scores closer to 1:
Use the "PolynomialDegree" option to specify the degree of the polynomial kernel:
Compare it with the default value (d=3):
Applications (3)
Define and visualize three points:
Compute similarities between the anchor and the other points using different kernels:
Display the results:
RBF (radial basis function) and Laplacian kernels measure similarity based on distance, assigning higher similarity to nearby points. On the other hand, linear and polynomial kernels depend on dot products, which capture alignment and magnitude rather than pure spatial proximity. This distinction is particularly important in machine learning applications, since distance-based kernels are well-suited for capturing local structure of the input data.
Properties and Relations (5)
In the case of matrices, KernelSimilarity calculates the similarity between every pair of vectors (known as the Gram Matrix):
The self-similarity of a vector with the "RadialBasisFunction" kernel is always 1:
In the case of two normalized vectors, the linear kernel with bias equals zero returns the cosine similarity, meaning that 1- KernelSimilarity[v1,v2]=CosineDistance[v1,v2]:
KernelSimilarity[a,b] is the same as
:
The "RadialBasisFunction", "Laplacian" and "Polynomial" kernels always produce symmetric and positive semidefinite (PSD) Gram matrices:
However, the Sigmoid and Linear kernels may produce non-positive-semidefinite Gram matrices, which can cause issues when used in kernel methods that require PSD matrices:
Possible Issues (2)
Kernel types must be one of the available options:
Suboptions must belong to the specified kernel type: