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]

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.

factor_loadings(views: Iterable[ndarray], normalize=True, **kwargs)

Returns the factor loadings for each view

Parameters:
  • views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) –

  • normalize (bool, optional) – Whether to normalize the factor loadings. Default is True.

  • kwargs (any additional keyword arguments required by the given model) –

Returns:

factor_loadings

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:

object

fit_transform(views: Iterable[ndarray], **kwargs)

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.

Parameters:

deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:

params – Parameter names mapped to their values.

Return type:

dict

pairwise_correlations(views: Iterable[ndarray], **kwargs)

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=None, **kwargs)

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:

float

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • 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.

Parameters:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in fit.

Returns:

self – The updated object.

Return type:

object

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • 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.

Parameters:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in score.

Returns:

self – The updated object.

Return type:

object

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to transform.

  • 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.

Parameters:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in transform.

Returns:

self – The updated object.

Return type:

object

transform(views: Iterable[ndarray], y=None, **kwargs)[source]

Predict the latent variables that generate the data in views using the sampled model parameters

Parameters:

views – list/tuple of numpy arrays or array likes with the same number of rows (samples)