cca_zoo.metrics¶
Metrics for evaluating fitted multiview CCA models. Functions take
already-computed arrays (latent scores, loadings, a correlation matrix)
rather than a fitted model, the same convention sklearn.metrics uses.
pairwise_correlations ¶
Pearson correlation between every pair of views' latent scores.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transformed
|
Sequence[ArrayLike]
|
Scores of shape (n_samples, n_components), one per view. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Shape (n_views, n_views, n_components); entry |
ndarray
|
correlates the d-th scores of views i and j. |
Examples:
>>> import numpy as np
>>> from cca_zoo.metrics import pairwise_correlations
>>> rng = np.random.default_rng(0)
>>> t1 = rng.standard_normal((20, 1))
>>> t2 = 0.8 * t1 + 0.2 * rng.standard_normal((20, 1))
>>> round(float(pairwise_correlations([t1, t2])[0, 1, 0]), 2)
0.98
Source code in cca_zoo/metrics/_correlation.py
average_pairwise_correlations ¶
Mean correlation over pairs of distinct views, per dimension.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
correlations
|
ArrayLike
|
Output of :func: |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Shape (n_components,). |
Source code in cca_zoo/metrics/_correlation.py
factor_loadings ¶
factor_loadings(
views: Sequence[ArrayLike],
transformed: Sequence[ArrayLike],
) -> list[np.ndarray]
Correlation of each feature with its own view's latent scores.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
views
|
Sequence[ArrayLike]
|
Arrays of shape (n_samples, n_features_i), one per view. |
required |
transformed
|
Sequence[ArrayLike]
|
Scores of shape (n_samples, n_components), one per view. |
required |
Returns:
| Type | Description |
|---|---|
list[ndarray]
|
One array of shape (n_features_i, n_components) per view. |
Examples:
>>> import numpy as np
>>> from cca_zoo.metrics import factor_loadings
>>> rng = np.random.default_rng(0)
>>> t1 = rng.standard_normal((20, 1))
>>> view1 = np.column_stack(
... [t1[:, 0] + 0.3 * rng.standard_normal(20), rng.standard_normal(20)]
... )
>>> round(float(factor_loadings([view1], [t1])[0][0, 0]), 2)
0.97
Source code in cca_zoo/metrics/_correlation.py
adequacy_coefficient ¶
Variance of each view extracted by its own canonical variates.
The mean squared factor loading per dimension (Cramer & Nicewander, 1979).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
loadings
|
Sequence[ArrayLike]
|
Loadings of shape (n_features_i, n_components), one per
view, as from :func: |
required |
Returns:
| Type | Description |
|---|---|
list[ndarray]
|
One array of shape (n_components,) per view. |
Examples:
>>> import numpy as np
>>> from cca_zoo.metrics import adequacy_coefficient, factor_loadings
>>> rng = np.random.default_rng(0)
>>> t1 = rng.standard_normal((20, 1))
>>> view1 = np.column_stack(
... [t1[:, 0] + 0.3 * rng.standard_normal(20), rng.standard_normal(20)]
... )
>>> adequacy = adequacy_coefficient(factor_loadings([view1], [t1]))
>>> round(float(adequacy[0][0]), 2)
0.48
Source code in cca_zoo/metrics/_redundancy.py
redundancy_index ¶
Stewart-Love redundancy: variance of view i explained through view j.
View i's adequacy times the squared canonical correlation between the
views' variates, per dimension. Asymmetric in i and j.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
loadings
|
Sequence[ArrayLike]
|
Loadings of shape (n_features_i, n_components), one per
view, as from :func: |
required |
correlations
|
ArrayLike
|
Shape (n_views, n_views, n_components), as from
:func: |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Shape (n_views, n_views, n_components); the diagonal is each view's |
ndarray
|
adequacy. |
Examples:
>>> import numpy as np
>>> from cca_zoo.metrics import (
... factor_loadings,
... pairwise_correlations,
... redundancy_index,
... )
>>> rng = np.random.default_rng(0)
>>> t1 = rng.standard_normal((20, 1))
>>> t2 = 0.8 * t1 + 0.2 * rng.standard_normal((20, 1))
>>> view1 = np.column_stack(
... [t1[:, 0] + 0.1 * rng.standard_normal(20), rng.standard_normal(20)]
... )
>>> view2 = np.column_stack(
... [t2[:, 0] + 0.1 * rng.standard_normal(20), rng.standard_normal(20)]
... )
>>> redundancy = redundancy_index(
... factor_loadings([view1, view2], [t1, t2]),
... pairwise_correlations([t1, t2]),
... )
>>> round(float(redundancy[0, 1, 0]), 2)
0.52
Source code in cca_zoo/metrics/_redundancy.py
total_redundancy ¶
Redundancy summed over dimensions, shape (n_views, n_views).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
redundancy
|
ArrayLike
|
Output of :func: |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Entry |