comet.connectivity
- class comet.connectivity.CoactivationPatterns(time_series: ndarray | list, n_states: int = 5, subject_clusters: int = 5, random_state: int | None = None, n_init: int = 50, progress_bar: bool = True)[source]
Bases:
ConnectivityMethodCo-activation patterns (state-based connectivity).
References
Torabi, M., Mitsis, G. D., & Poline, J. B. (2024). On the variability of dynamic functional connectivity assessment methods. GigaScience, 13, giae009. https://doi.org/10.1093/gigascience/giae009
- Parameters:
time_series (list or np.ndarray) – The input time series data.
n_states (int, optional) – Number of states for the method. Default is 5.
subject_clusters (int, optional) – Number of subject clusters. Default is 5.
- estimate()[source]
Estimate state-based connectivity
- Returns:
np.ndarray – State time course (n_subjects x T)
np.ndarray – Connectivity states (P x P x n_states)
- name = 'STATE Co-activation Patterns'
- class comet.connectivity.ConnectivityMethod(time_series, diagonal=0, fisher_z=False, tril=False)[source]
Bases:
objectBase class for all dynamic functional connectivity methods.
- time_series
Time series data.
- Type:
np.ndarray
- T
Number of timepoints.
- Type:
int
- P
Number of parcels.
- Type:
int
- diagonal
Value to set on the diagonal of connectivity matrices.
- Type:
int or float
- fisher_z
Whether to apply Fisher z-transformation.
- Type:
bool
- tril
Whether to return only the lower triangle of the matrices.
- Type:
bool
- class comet.connectivity.ContinuousHMM(time_series: ndarray | list, n_states: int = 5, hmm_iter: int = 20, progress_bar: bool = True)[source]
Bases:
ConnectivityMethodContinuous hidden markov model (state-based connectivity).
References
Torabi, M., Mitsis, G. D., & Poline, J. B. (2024). On the variability of dynamic functional connectivity assessment methods. GigaScience, 13, giae009. https://doi.org/10.1093/gigascience/giae009
- Parameters:
time_series (list or np.ndarray) – The input time series data.
n_states (int, optional) – Number of states for the method. Default is 5.
hmm_iter (int, optional) – Number of iterations for the HMM. Default is 20.
- estimate()[source]
Estimate state-based connectivity
- Returns:
np.ndarray – State time course (n_subjects x T)
np.ndarray – Connectivity states (P x P x n_states)
- name = 'STATE Continuous Hidden Markov Model'
- class comet.connectivity.DCC(time_series: ndarray, num_cores: int = 16, standardizeData: bool = True, progress_bar: bool = True, diagonal: int = 0, fisher_z: bool = False, tril: bool = False)[source]
Bases:
ConnectivityMethodDynamic Conditional Correlation (DCC) as described by Lindquist et al. (2014).
- Parameters:
time_series (np.ndarray) – The input time series data.
num_cores (int, optional) – Number of CPU cores to use for parallel processing. Default is 16.
standardizeData (bool, optional) – Whether to standardize the time series data. Default is True.
diagonal (int, optional) – Value to set on the diagonal of connectivity matrices. Default is 0.
fisher_z (bool, optional) – Whether to apply Fisher z-transformation. Default is False.
tril (bool, optional) – Whether to return only the lower triangle of the matrices. Default is False.
References
Lindquist, M. A., Xu, Y., Nebel, M. B., & Caffo, B. S. (2014). Evaluating dynamic bivariate correlations in resting-state fMRI: a comparison study and a new approach. NeuroImage, 101, 531-546. https://doi.org/10.1016/j.neuroimage.2014.06.052
- estimate()[source]
DCC algorithm
- Parameters:
theta (T-by-N matrix) – fMRI time series data
- Returns:
R – estimated dynamic conditional correlation tensor
- Return type:
N*N*T np.ndarray
- name = 'CONT Dynamic Conditional Correlation'
- class comet.connectivity.DiscreteHMM(time_series: ndarray | list, n_states: int = 5, state_ratio: float = 0.6, subject_clusters: int = 5, windowsize: int = 29, shape: Literal['rectangular', 'gaussian', 'hamming'] = 'gaussian', std: float = 10, stepsize: int = 15, hmm_iter: int = 20, progress_bar: bool = True)[source]
Bases:
ConnectivityMethodDiscrete hidden markov model (state-based connectivity).
References
Torabi, M., Mitsis, G. D., & Poline, J. B. (2024). On the variability of dynamic functional connectivity assessment methods. GigaScience, 13, giae009. https://doi.org/10.1093/gigascience/giae009
- Parameters:
time_series (list or np.ndarray) – The input time series data.
n_states (int, optional) – Number of states for the method. Default is 5.
state_ratio (float, optional) – Ratio of states to use for clustering. Default is 3/5.
subject_clusters (int, optional) – Number of subject clusters. Default is 5.
windowsize (int, optional) – Size of the sliding window. Default is 29.
shape (str, optional) – Shape of the window. Default is “gaussian”.
std (float, optional) – Standard deviation for gaussian window. Default is 10.
stepsize (float, optional) – Step size for the sliding window. Default is 15.
hmm_iter (int, optional) – Number of iterations for the HMM. Default is 20.
- estimate()[source]
Estimate state-based connectivity
- Returns:
np.ndarray – State time course (n_subjects x T)
np.ndarray – Connectivity states (P x P x n_states)
- name = 'STATE Discrete Hidden Markov Model'
- class comet.connectivity.EdgeConnectivity(time_series: ndarray, method: Literal['eTS', 'eFC'] = 'eTS', standardizeData: bool = True, labels: list = None, vlim: float = 3)[source]
Bases:
ConnectivityMethodEdge-centric connectivity method.
- Parameters:
time_series (np.ndarray) – The input time series data.
method (string, optional) –
- The specific connectivity to calculate. Default is “eTS”.
eTS: returns the edge time series (edges x time)
eFC: returns the edge functional connectivity (edges x edges x time).
standardizeData (bool, optional) – Whether to standardize the time series data. Default is True.
vlim (float, optional) – Limit for plotting in the GUI (not used in the method itself). Default is 3.
References
Faskowitz, J., Esfahlani, F. Z., Jo, Y., Sporns, O., & Betzel, R. F. (2020). Edge-centric functional network representations of human cerebral cortex reveal overlapping system-level architecture. Nature neuroscience, 23(12), 1644–1654. DOI: https://doi.org/10.1038/s41593-020-00719-y
- estimate()[source]
Calculate edge-centric connectivity (eTS or eFC).
- Returns:
- Dynamic functional connectivity depending on the method.
For eTS: Time x Edge array. For eFC: Edge x Edge x Time array.
- Return type:
np.ndarray
- name = 'CONT Edge-centric Connectivity'
- class comet.connectivity.FlexibleLeastSquares(time_series: ndarray, standardizeData: bool = True, mu: float = 100.0, num_cores: int = 4, progress_bar: bool = True, diagonal: int = 0, fisher_z: bool = False, tril: bool = False)[source]
Bases:
ConnectivityMethodFlexible Least Squares connectivity method.
This implementation estimates dynamic functional connectivity using the Flexible Least Squares (FLS) algorithm as described in the DynamicBC toolbox.
For each source region i, the FLS linear system is built once and solved against all target time series simultaneously. Parallel execution across regions is supported via joblib.
- Parameters:
time_series (np.ndarray) – The input time series data of shape (T, P), where T is the number of time points and P the number of regions.
standardizeData (bool, optional) – Whether to standardize the time series column-wise before estimation. Default is True.
mu (float, optional) – Regularization parameter controlling the smoothness of betas. Default is 100.0.
num_cores (int, optional) – Number of CPU cores to use for parallel processing. Set to 1 for single-core execution. Default is 4.
progress_bar (bool, optional) – Whether to display a progress bar during estimation. Default is True.
diagonal (int, optional) – Value to set on the diagonal of connectivity matrices. Default is 0.
fisher_z (bool, optional) – Whether to apply Fisher z-transformation in post-processing. Default is False.
tril (bool, optional) – Whether to return only the lower triangle of the matrices. Default is False.
- dfc
The dynamic connectivity estimates of shape (P, P, T).
- Type:
np.ndarray
- N_estimates
Number of estimates (equals the number of time points T).
- Type:
int
References
Liao, W., Wu, G. R., Xu, Q., Ji, G. J., Zhang, Z., Zang, Y. F., & Lu, G. (2014). DynamicBC: a MATLAB toolbox for dynamic brain connectome analysis. Brain Connectivity, 4(10), 780–790. https://doi.org/10.1089/brain.2014.0253
- estimate() ndarray[source]
Estimate dynamic functional connectivity using FLS.
- Returns:
Dynamic connectivity as a (P, P, T) array, symmetrized and post-processed according to class settings.
- Return type:
np.ndarray
- name = 'CONT Flexible Least Squares'
- class comet.connectivity.Jackknife(time_series: ndarray, windowsize: int = 1, stepsize: int = 1, diagonal: int = 0, fisher_z: bool = False, tril: bool = False)[source]
Bases:
ConnectivityMethodJackknife correlation method.
- Parameters:
time_series (np.ndarray) – The input time series data.
windowsize (int, optional) – Size of the sliding window. Default is 1.
stepsize (int, optional) – Step size for sliding the window. Default is 1.
diagonal (int, optional) – Value to set on the diagonal of connectivity matrices. Default is 0.
fisher_z (bool, optional) – Whether to apply Fisher z-transformation. Default is False.
tril (bool, optional) – Whether to return only the lower triangle of the matrices. Default is False.
References
Richter CG, Thompson WH, Bosman CA, Fries P. A jackknife approach to quantifying single-trial correlation between covariance-based metrics undefined on a single-trial basis. https://doi.org/10.1016/j.neuroimage.2015.04.040
- centers()[source]
Calculate the central index of each window so dynamic functional connectivity (dFC) estimates can be related to the original time series.
- Returns:
Central index of each window.
- Return type:
np.ndarray
- estimate()[source]
Calculate jackknife correlation.
- Returns:
Dynamic functional connectivity as a PxPxN array.
- Return type:
np.ndarray
- name = 'CONT Jackknife Correlation'
- class comet.connectivity.KSVD(time_series: ndarray | list, n_states: int = 5)[source]
Bases:
ConnectivityMethodWindowless state-based connectivity based on K-SVD.
References
Torabi, M., Mitsis, G. D., & Poline, J. B. (2024). On the variability of dynamic functional connectivity assessment methods. GigaScience, 13, giae009. https://doi.org/10.1093/gigascience/giae009
Rubinstein, R., Zibulevsky, M., & Elad, M. (2008). Efficient implementation of the K-SVD algorithm using batch orthogonal matching pursuit. Cs Technion, 40(8), 1-15.
- Parameters:
time_series (list or np.ndarray) – The input time series data.
n_states (int, optional) – Number of states for the method. Default is 5.
- estimate()[source]
Estimate state-based connectivity
- Returns:
np.ndarray – State time course (n_subjects x T)
np.ndarray – Connectivity states (P x P x n_states)
- name = 'STATE K-SVD'
- class comet.connectivity.LeiDA(time_series: ndarray, flip_eigenvectors: bool = True, diagonal: int = 0, fisher_z: bool = False, tril: bool = False)[source]
Bases:
ConnectivityMethodLeading Eigenvector Dynamics.
- Parameters:
time_series (np.ndarray) – The input time series data.
flip_eigenvectors (bool, optional) – The sign of each leading eigenvector is adjusted so that the majority of its elements are negative. This ensures consistent orientation of eigenvectors across time points and subjects. Default is True.
diagonal (int, optional) – Value to set on the diagonal of connectivity matrices. Default is 0.
fisher_z (bool, optional) – Whether to apply Fisher z-transformation. Default is False.
tril (bool, optional) – Whether to return only the lower triangle of the matrices. Default is False.
References
Cabral, J., Vidaurre, D., Marques, P., Magalhães, R., Silva Moreira, P., Miguel Soares, J., … & Kringelbach, M. L. (2017). Cognitive performance in healthy older adults relates to spontaneous switching between states of functional connectivity during rest. Scientific reports, 7(1), 5135. https://doi.org/10.1038/s41598-017-05425-7
Olsen, A. S., Lykkebo-Valløe, A., Ozenne, B., Madsen, M. K., Stenbæk, D. S., Armand, S., … & Fisher, P. M. (2022). Psilocybin modulation of time-varying functional connectivity is associated with plasma psilocin and subjective effects. Neuroimage, 264, 119716. https://doi.org/10.1016/j.neuroimage.2022.119716
Vohryzek, J., Deco, G., Cessac, B., Kringelbach, M. L., & Cabral, J. (2020). Ghost attractors in spontaneous brain activity: Recurrent excursions into functionally-relevant BOLD phase-locking states. Frontiers in systems neuroscience, 14, 20. https://doi.org/10.3389/fnsys.2020.00020
- estimate()[source]
Calculate Leading Eigenvector Dynamics Analysis (LeiDA). The leading eigenvectors are saved in as the V1 attribute.
- Returns:
Dynamic functional connectivity as a PxPxN array.
- Return type:
np.ndarray
- name = 'CONT Leading Eigenvector Dynamics'
- class comet.connectivity.PhaseSynchronization(time_series: ndarray, method: Literal['crp', 'phcoh', 'teneto'] = 'crp', diagonal: int = 0, fisher_z: bool = False, tril: bool = False)[source]
Bases:
ConnectivityMethodInstantaneous Phase Synchronization methods.
- Parameters:
time_series (np.ndarray) – The input time series data.
method ({'crp', 'phcoh', 'teneto'}, optional) – The phase synchrony method to use. Default is ‘crp’.
diagonal (int, optional) – Value to set on the diagonal of connectivity matrices. Default is 0.
fisher_z (bool, optional) – Whether to apply Fisher z-transformation. Default is False.
tril (bool, optional) – Whether to return only the lower triangle of the matrices. Default is False.
References
Honari, H., Choe, A. S., & Lindquist, M. A. (2021). Evaluating phase synchronization methods in fMRI: A comparison study and new approaches. NeuroImage, 228, 117704. https://doi.org/10.1016/j.neuroimage.2020.117704
- estimate()[source]
Abstract method to compute the connectivity matrix. This method should be implemented in each child class.
- Raises:
NotImplementedError – If the method is not implemented in the child class.
- name = 'CONT Phase Synchronization'
- class comet.connectivity.SlidingWindow(time_series: ndarray, windowsize: int = 29, stepsize: int = 1, shape: Literal['rectangular', 'gaussian', 'hamming'] = 'rectangular', std: float = 10, diagonal: int = 0, fisher_z: bool = False, tril: bool = False)[source]
Bases:
ConnectivityMethodSliding Window connectivity method.
This is the most widely used dynamic functional connectivity method. It involves sliding a window over the data. Covariance is estimated for each windowed section.
- Parameters:
time_series (np.ndarray) – The input time series data.
windowsize (int, optional) – Size of the sliding window. Default is 29.
stepsize (int, optional) – Step size for sliding the window. Default is 1.
shape ({'rectangular', 'gaussian', 'hamming'}, optional) – Shape of the window. Default is ‘rectangular’.
std (float, optional) – Standard deviation for the Gaussian window. Default is 10.
diagonal (int, optional) – Value to set on the diagonal of connectivity matrices. Default is 0.
fisher_z (bool, optional) – Whether to apply Fisher z-transformation. Default is False.
tril (bool, optional) – Whether to return only the lower triangle of the matrices. Default is False.
- centers()[source]
Calculate the central index of each window so dynamic functional connectivity (dFC) estimates can be related to the original time series.
- Returns:
Central index of each window.
- Return type:
np.ndarray
- estimate()[source]
Calculate sliding window correlation.
- Returns:
Dynamic functional connectivity as a PxPxN array.
- Return type:
np.ndarray
- name = 'CONT Sliding Window'
- class comet.connectivity.SlidingWindowClustering(time_series: ndarray | list, n_states: int = 5, subject_clusters: int = 5, windowsize: int = 29, shape: Literal['rectangular', 'gaussian', 'hamming'] = 'gaussian', std: float = 10, stepsize: int = 15, random_state: int | None = None, n_init: int = 50, progress_bar: bool = True)[source]
Bases:
ConnectivityMethodSiding window clustering (SWC) state-based connectivity (2-level clustering).
References
Torabi, M., Mitsis, G. D., & Poline, J. B. (2024). On the variability of dynamic functional connectivity assessment methods. GigaScience, 13, giae009. https://doi.org/10.1093/gigascience/giae009
- Parameters:
time_series (list or np.ndarray) – The input time series data.
n_states (int, optional) – Number of states for the method. Default is 5.
subject_clusters (int, optional) – Number of clusters for the first level clustering. Default is 5.
windowsize (int, optional) – Size of the sliding window. Default is 29.
shape (str, optional) – Shape of the window. Default is “gaussian”.
std (float, optional) – Standard deviation for gaussian window. Default is 10.
stepsize (int, optional) – Step size for the sliding window. Default is 15.
- estimate()[source]
Estimate state-based connectivity
- Returns:
np.ndarray – State time course (n_subjects x T)
np.ndarray – Connectivity states (P x P x n_states)
- name = 'STATE Sliding Window Clustering'
- class comet.connectivity.SpatialDistance(time_series: ndarray, dist: Literal['euclidean', 'cosine', 'cityblock'] = 'euclidean', diagonal: int = 0, fisher_z: bool = False, tril: bool = False)[source]
Bases:
ConnectivityMethodSpatial Distance connectivity method.
- Parameters:
time_series (np.ndarray) – The input time series data.
dist ({'euclidean', 'cosine', 'cityblock'}, optional) – Type of distance metric to use. Default is ‘euclidean’.
diagonal (int, optional) – Value to set on the diagonal of connectivity matrices. Default is 0.
fisher_z (bool, optional) – Whether to apply Fisher z-transformation. Default is False.
tril (bool, optional) – Whether to return only the lower triangle of the matrices. Default is False.
References
William Hedley Thompson, Per Brantefors, Peter Fransson. From static to temporal network theory: Applications to functional brain connectivity. https://doi.org/10.1162/NETN_a_00011
- estimate()[source]
Calculate spatial distance correlation.
- Returns:
Dynamic functional connectivity as a PxPxN array.
- Return type:
np.ndarray
- name = 'CONT Spatial Distance'
- class comet.connectivity.Static_Covariance(time_series: ndarray, cov_estimator: Literal['LedoitWolf', None] = None, diagonal: int = 0, fisher_z: bool = False, tril: bool = False)[source]
Bases:
ConnectivityMethodStatic functional connectivity method using covariance.
- Parameters:
time_series (np.ndarray) – The input time series data.
cov_estimator (str, optional) – Shrinkage for covariance estimation. Can be None or Ledoit-Wolf. Default is None.
diagonal (int, optional) – Value to set on the diagonal of connectivity matrices. Default is 0.
fisher_z (bool, optional) – Whether to apply Fisher z-transformation. Default is False.
tril (bool, optional) – Whether to return only the lower triangle of the matrices. Default is False.
- estimate()[source]
Estimate the functional connectivity.
- Returns:
Static functional connectivity matrix.
- Return type:
np.ndarray
- name = 'STATIC Covariance'
- class comet.connectivity.Static_Mutual_Info(time_series: ndarray, num_bins: int = 10, diagonal: int = 0, fisher_z: bool = False, tril: bool = False)[source]
Bases:
ConnectivityMethodStatic functional connectivity method using mutual information.
- Parameters:
time_series (np.ndarray) – The input time series data.
num_bins (int, optional) – Number of bins to use for the mutual information calculation. Default is 10.
diagonal (int, optional) – Value to set on the diagonal of connectivity matrices. Default is 0.
fisher_z (bool, optional) – Whether to apply Fisher z-transformation. Default is False.
tril (bool, optional) – Whether to return only the lower triangle of the matrices. Default is False.
- estimate()[source]
Estimate the functional connectivity.
- Returns:
Static functional connectivity matrix.
- Return type:
np.ndarray
- name = 'STATIC Mutual Information'
- class comet.connectivity.Static_Partial(time_series: ndarray, cov_estimator: Literal['LedoitWolf', None] = None, diagonal: int = 0, fisher_z: bool = False, tril: bool = False)[source]
Bases:
ConnectivityMethodStatic functional connectivity method using partial correlation.
- Parameters:
time_series (np.ndarray) – The input time series data.
cov_estimator (str, optional) – Shrinkage for covariance estimation. Can be None or Ledoit-Wolf. Default is None.
diagonal (int, optional) – Value to set on the diagonal of connectivity matrices. Default is 0.
fisher_z (bool, optional) – Whether to apply Fisher z-transformation. Default is False.
tril (bool, optional) – Whether to return only the lower triangle of the matrices. Default is False.
- estimate()[source]
Estimate the functional connectivity.
- Returns:
Static functional connectivity matrix.
- Return type:
np.ndarray
- name = 'STATIC Partial Correlation'
- class comet.connectivity.Static_Pearson(time_series: ndarray, cov_estimator: Literal[None, 'LedoitWolf'] = None, diagonal: int = 0, fisher_z: bool = False, tril: bool = False)[source]
Bases:
ConnectivityMethodStatic functional connectivity method using Pearson correlation.
- Parameters:
time_series (np.ndarray) – The input time series data.
shrinkage (str, optional) – Shrinkage for covariance estimation. Can be None or Ledoit-Wolf. Default is None.
diagonal (int, optional) – Value to set on the diagonal of connectivity matrices. Default is 0.
fisher_z (bool, optional) – Whether to apply Fisher z-transformation. Default is False.
tril (bool, optional) – Whether to return only the lower triangle of the matrices. Default is False.
- estimate()[source]
Estimate the functional connectivity.
- Returns:
Static functional connectivity matrix.
- Return type:
np.ndarray
- name = 'STATIC Pearson Correlation'
- class comet.connectivity.TemporalDerivatives(time_series: ndarray, windowsize: int = 7, diagonal: int = 0, fisher_z: bool = False, tril: bool = False)[source]
Bases:
ConnectivityMethodMultiplication of Temporal Derivatives connectivity method.
- Parameters:
time_series (np.ndarray) – The input time series data.
windowsize (int, optional) – Size of the sliding window. Default is 7.
diagonal (int, optional) – Value to set on the diagonal of connectivity matrices. Default is 0.
fisher_z (bool, optional) – Whether to apply Fisher z-transformation. Default is False.
tril (bool, optional) – Whether to return only the lower triangle of the matrices. Default is False.
References
Shine JM, Koyejo O, Bell PT, Gorgolewski KJ, Gilat M, Poldrack RA. Estimation of dynamic functional connectivity using Multiplication of Temporal Derivatives. https://doi.org/10.1016/j.neuroimage.2015.07.064.
- centers()[source]
Calculate the central index of each window so dynamic functional connectivity (dFC) estimates can be related to the original time series.
- Returns:
Central index of each window.
- Return type:
np.ndarray
- estimate()[source]
Calculate multiplication of temporal derivatives.
- Returns:
Dynamic functional connectivity as a PxPxN array.
- Return type:
np.ndarray
- name = 'CONT Multiplication of Temporal Derivatives'
- class comet.connectivity.WaveletCoherence(time_series: ndarray, method: Literal['weighted'] = 'weighted', TR: float = 0.72, fmin: float = 0.007, fmax: float = 0.15, n_scales: int = 15, drop_scales: int = 2, drop_timepoints: int = 50, progress_bar: bool = True, diagonal: int = 0, fisher_z: bool = False, tril: bool = False)[source]
Bases:
ConnectivityMethodInstantaneous Wavelet Coherence.
- Parameters:
time_series (np.ndarray) – The input time series data.
method ({'weighted'}, optional) – The method to use for calculating wavelet coherence. Default is ‘weighted’.
TR (float, optional) – Repetition time of the data. Default is 0.72.
fmin (float, optional) – Minimum frequency for wavelet transform. Default is 0.007.
fmax (float, optional) – Maximum frequency for wavelet transform. Default is 0.15.
n_scales (int, optional) – Number of scales for wavelet transform. Default is 15.
drop_scales (int, optional) – Number of scales to drop from the edges. Default is 2.
drop_timepoints (int, optional) – Number of time points to drop from the edges. Default is 50.
diagonal (int, optional) – Value to set on the diagonal of connectivity matrices. Default is 0.
fisher_z (bool, optional) – Whether to apply Fisher z-transformation. Default is False.
tril (bool, optional) – Whether to return only the lower triangle of the matrices. Default is False.
References
Jacob Billings, Manish Saggar, Jaroslav Hlinka, Shella Keilholz, Giovanni Petri; Simplicial and topological descriptions of human brain dynamics. Network Neuroscience 2021; 5 (2): 549–568. https://doi.org/10.1162/netn_a_00190
- estimate()[source]
Calculate instantaneous wavelet coherence.
- Returns:
Dynamic functional connectivity as a PxPxN array.
- Return type:
np.ndarray
- name = 'CONT Wavelet Coherence'