GCCA¶
Generalised Canonical Correlation Analysis (GCCA) is a multiview extension of CCA that finds a shared embedding across all views. It does this by maximising the sum of pairwise correlations between the views in the shared space, while also applying regularisation to prevent overfitting.
- class polyview.embed.gcca.GCCA(*args: Any, **kwargs: Any)¶
Bases:
BaseMultiViewTransformerGeneralised Canonical Correlation Analysis (GCCA).
Finds a shared low-dimensional embedding G that maximises linear agreement across all views simultaneously (MAXVAR criterion). Works with M >= 2 views. When M = 2 this recovers classical CCA.
- Parameters:
n_components (int, default=2) – Number of shared dimensions k.
regularisation (float or list of float, default=1e-4) – Ridge regularisation added to each view’s covariance before inversion. A single float applies the same value to all views; a list gives per-view values. Larger values = stronger regularisation (useful when d_v > n or features are collinear).
output (str {"concat", "mean", "list", "shared"}, default="shared") – How to combine per-view projections in transform(): - “concat” : [Z1 | Z2 | … | ZM] shape (n, M*k) - “mean” : (Z1 + Z2 + … + ZM) / M shape (n, k) - “list” : [Z1, Z2, …, ZM] list of (n, k) arrays - “shared” :
G_shape (n, n_components)centre (bool, default=True) – Subtract column means from each view before fitting.
eigen_solver ({"auto", "dense", "arpack"}, default="auto") – Solver for the top
n_componentseigenvectors of the aggregated smoother matrix. - “dense” : LAPACK, restricted to the requested eigenpairs. - “arpack” : iterative Lanczos solver applied matrix-free, so the (n, n) smoother matrix is never formed. Much faster and lighter in memory for largen_samples. - “auto” : “arpack” whenn_samples > 200and the views have fewer features in total than there are samples, “dense” otherwise (the leading eigenvalues then cluster and Lanczos converges slowly).
- G_¶
Shared embedding of the training data.
- Type:
ndarray of shape (n_train, n_components)
- weights_¶
Per-view projection matrices W(v).
- Type:
list of ndarray, shape (n_features_v, n_components)
- means_¶
Per-view column means (used to centre test data).
- Type:
list of ndarray, shape (n_features_v,)
- eigenvalues_¶
Top-k eigenvalues of the aggregated smoother matrix.
- Type:
ndarray of shape (n_components,)
Examples
>>> import numpy as np >>> from polyview.embed.gcca import GCCA >>> X1, X2, X3 = (np.random.rand(100, 20) for _ in range(3)) >>> gcca = GCCA(n_components=10, output="concat") >>> Z_train = gcca.fit_transform([X1, X2, X3]) >>> Z_train.shape (100, 30) >>> T1, T2, T3 = (np.random.rand(20, 20) for _ in range(3)) >>> Z_test = gcca.transform([T1, T2, T3]) >>> Z_test.shape (20, 30)
References
Guo, C., & Wu, D. (2021). Canonical correlation analysis (CCA) based multi-view learning: An overview. arXiv preprint arXiv:1907.01693.
- canonical_correlations() numpy.ndarray¶
Pairwise canonical correlations between all view pairs.
- Returns:
corrs[v1, v2, :] = per-component correlation between projections of view v1 and view v2.
- Return type:
ndarray of shape (n_views, n_views, n_components)