cca_zoo.probabilistic
.ProbabilisticRCCA#
- class cca_zoo.probabilistic.ProbabilisticRCCA(latent_dimensions: int = 1, copy_data=True, random_state: int = 0, learning_rate=0.1, n_iter=20000, num_samples=5000, num_warmup=5000)[source]#
Bases:
ProbabilisticCCA
Probabilistic Ridge Canonical Correlation Analysis (Probabilistic Ridge CCA).
Probabilistic Ridge CCA extends the Probabilistic Canonical Correlation Analysis model by introducing regularization terms in the linear relationships between multiple representations of data. This regularization improves the conditioning of the problem and provides a way to incorporate prior knowledge. It combines features of both CCA and Ridge Regression.
- Parameters:
c (float, default=1.0) – Regularization strength; must be a positive float. Regularization improves the conditioning of the problem and reduces the variance of the estimates. Larger values specify stronger regularization.
References
[1] De Bie, T. and De Moor, B., 2003. On the regularization of canonical correlation analysis. Int. Sympos. ICA and BSS, pp.785-790.
- average_pairwise_correlations(views: Iterable[ndarray], **kwargs) ndarray #
Calculate the average pairwise correlations between representations in each dimension.
- Parameters:
views (list/tuple of numpy arrays or array-like objects with the same number of rows (samples)) –
kwargs (any additional keyword arguments required by the given model) –
- Returns:
average_pairwise_correlations
- Return type:
numpy array of shape (latent_dimensions, )
- 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 representations (X_i), canonical variates from the representations 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 representations 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)#
Infer the parameters and latent variables of the Probabilistic Canonical Correlation Analysis (CCA) model.
- Parameters:
views (Iterable[np.ndarray]) – A list or tuple of numpy arrays representing different representations of the same samples. Each numpy array must have the same number of rows.
y (Any, optional) – Ignored in this implementation.
- Returns:
self – Returns the instance itself, updated with the inferred parameters and latent variables.
- Return type:
Notes
The data in each view should be normalized for optimal performance.
- fit_transform(X, y=None, **fit_params)#
Fit to data, then transform it.
Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.
- Parameters:
X (array-like of shape (n_samples, n_features)) – Input samples.
y (array-like of shape (n_samples,) or (n_samples, n_outputs), default=None) – Target values (None for unsupervised transformations).
**fit_params (dict) – Additional fit parameters.
- Returns:
X_new – Transformed array.
- Return type:
ndarray array of shape (n_samples, n_features_new)
- 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.
- pairwise_correlations(views: Iterable[ndarray], **kwargs) ndarray #
Calculate pairwise correlations between representations in each dimension.
- Parameters:
views (list/tuple of numpy arrays or array-like objects 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 #
Calculate the sum of average pairwise correlations between representations.
- Parameters:
views (list/tuple of numpy arrays or array-like objects with the same number of rows (samples)) –
y (None) –
kwargs (any additional keyword arguments required by the given model) –
- Returns:
score – Sum of average pairwise correlations between representations.
- Return type:
- set_fit_request(*, views: bool | None | str = '$UNCHANGED$') ProbabilisticRCCA #
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
. Otherwise it has no effect.
- set_output(*, transform=None)#
Set output container.
See Introducing the set_output API for an example on how to use the API.
- Parameters:
transform ({"default", "pandas"}, default=None) –
Configure output of transform and fit_transform.
”default”: Default output format of a transformer
”pandas”: DataFrame output
None: Transform configuration is unchanged
- Returns:
self – Estimator instance.
- Return type:
estimator instance
- 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$') ProbabilisticRCCA #
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
. Otherwise it has no effect.
- set_transform_request(*, views: bool | None | str = '$UNCHANGED$') ProbabilisticRCCA #
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
. Otherwise it has no effect.
- transform(views: Iterable[ndarray], *args, **kwargs) List[ndarray] #
Transforms the given representations using the fitted model.
- 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
- 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]