|
| 1 | +import logging |
| 2 | +import os |
| 3 | +import sys |
| 4 | + |
| 5 | +from fcest.helpers.data import to_3d_format |
| 6 | +import math |
| 7 | +from nilearn import connectome |
| 8 | +import numpy as np |
| 9 | +import pandas as pd |
| 10 | +from scipy import cluster |
| 11 | +from sklearn.cluster import KMeans |
| 12 | + |
| 13 | +from helpers.array_operations import reconstruct_symmetric_matrix_from_tril |
| 14 | +from helpers.brain_states import compute_basis_state, extract_number_of_brain_state_switches |
| 15 | +from helpers.icc import compute_icc_scores_pingouin |
| 16 | + |
| 17 | + |
| 18 | +class BrainStatesExtractor: |
| 19 | + |
| 20 | + def __init__( |
| 21 | + self, |
| 22 | + connectivity_metric: str, |
| 23 | + num_time_series: int, |
| 24 | + tvfc_estimates: np.array, |
| 25 | + ) -> None: |
| 26 | + """ |
| 27 | + Class for extracting brain states from TVFC estimates. |
| 28 | +
|
| 29 | + Parameters |
| 30 | + ---------- |
| 31 | + connectivity_metric : str, default='correlation' |
| 32 | + tvfc_estimates : np.array |
| 33 | + Array of shape (num_subjects, num_time_steps, num_features). |
| 34 | + """ |
| 35 | + logging.info("Initializing BrainStatesExtractor...") |
| 36 | + |
| 37 | + self.connectivity_metric = connectivity_metric |
| 38 | + self.num_time_steps = tvfc_estimates.shape[1] |
| 39 | + self.num_time_series = num_time_series |
| 40 | + |
| 41 | + self.tvfc_estimates_tril = tvfc_estimates.reshape(-1, tvfc_estimates.shape[-1]) |
| 42 | + |
| 43 | + def extract_brain_states( |
| 44 | + self, |
| 45 | + num_brain_states: int, |
| 46 | + ): |
| 47 | + """ |
| 48 | + Extract brain states from TVFC estimates. |
| 49 | +
|
| 50 | + Parameters |
| 51 | + ---------- |
| 52 | + num_brain_states : int |
| 53 | + """ |
| 54 | + return self.compute_basis_state( |
| 55 | + all_subjects_tril_tvfc=self.tvfc_estimates_tril, |
| 56 | + num_basis_states=num_brain_states, |
| 57 | + num_time_series=self.num_time_series, |
| 58 | + num_time_steps=self.num_time_steps, |
| 59 | + ) |
0 commit comments