Kernels¶
Positive-definite kernels that turn one source of information into a raw Gram matrix.
Every kernel maps a set of objects X (any array-like whose first axis indexes the
objects; the remaining axes are flattened) to the raw Gram matrix
K[i, j] = kappa(x_i, x_j). The method only requires each kernel to be positive
definite; which kernel to use is part of the instantiation, not of the method.
A word on composition. The joint Gram is the Hadamard product of the component Grams.
With linear-type kernels this realises the tensor product of the feature spaces, so the
joint similarity keeps the multiplicative interaction between sources. With Gaussian
kernels it does not: the product of two Gaussians is the Gaussian of the summed
exponents, and the composition collapses into an additive combination of the source
metrics. RBF is available, but Linear/Cosine are the default for this
reason.
Linear
¶
Cosine
¶
Bases: Kernel
kappa(x, y) = <x, y> / (|x| |y|); zero vectors get similarity 0 (1 with themselves).
Source code in src\fannar\kernels.py
RBF
¶
Bases: Kernel
Gaussian kernel exp(-gamma |x - y|^2). gamma=None uses the median heuristic.
See the module docstring: under Hadamard composition, Gaussian components add their metrics instead of multiplying the similarities.
Source code in src\fannar\kernels.py
compute
¶
Source code in src\fannar\kernels.py
Polynomial
¶
Bases: Kernel
kappa(x, y) = (gamma <x, y> + coef0) ** degree with coef0 >= 0.
Source code in src\fannar\kernels.py
FunctionKernel
¶
Bases: Kernel
Wraps a user function fn(X, Y) -> (n, m) array. Positive definiteness is the user's.
Source code in src\fannar\kernels.py
Kernel
¶
Bases: ABC
Base class. Subclasses implement compute on (n, D) and (m, D) arrays.
as_kernel
¶
as_kernel(obj) -> Kernel
Accepts a Kernel, a name ("linear", "cosine", "rbf", "polynomial")
or a callable fn(X, Y).