cca_zoo.linear.CCA_EY#

class cca_zoo.linear.CCA_EY(latent_dimensions: int = 1, copy_data=True, random_state=None, tol=0.001, accept_sparse=None, batch_size=None, epochs=1, learning_rate=0.005, initialization: str | callable = 'random', early_stopping=False, patience=5, nesterov=True, momentum=0.9, dampening=0.0)[source]#

Bases: BaseGradientModel

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, validation_views=None, **trainer_kwargs)#

Fits the model to the given data

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:

self

Return type:

object

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.

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) 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:

float

set_fit_request(*, validation_views: bool | None | str = '$UNCHANGED$', views: bool | None | str = '$UNCHANGED$') CCA_EY#

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. Otherwise it has no effect.

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

  • 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_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$') CCA_EY#

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. 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$') CCA_EY#

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. 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], *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]