Kernel Fusion¶
Kernel fusion is a technique used in machine learning to combine multiple kernels, which are functions that measure the similarity between data points. This approach allows for the integration of different types of data or features, enabling the model to capture complex relationships and improve performance. Typically, kernel fusion involves weighting and summing the outputs of individual kernels, which can be designed for specific data modalities or feature sets.
The kernel helpers this module re-exports (KernelSpec, center_kernel,
normalize_kernel, is_valid_kernel) are documented once, in
Kernel utilities.
- class polyview.fusion.kernel_fusion.KernelFusion(*args: Any, **kwargs: Any)¶
Bases:
BaseFusionFuse views by combining per-view kernel matrices.
Each view is mapped to a kernel matrix by its
KernelSpec, then fused according tofusion_mode:fusion_mode='sum':K_fused = sum_i (w_i * K_i) normalize_weights=False K_fused = sum_i (w_i / W * K_i) normalize_weights=True
fusion_mode='product':K_fused = prod_i K_i ** w_i normalize_weights=False K_fused = prod_i K_i ** (w_i / W) normalize_weights=True
The output is a raw (n_samples, n_samples) kernel matrix for use with any kernel method: spectral clustering, kernel SVM, kernel PCA, etc.
- Parameters:
specs (KernelSpec or list of KernelSpec or None) – One spec per view.
Noneor a single spec is broadcast: -None-> RBF, weight=1, center+normalize on each view - single KernelSpec -> same spec applied to every viewnormalize_weights (bool, default=False) – Divide weights by their sum (convex combination).
fusion_mode ({"sum", "product"}, default="sum") – Fusion operation used to combine per-view kernels.
product_eps (float, default=1e-12) – Small positive constant used in
fusion_mode='product'to avoid taking powers of exact zeros.
- weights_¶
- Type:
ndarray (n_views,)
- specs_¶
- Type:
list of KernelSpec
- .. rubric:: References
- - Gönen, M., & Alpaydin, E. (2011). Multiple kernel learning algorithms.
Journal of Machine Learning Research, 12, 2211-2268.
Examples
>>> import numpy as np >>> from polyview.fusion.kernel_fusion import KernelFusion, KernelSpec >>> X1 = np.random.rand(50, 4) >>> X2 = np.random.rand(50, 6) >>> kf = KernelFusion() >>> K = kf.fit_transform([X1, X2]) # RBF on each view >>> K.shape (50, 50)
>>> specs = [KernelSpec("rbf", weight=2.0, gamma=0.1), ... KernelSpec("linear", weight=1.0)] >>> K = KernelFusion(specs).fit_transform([X1, X2])
>>> A1, A2 = X1 @ X1.T, X2 @ X2.T # A* are n x n kernel matrices >>> specs = [KernelSpec("precomputed"), KernelSpec("precomputed")] >>> K = KernelFusion(specs).fit_transform([A1, A2])
- fit(views: List, y=None) KernelFusion¶
Compute per-view kernels and fuse them.
- Parameters:
views (list of array-like) – Feature arrays (n_samples, n_features_i), or square kernel matrices (n_samples, n_samples) paired with
KernelSpec("precomputed").y (ignored)
- Return type:
self
- kernel_matrix() numpy.ndarray¶
Return a copy of the fused kernel matrix.
- transform(views: List) numpy.ndarray¶
Return the fused kernel for a (possibly new) set of views.
- Parameters:
views (list of array-like)
- Returns:
K_fused
- Return type:
ndarray of shape (n_samples_new, n_samples_new)
- view_contributions() List[dict]¶
Per-view contribution fractions to the fused kernel (by Frobenius norm).