mdreg.fit_pca#

mdreg.fit_pca(data_4d, n_components=None)[source]#

Performs Principal Component Analysis (PCA) on a 4D dataset (3D spatial + 1D time).

The function reshapes the 4D array into a 2D matrix where each row represents the time series of a single voxel. PCA is then applied to this matrix to identify the principal components of the temporal variations.

Parameters:
  • data_4d (np.ndarray) – The input 4D array with shape (X, Y, Z, T), where T is the time dimension.

  • n_components (int, optional) – The number of principal components to keep. If None, all components are kept. Defaults to None.

Returns:

A tuple containing:
  • components (np.ndarray): The principal components (eigen-curves) of the

    time series. Shape: (n_components, T).

  • spatial_maps (np.ndarray): The 3D spatial weights (scores) for each

    component. Shape: (X, Y, Z, n_components).

  • explained_variance (np.ndarray): The amount of variance explained by

    each component.

Return type:

tuple