cca_zoo.nonparametric¶
Kernel- and graph-based nonparametric CCA methods.
KCCA ¶
KCCA(
n_components: int = 1,
*,
center: bool = True,
shrinkage: float | list[float] = 0.1,
kernel: str | list[str] = "linear",
gamma: float | list[float | None] | None = None,
degree: float | list[float] = 3,
coef0: float | list[float] = 1.0,
kernel_params: dict[str, object]
| list[dict[str, object]]
| None = None,
)
Bases: _BaseKernelModel
Kernel CCA for two or more views.
:class:~cca_zoo.linear.MCCA in each view's kernel feature space. With
centred kernels \(K_i\) the dual problem is \(A \alpha = \lambda B \alpha\),
with between-view blocks \(K_i K_j / (n - 1)\) and within-view blocks
\((1 - c_i) K_i^2 / (n - 1) + c_i K_i\), the covariance and the squared
norm of the feature-space direction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_components
|
int
|
Number of latent dimensions. Default is 1. |
1
|
center
|
bool
|
Whether to centre each view. Default is True. |
True
|
shrinkage
|
float | list[float]
|
Shrinkage of each view's covariance in the kernel feature
space towards the identity, in |
0.1
|
kernel
|
str | list[str]
|
Kernel name or callable for
:func: |
'linear'
|
gamma
|
float | list[float | None] | None
|
Kernel coefficient for RBF, polynomial and sigmoid kernels. Per-view. Default is None. |
None
|
degree
|
float | list[float]
|
Polynomial kernel degree. Per-view. Default is 3. |
3
|
coef0
|
float | list[float]
|
Polynomial and sigmoid kernel constant. Per-view. Default is 1. |
1.0
|
kernel_params
|
dict[str, object] | list[dict[str, object]] | None
|
Extra kernel keyword arguments. Per-view. Default is None. |
None
|
Attributes:
| Name | Type | Description |
|---|---|---|
weights_ |
list[ndarray]
|
Dual coefficients of each view, shape (n_samples, n_components). |
views_fit_ |
list[ndarray]
|
The centred training views, against which the kernel of a new view is evaluated and centred. |
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.
Examples:
>>> import numpy as np
>>> from cca_zoo.nonparametric import KCCA
>>> rng = np.random.default_rng(0)
>>> X1 = rng.standard_normal((30, 5))
>>> X2 = rng.standard_normal((30, 5))
>>> model = KCCA(n_components=2, kernel="rbf", shrinkage=0.1).fit([X1, X2])
Source code in cca_zoo/nonparametric/_kcca.py
fit ¶
Fit the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
views
|
list[ArrayLike]
|
Arrays of shape (n_samples, n_features_i), one per view. |
required |
y
|
None
|
Ignored. |
None
|
Returns:
| Type | Description |
|---|---|
KCCA
|
self. |
Source code in cca_zoo/nonparametric/_kcca.py
KGCCA ¶
KGCCA(
n_components: int = 1,
*,
center: bool = True,
shrinkage: float | list[float] = 0.1,
kernel: str | list[str] = "linear",
gamma: float | list[float | None] | None = None,
degree: float | list[float] = 3,
coef0: float | list[float] = 1.0,
kernel_params: dict[str, object]
| list[dict[str, object]]
| None = None,
view_weights: list[float] | None = None,
)
Bases: _BaseKernelModel
Kernel generalized CCA.
:class:~cca_zoo.linear.GCCA in each view's kernel feature space. With
centred kernels \(K_i\), \(T\) holds the top eigenvectors of
\(\sum_i \mu_i K_i ((1 - c_i) K_i^2 / (n - 1) + c_i K_i)^{-1} K_i\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_components
|
int
|
Number of latent dimensions. Default is 1. |
1
|
center
|
bool
|
Whether to centre each view. Default is True. |
True
|
shrinkage
|
float | list[float]
|
Shrinkage of each view's covariance in the kernel feature
space towards the identity, in |
0.1
|
kernel
|
str | list[str]
|
Kernel name or callable for
:func: |
'linear'
|
gamma
|
float | list[float | None] | None
|
Kernel coefficient for RBF, polynomial and sigmoid kernels. Per-view. Default is None. |
None
|
degree
|
float | list[float]
|
Polynomial kernel degree. Per-view. Default is 3. |
3
|
coef0
|
float | list[float]
|
Polynomial and sigmoid kernel constant. Per-view. Default is 1. |
1.0
|
kernel_params
|
dict[str, object] | list[dict[str, object]] | None
|
Extra kernel keyword arguments. Per-view. Default is None. |
None
|
view_weights
|
list[float] | None
|
Weight of each view; None weights them equally. Default is None. |
None
|
Attributes:
| Name | Type | Description |
|---|---|---|
weights_ |
list[ndarray]
|
Dual coefficients of each view, shape (n_samples, n_components). |
views_fit_ |
list[ndarray]
|
The centred training views, against which the kernel of a new view is evaluated and centred. |
References
Tenenhaus, A., Philippe, C., & Frouin, V. (2015). Kernel generalized canonical correlation analysis. Computational Statistics & Data Analysis, 90, 114-131.
Examples:
>>> import numpy as np
>>> from cca_zoo.nonparametric import KGCCA
>>> 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(n_components=2, kernel="rbf").fit([X1, X2, X3])
Source code in cca_zoo/nonparametric/_kgcca.py
fit ¶
Fit the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
views
|
list[ArrayLike]
|
Arrays of shape (n_samples, n_features_i), one per view. |
required |
y
|
None
|
Ignored. |
None
|
Returns:
| Type | Description |
|---|---|
KGCCA
|
self. |
Source code in cca_zoo/nonparametric/_kgcca.py
KTCCA ¶
KTCCA(
n_components: int = 1,
*,
center: bool = True,
shrinkage: float | list[float] = 0.1,
kernel: str | list[str] = "linear",
gamma: float | list[float | None] | None = None,
degree: float | list[float] = 3,
coef0: float | list[float] = 1.0,
kernel_params: dict[str, object]
| list[dict[str, object]]
| None = None,
init: str = "svd",
random_state: int | None = None,
)
Bases: _BaseKernelModel
Kernel tensor CCA.
:class:~cca_zoo.linear.TCCA in each view's kernel feature space:
PARAFAC of the cross-moment tensor of the whitened feature maps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_components
|
int
|
Number of latent dimensions. Default is 1. |
1
|
center
|
bool
|
Whether to centre each view. Default is True. |
True
|
shrinkage
|
float | list[float]
|
Shrinkage of each view's covariance in the kernel feature
space towards the identity, in |
0.1
|
kernel
|
str | list[str]
|
Kernel name or callable for
:func: |
'linear'
|
gamma
|
float | list[float | None] | None
|
Kernel coefficient for RBF, polynomial and sigmoid kernels. Per-view. Default is None. |
None
|
degree
|
float | list[float]
|
Polynomial kernel degree. Per-view. Default is 3. |
3
|
coef0
|
float | list[float]
|
Polynomial and sigmoid kernel constant. Per-view. Default is 1. |
1.0
|
kernel_params
|
dict[str, object] | list[dict[str, object]] | None
|
Extra kernel keyword arguments. Per-view. Default is None. |
None
|
init
|
str
|
PARAFAC's initialisation, |
'svd'
|
random_state
|
int | None
|
Seed for |
None
|
Attributes:
| Name | Type | Description |
|---|---|---|
weights_ |
list[ndarray]
|
Dual coefficients of each view, shape (n_samples, n_components). |
views_fit_ |
list[ndarray]
|
The centred training views, against which the kernel of a new view is evaluated and centred. |
References
Luo, Y., Tao, D., Ramamohanarao, K., Xu, C., & Wen, Y. (2015). Tensor canonical correlation analysis for multi-view dimension reduction. IEEE Transactions on Knowledge and Data Engineering, 27(11), 3111-3124.
Examples:
>>> import numpy as np
>>> from cca_zoo.nonparametric import KTCCA
>>> 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(random_state=0).fit([X1, X2, X3])
Source code in cca_zoo/nonparametric/_ktcca.py
fit ¶
Fit the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
views
|
list[ArrayLike]
|
Arrays of shape (n_samples, n_features_i), one per view. |
required |
y
|
None
|
Ignored. |
None
|
Returns:
| Type | Description |
|---|---|
KTCCA
|
self. |
Source code in cca_zoo/nonparametric/_ktcca.py
ManifoldCCA ¶
ManifoldCCA(
n_components: int = 1,
*,
center: bool = True,
shrinkage: float | list[float] = 0.1,
method: str = "laplacian",
n_neighbors: int | list[int] = 10,
affinity: str | list[str] = "nearest_neighbors",
gamma: float | list[float | None] | None = None,
reg: float | list[float] = 0.001,
n_operator_components: int
| list[int | None]
| None = None,
)
Bases: BaseModel
Multiview CCA with a graph-operator constraint per view.
Maximises cross-view covariance of the training embeddings, restricted to
each view's smoothest eigenvectors of a graph Laplacian or LLE operator
M_i built from that view's neighbourhoods, subject to a blend of each
view's variance and its roughness on its graph:
The roughness is rescaled so its trace over the kept eigenvectors equals
their variance's, so that shrinkage means the same for either operator.
This is :class:~cca_zoo.linear.MCCA with shrinkage=c on each view's
operator eigenvectors scaled by the inverse square root of their rescaled
eigenvalues: shrinkage=0 is CCA between the views' smooth graph
coordinates, and shrinkage=1 PLS, which trades correlation for
smoothness. With identical views and shrinkage > 0 it reduces to the
view's :class:~sklearn.manifold.LocallyLinearEmbedding or, up to centring,
:class:~sklearn.manifold.SpectralEmbedding.
New points are embedded with each method's standard out-of-sample extension:
LLE barycentric weights for method="lle", the Nystrom extension for
method="laplacian"; either returns a training point's own embedding.
Fitting solves a dense (n M) x (n M)
eigenproblem, so it suits moderate sample sizes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_components
|
int
|
Number of latent dimensions. Default is 1. |
1
|
center
|
bool
|
Whether to centre each view. Default is True. |
True
|
shrinkage
|
float | list[float]
|
Blend of each view's constraint from its embedding's variance
(0, CCA) to its roughness on the view's graph (1, PLS), as
:class: |
0.1
|
method
|
str
|
|
'laplacian'
|
n_neighbors
|
int | list[int]
|
Neighbours in each view's graph. Per-view. Default is 10. |
10
|
affinity
|
str | list[str]
|
|
'nearest_neighbors'
|
gamma
|
float | list[float | None] | None
|
RBF kernel coefficient for |
None
|
reg
|
float | list[float]
|
Regularisation of each local reconstruction for
|
0.001
|
n_operator_components
|
int | list[int | None] | None
|
Smoothest operator eigenvectors kept per view
before the joint solve; fewer is stronger regularisation. |
None
|
Attributes:
| Name | Type | Description |
|---|---|---|
embedding_ |
Training embedding of each view, shape (n_samples, n_components). |
|
views_fit_ |
The centred training views, from which a new view's embedding is interpolated. |
References
Roweis, S. T., & Saul, L. K. (2000). Nonlinear dimensionality reduction by locally linear embedding. Science, 290(5500), 2323-2326.
Belkin, M., & Niyogi, P. (2003). Laplacian eigenmaps for dimensionality reduction and data representation. Neural Computation, 15(6), 1373-1396.
Examples:
>>> import numpy as np
>>> from cca_zoo.nonparametric import ManifoldCCA
>>> rng = np.random.default_rng(0)
>>> X1, X2 = rng.standard_normal((60, 8)), rng.standard_normal((60, 6))
>>> model = ManifoldCCA(n_neighbors=8).fit([X1, X2])
>>> Z1, Z2 = model.transform([X1, X2])
Source code in cca_zoo/nonparametric/_manifold_cca.py
fit ¶
Fit the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
views
|
list[ArrayLike]
|
Arrays of shape (n_samples, n_features_i), one per view. |
required |
y
|
None
|
Ignored. |
None
|
Returns:
| Type | Description |
|---|---|
ManifoldCCA
|
self. |
Source code in cca_zoo/nonparametric/_manifold_cca.py
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 | |