cca_zoo.probabilisticο
- class cca_zoo.probabilistic.ProbabilisticCCA(latent_dimensions: int = 1, copy_data=True, random_state: int = 0, num_samples=100, num_warmup=100)[source]ο
Bases:
BaseModel
A class used to fit a Probabilistic CCA model using variational inference.
Probabilistic CCA is a generative model that assumes each view of data is generated from a shared latent variable z and some view-specific parameters (mu: mean, psi: covariance, W: weight matrix). The model can be written as:
z ~ N(0, I) x_i ~ N(W_i z + mu_i, psi_i)
The model parameters and the latent variables are inferred using MCMC sampling with the NUTS algorithm.
- Parameters:
latent_dimensions (int, optional) β Number of latent dimensions to use, by default 1
copy_data (bool, optional) β Whether to copy the data, by default True
random_state (int, optional) β Random state, by default 0
num_samples (int, optional) β Number of samples to use in MCMC, by default 100
num_warmup (int, optional) β Number of warmup samples to use in MCMC, by default 100
References
Bach, Francis R., and Michael I. Jordan. βA probabilistic interpretation of canonical correlation analysis.β (2005). Wang, Chong. βVariational Bayesian approach to canonical correlation analysis.β IEEE Transactions on Neural Networks 18.3 (2007): 905-910.
- canonical_loadings(views: Iterable[ndarray], normalize: bool = True, **kwargs) List[ndarray] ο
Calculate canonical loadings for each view.
Canonical loadings represent the correlation between the original variables in a view and their respective canonical variates. Canonical variates are linear combinations of the original variables formed to maximize the correlation with canonical variates from another view.
Mathematically, given two views (X_i), canonical variates from the views are:
(Z_i = w_i^T X_i)
The canonical loading for a variable in (X_i) is the correlation between that variable and (Z_i).
- Parameters:
views (list/tuple of numpy arrays) β Each array corresponds to a view. All views must have the same number of rows (observations).
- Returns:
loadings β Canonical loadings for each view. High absolute values indicate that the respective original variables play a significant role in defining the canonical variate.
- Return type:
list of numpy arrays
- explained_covariance(views: Iterable[ndarray]) ndarray ο
Calculates the covariance matrix of the transformed components for each view.
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
- Returns:
explained_covariances β Covariance matrices for the transformed components of each view.
- Return type:
list of numpy arrays
- explained_covariance_cumulative(views: Iterable[ndarray]) ndarray ο
Calculates the cumulative explained covariance ratio for each latent dimension for each view.
- Returns:
cumulative_ratios
- Return type:
list of numpy arrays
- explained_variance(views: Iterable[ndarray]) List[ndarray] ο
Calculates the variance captured by each latent dimension for each view.
- Returns:
transformed_vars
- Return type:
list of numpy arrays
- explained_variance_cumulative(views: Iterable[ndarray]) List[ndarray] ο
Calculates the cumulative explained variance ratio for each latent dimension for each view.
- Returns:
cumulative_ratios
- Return type:
list of numpy arrays
- explained_variance_ratio(views: Iterable[ndarray]) List[ndarray] ο
Calculates the ratio of the variance captured by each latent dimension to the total variance for each view.
- Returns:
explained_variance_ratios
- Return type:
list of numpy arrays
- fit(views: Iterable[ndarray], y=None)[source]ο
Infer the parameters and latent variables of the Probabilistic CCA model.
- Parameters:
views (Iterable[np.ndarray]) β A list or tuple of numpy arrays or array likes with the same number of rows (samples)
- Returns:
self β Returns the instance itself.
- Return type:
- fit_transform(views: Iterable[ndarray], **kwargs) List[ndarray] ο
Fits the model to the given data and returns the transformed views
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
transformed_views
- Return type:
list of numpy arrays
- get_metadata_routing()ο
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
- Returns:
routing β A
MetadataRequest
encapsulating routing information.- Return type:
MetadataRequest
- get_params(deep=True)ο
Get parameters for this estimator.
- property loadings: List[ndarray]ο
Compute and return loadings for each view. These are cached for performance optimization.
In the context of the cca-zoo models, loadings are the normalized weights. Due to the structure of these models, weight vectors are normalized such that wβXβXw = 1, as opposed to wβw = 1, which is commonly used in PCA. As a result, when computing the loadings, the weights are normalized to have unit norm, ensuring that the loadings range between -1 and 1.
Itβs essential to differentiate between these loadings and canonical loadings. The latter are correlations between the original variables and their corresponding canonical variates.
- Returns:
Loadings for each view.
- Return type:
List[np.ndarray]
- pairwise_correlations(views: Iterable[ndarray], **kwargs) ndarray ο
Returns the pairwise correlations between the views in each dimension
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
pairwise_correlations
- Return type:
numpy array of shape (n_views, n_views, latent_dimensions)
- score(views: Iterable[ndarray], y: Any | None = None, **kwargs) float ο
Returns the average pairwise correlation between the views
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
y (None) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
score
- Return type:
- set_fit_request(*, views: bool | None | str = '$UNCHANGED$') ProbabilisticCCA ο
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- set_params(**params)ο
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as
Pipeline
). The latter have parameters of the form<component>__<parameter>
so that itβs possible to update each component of a nested object.- Parameters:
**params (dict) β Estimator parameters.
- Returns:
self β Estimator instance.
- Return type:
estimator instance
- set_score_request(*, views: bool | None | str = '$UNCHANGED$') ProbabilisticCCA ο
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed toscore
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it toscore
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- set_transform_request(*, views: bool | None | str = '$UNCHANGED$') ProbabilisticCCA ο
Request metadata passed to the
transform
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed totransform
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it totransform
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.