cedalion.sigdecomp.multimodal.utils_multimodal_models

Utility functions for multimodal models.

Functions

standardize(x[, dim, scale])

Standardize x along dimension dim.

validate_dimension_labels(X, Y, sample_name, ...)

Validates that X and Y datasets contain the expected dimension labels.

validate_dimension_sizes(Ntx, Nty, ...)

Validates dimension sizes of multimodal data.

validate_l1_reg(l1_reg)

Check correct format of L1 regularization parameter.

validate_l2_reg(l2_reg)

Check correct format of L2 regularization parameter.

validate_time_shifts(T, time_shifts)

Corroborate that time shifts have the right format and are within the data domain.

cedalion.sigdecomp.multimodal.utils_multimodal_models.validate_dimension_labels(
X: DataArray,
Y: DataArray,
sample_name: str,
featureX_name: str,
featureY_name: str,
)[source]

Validates that X and Y datasets contain the expected dimension labels.

This method checks that the data arrays X and Y contain the same sample label and corresponding X and Y feature labels.

Parameters:
  • X (DataArray) – Input data for modality X. Expected to have dimensions (sample_name, featureX_name).

  • Y (DataArray) – Input data for modality Y. Expected to have dimensions (sample_name, featureY_name).

  • sample_name (str) – Name of the sample dimension.

  • featureX_name (str) – Name of the feature dimension for X.

  • featureY_name (str) – Name of the feature dimension for Y.

Raises:

ValueError – If X or Y are missing the expected feature dimension labels.

cedalion.sigdecomp.multimodal.utils_multimodal_models.validate_dimension_sizes(Ntx: int, Nty: int, N_features: int, N_components: int) int[source]

Validates dimension sizes of multimodal data.

Takes the sample dimension sizes corresponding to X and Y datasets, Ntx and Nty, the number of features and the number of components and corroborate the they are consistent among themselves.

Parameters:
  • Ntx (int) – Number of samples in X.

  • Nty (int) – Number of samples in Y.

  • N_features (int) – Number of features in X and Y.

  • N_components (int) – Number of components to extract.

Returns:

updated number of components.

Return type:

N (int)

Raises:

ValueError – If X or Y do not have the expected dimensions, if the number of samples between X and Y is inconsistent, or if the number of components exceeds the number of features.

cedalion.sigdecomp.multimodal.utils_multimodal_models.validate_l1_reg(l1_reg: float | list[float, float]) list[float, float][source]

Check correct format of L1 regularization parameter.

Parameters:

l1_reg (float or list of floats) – L1 regularization parameter(s) for sparsity. If a scalar, the same value is applied to both u and v; if a list of two values, the first is used for u and the second for v.

Returns:

List with L1 regularization parameters, the first is used for u

and the second for v.

Return type:

list of floats

cedalion.sigdecomp.multimodal.utils_multimodal_models.validate_l2_reg(l2_reg: float | list[float, float]) list[float, float][source]

Check correct format of L2 regularization parameter.

Parameters:

l2_reg (float or list of floats) – L2 regularization parameter(s) for normalization. If a scalar, the same value is applied to both u and v; if a list of two values, the first is used for u and the second for v.

Returns:

List with L2 regularization parameters, the first is used for u

and the second for v.

Return type:

list of floats

cedalion.sigdecomp.multimodal.utils_multimodal_models.validate_time_shifts(T: float, time_shifts: ndarray) ndarray[source]

Corroborate that time shifts have the right format and are within the data domain.

This method checks that the time shifts are positive and within the data domain. It also order the shifts in ascending order and adds zero lag at the beginning of the series if not present.

Parameters:
  • T (float) – Maximum time of the data.

  • time_shifts (np.ndarray) – Array of time shifts to consider.

Returns:

A tuple (time_shifts, N_shifts) where:

time_shifts (np.ndarray): Array of ordered, positive time shifts.

Return type:

tuple

cedalion.sigdecomp.multimodal.utils_multimodal_models.standardize(
x: DataArray,
dim: str = 'time',
scale: bool = True,
) tuple[DataArray, DataArray, DataArray][source]

Standardize x along dimension dim.

It standardizes the input data x along the specified dimension dim by removing the mean value and scaling to unit variance (if scale=True).

Parameters:
  • x (DataArray) – Input data to standardize.

  • dim (str) – Dimension to standardize along.

  • scale (bool) – Whether to scale the data to unit variance.

Returns:

A tuple (x_standard, mean, std) where:

x_standard (DataArray): Standardized version of x. mean (DataArray): Mean value of x along dimension dim. std (DataArray): Standard deviation of x along dimension dim.

Return type:

tuple