Base class for SVM Kernel functions.
Kernels compute similarity between instances in a (possibly infinite) feature space without explicitly computing the feature mapping.
Classes
Abstract base class for kernel functions.
A kernel function K(x, y) computes the dot product of two instances in a (possibly high-dimensional or infinite) feature space without explicitly computing the feature mapping \phi:
K(x, y) = \langle \phi(x), \phi(y) \rangle
Kernels must satisfy Mercer's condition (positive semi-definite) to ensure valid behavior with SVMs.
Constructor
__init__( self, )
Attributes
X_
np.ndarray of shape (n_samples, n_features)
Training data (set by
build()).
n_samples_
int
Number of training samples.
n_features_
int
Number of features.
Methods
compute_matrix_cross
(self, X1: np.ndarray, X2: np.ndarray) -> np.ndarray
compute_matrix_cross
(self, X1: np.ndarray, X2: np.ndarray) -> np.ndarray
Compute the kernel matrix between two different sets of samples.
Parameters
X1
np.ndarray of shape (n1, n_features)
First set of samples.
X2
np.ndarray of shape (n2, n_features)
Second set of samples.
Returns
K
np.ndarray of shape (n1, n2)
Kernel matrix where
K[i, j] = K(X1[i], X2[j]).
Kernel with caching for repeated evaluations.
Stores computed kernel values to avoid redundant calculations.
Constructor
__init__( self, cache_size: int = _DEFAULT_CACHE_SIZE, )
Parameters
cache_size
int
= 250007
Size of the cache, in number of stored kernel entries. Use
0 for an unbounded (full) cache and -1 to disable caching entirely. The default is a large prime so the symmetric (i, j) cache keys hash evenly across buckets.
Methods
Functions
kernel(tags: List[str]=None, version: str='1.0.0')
Class decorator that registers a kernel with the component registry.
Parameters
tags
list of str
= None
Tags for categorization in the registry.
version
str
= "1.0.0"
Version string for the kernel.
Returns
decorator
callable
Decorator that attaches registry metadata to the kernel class.