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.
- class polyview.fusion.kernel_fusion.KernelFusion(*args: Any, **kwargs: Any)¶
Bases:
BaseMultiViewTransformerFuse views via a weighted sum of per-view kernel matrices.
Each view is mapped to a kernel matrix by its
KernelSpec, then:K_fused = sum_i (w_i * K_i) normalize_weights=False K_fused = sum_i (w_i / W * K_i) 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).
- kernels_¶
- Type:
list of ndarray (n_samples, n_samples)
- weights_¶
- Type:
ndarray (n_views,)
- K_fused_¶
- Type:
ndarray (n_samples, n_samples)
- 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
>>> kf = KernelFusion() >>> K = kf.fit_transform([X1, X2]) # RBF on each view
>>> specs = [KernelSpec("rbf", weight=2.0, gamma=0.1), ... KernelSpec("linear", weight=1.0)] >>> K = KernelFusion(specs).fit_transform([X1, X2])
>>> specs = [KernelSpec("precomputed"), KernelSpec("precomputed")] >>> K = KernelFusion(specs).fit_transform([A1, A2]) # A* are n x n
- 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).