cca_zoo.nonparametric¶
Kernel-based nonparametric CCA methods.
KCCA ¶
KCCA(latent_dimensions: int = 1, center: bool = True, c: float | list[float] = 0.1, kernel: str | list[str] = 'linear', gamma: float | list[float | None] | None = None, degree: float | list[float] = 1.0, coef0: float | list[float] = 1.0, kernel_params: dict[str, object] | list[dict[str, object]] | None = None, eps: float = 0.001)
Bases: BaseModel
Kernel Canonical Correlation Analysis.
Extends MCCA to nonlinear relationships by mapping each view into a
reproducing kernel Hilbert space via a kernel function :math:k_i. The
dual variables (kernel coefficients) :math:\boldsymbol{\alpha}_i are
found by solving the kernelised generalised eigenvalue problem:
.. math::
A \boldsymbol{\alpha} = \lambda B \boldsymbol{\alpha}
where:
- :math:
Ais the between-kernel cross-covariance block matrix. - :math:
B = \mathrm{block\_diag}\bigl( c_i K_i + (1 - c_i) K_i^2 \bigr)is the regularised within-kernel matrix.
References
Hardoon, D. R., Szedmak, S., & Shawe-Taylor, J. (2004). Canonical correlation analysis: An overview with application to learning methods. Neural Computation, 16(12), 2639–2664.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
latent_dimensions
|
int
|
Number of latent dimensions. Default is 1. |
1
|
center
|
bool
|
Whether to subtract column means before fitting. Default True. |
True
|
c
|
float | list[float]
|
Regularisation parameter(s) in |
0.1
|
kernel
|
str | list[str]
|
Kernel name(s) or callable(s) passed to
:func: |
'linear'
|
gamma
|
float | list[float | None] | None
|
Gamma parameter(s) for the RBF/polynomial kernel. |
None
|
degree
|
float | list[float]
|
Degree parameter(s) for the polynomial kernel. |
1.0
|
coef0
|
float | list[float]
|
coef0 parameter(s) for the polynomial/sigmoid kernel. |
1.0
|
kernel_params
|
dict[str, object] | list[dict[str, object]] | None
|
Extra per-view keyword arguments for the kernel. |
None
|
eps
|
float
|
Regularisation floor for the B matrix. Default is 1e-3. |
0.001
|
Example
import numpy as np rng = np.random.default_rng(0) X1 = rng.standard_normal((30, 5)) X2 = rng.standard_normal((30, 5)) model = KCCA(latent_dimensions=2, c=0.1).fit([X1, X2]) scores = model.transform([X1, X2])
Source code in cca_zoo/nonparametric/_kcca.py
fit ¶
Fit the KCCA model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
views
|
list[ArrayLike]
|
List of arrays, each (n_samples, n_features_i). |
required |
y
|
None
|
Ignored. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
self |
KCCA
|
Fitted estimator. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If fewer than 2 views are provided. |
ValueError
|
If views have inconsistent numbers of samples. |
Source code in cca_zoo/nonparametric/_kcca.py
transform ¶
Transform new views using the fitted kernel dual variables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
views
|
list[ArrayLike]
|
List of arrays, each (n_samples_test, n_features_i). |
required |
Returns:
| Type | Description |
|---|---|
list[ndarray]
|
List of arrays, each (n_samples_test, latent_dimensions). |
Raises:
| Type | Description |
|---|---|
NotFittedError
|
If |
Source code in cca_zoo/nonparametric/_kcca.py
KGCCA ¶
KGCCA(latent_dimensions: int = 1, center: bool = True, c: float | list[float] = 0.1, kernel: str | list[str] = 'linear', gamma: float | list[float | None] | None = None, degree: float | list[float] = 1.0, coef0: float | list[float] = 1.0, kernel_params: dict[str, object] | list[dict[str, object]] | None = None, view_weights: list[float] | None = None, eps: float = 1e-06)
Bases: BaseModel
Kernel Generalised Canonical Correlation Analysis.
Kernelised version of GCCA. The shared latent vector is found by solving the eigenvalue problem on the weighted sum of kernel projection matrices:
.. math::
Q = \sum_{i=1}^M \mu_i K_i
\bigl(c_i K_i + (1 - c_i) K_i^2\bigr)^{-1} K_i
and the dual variables (kernel coefficients) are recovered as
:math:\boldsymbol{\alpha}_i = K_i^+ T where :math:T is the matrix
of top-k eigenvectors of :math:Q.
References
Tenenhaus, A., Philippe, C., & Frouin, V. (2015). Kernel generalized canonical correlation analysis. Computational Statistics & Data Analysis, 90, 114–131.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
latent_dimensions
|
int
|
Number of latent dimensions. Default is 1. |
1
|
center
|
bool
|
Whether to subtract column means before fitting. Default True. |
True
|
c
|
float | list[float]
|
Regularisation parameter(s). Default is 0.1. |
0.1
|
kernel
|
str | list[str]
|
Kernel name(s). Default is |
'linear'
|
gamma
|
float | list[float | None] | None
|
Gamma for RBF/polynomial kernel. |
None
|
degree
|
float | list[float]
|
Degree for polynomial kernel. |
1.0
|
coef0
|
float | list[float]
|
coef0 for polynomial/sigmoid kernel. |
1.0
|
kernel_params
|
dict[str, object] | list[dict[str, object]] | None
|
Extra per-view kernel keyword arguments. |
None
|
view_weights
|
list[float] | None
|
Per-view weights. Default is equal weights. |
None
|
eps
|
float
|
Regularisation floor. Default is 1e-6. |
1e-06
|
Example
import numpy as np rng = np.random.default_rng(0) X1 = rng.standard_normal((30, 5)) X2 = rng.standard_normal((30, 5)) X3 = rng.standard_normal((30, 5)) model = KGCCA(latent_dimensions=2).fit([X1, X2, X3])
Source code in cca_zoo/nonparametric/_kgcca.py
fit ¶
Fit the KGCCA model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
views
|
list[ArrayLike]
|
List of arrays, each (n_samples, n_features_i). |
required |
y
|
None
|
Ignored. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
self |
KGCCA
|
Fitted estimator. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If fewer than 2 views are provided. |
ValueError
|
If views have inconsistent numbers of samples. |
Source code in cca_zoo/nonparametric/_kgcca.py
transform ¶
Transform new views using fitted kernel dual variables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
views
|
list[ArrayLike]
|
List of arrays, each (n_samples_test, n_features_i). |
required |
Returns:
| Type | Description |
|---|---|
list[ndarray]
|
List of arrays, each (n_samples_test, latent_dimensions). |
Raises:
| Type | Description |
|---|---|
NotFittedError
|
If |
Source code in cca_zoo/nonparametric/_kgcca.py
KTCCA ¶
KTCCA(latent_dimensions: int = 1, center: bool = True, c: float | list[float] = 0.1, kernel: str | list[str] = 'linear', gamma: float | list[float | None] | None = None, degree: float | list[float] = 1.0, coef0: float | list[float] = 1.0, kernel_params: dict[str, object] | list[dict[str, object]] | None = None, eps: float = 0.001, random_state: int | None = None)
Bases: BaseModel
Kernel Tensor Canonical Correlation Analysis.
Extends TCCA to nonlinear relationships by computing the cross-moment
tensor from whitened kernel matrices rather than from the raw views.
Each kernel matrix :math:K_i is whitened using its regularised
self-product, then PARAFAC is applied to the resulting cross-moment
tensor.
References
Kim, T.-K., Wong, S.-F., & Cipolla, R. (2007). Tensor canonical correlation analysis for action classification. CVPR 2007. IEEE.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
latent_dimensions
|
int
|
Number of latent dimensions. Default is 1. |
1
|
center
|
bool
|
Whether to subtract column means before fitting. Default True. |
True
|
c
|
float | list[float]
|
Regularisation parameter(s). Default is 0.1. |
0.1
|
kernel
|
str | list[str]
|
Kernel name(s). Default is |
'linear'
|
gamma
|
float | list[float | None] | None
|
Gamma for RBF/polynomial kernel. |
None
|
degree
|
float | list[float]
|
Degree for polynomial kernel. |
1.0
|
coef0
|
float | list[float]
|
coef0 for polynomial/sigmoid kernel. |
1.0
|
kernel_params
|
dict[str, object] | list[dict[str, object]] | None
|
Extra per-view keyword arguments for the kernel. |
None
|
eps
|
float
|
Regularisation floor. Default is 1e-3. |
0.001
|
random_state
|
int | None
|
Seed for PARAFAC. Default is None. |
None
|
Example
import numpy as np rng = np.random.default_rng(0) X1 = rng.standard_normal((20, 5)) X2 = rng.standard_normal((20, 5)) X3 = rng.standard_normal((20, 5)) model = KTCCA(latent_dimensions=1, random_state=0).fit([X1, X2, X3])
Source code in cca_zoo/nonparametric/_ktcca.py
fit ¶
Fit the KTCCA model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
views
|
list[ArrayLike]
|
List of arrays, each (n_samples, n_features_i). |
required |
y
|
None
|
Ignored. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
self |
KTCCA
|
Fitted estimator. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If fewer than 2 views are provided. |
ValueError
|
If views have inconsistent numbers of samples. |
Source code in cca_zoo/nonparametric/_ktcca.py
transform ¶
Transform new views using fitted kernel dual variables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
views
|
list[ArrayLike]
|
List of arrays, each (n_samples_test, n_features_i). |
required |
Returns:
| Type | Description |
|---|---|
list[ndarray]
|
List of arrays, each (n_samples_test, latent_dimensions). |
Raises:
| Type | Description |
|---|---|
NotFittedError
|
If |