pycrostates.segmentation.RawSegmentation#
- class pycrostates.segmentation.RawSegmentation(*args, **kwargs)[source]#
Contains the segmentation of a
Rawinstance.- Parameters:
- labels
arrayof shape(n_samples,) Microstates labels attributed to each sample, i.e. the segmentation.
- raw
Raw Rawinstance used for prediction.- cluster_centers
array(n_clusters, n_channels) Clusters, i.e. the microstates maps used to compute the segmentation.
- cluster_names
list|None Name of the clusters.
- predict_parameters
dict|None The prediction parameters.
- labels
- Attributes:
cluster_centers_Cluster centers (i.e topographies) used to compute the segmentation.
cluster_namesName of the cluster centers.
labelsMicrostate label attributed to each sample (the segmentation).
predict_parametersParameters used to predict the current segmentation.
rawRawinstance from which the segmentation was computed.
Methods
compute_expected_transition_matrix([stat, ...])Compute the expected transition matrix.
compute_parameters([norm_gfp, return_dist])Compute microstate parameters.
compute_transition_matrix([stat, ...])Compute the observed transition matrix.
entropy([ignore_repetitions, log_base])Compute the Shannon entropy of the segmentation.
plot([tmin, tmax, cmap, axes, cbar_axes, ...])Plot the segmentation.
plot_cluster_centers([axes, block, show])Plot cluster centers as topographic maps.
- compute_expected_transition_matrix(stat='probability', ignore_repetitions=True)#
Compute the expected transition matrix.
Compute the theoretical transition matrix as if time course was ignored, but microstate proportions kept (i.e. shuffled segmentation). This matrix can be used to quantify/correct the effect of microstate time coverage on the observed transition matrix obtained with the method
compute_expected_transition_matrix. Transition “from” and “to” unlabeled segments-1are ignored.- Parameters:
- stat
str Aggregate statistic to compute transitions. Can be:
probabilityorproportion: normalize count such as the probabilities along the first axis is always equal to1.percent: normalize count such as the probabilities along the first axis is always equal to100.
- ignore_repetitions
bool If
True, ignores state repetitions. For example, the input sequenceAAABBCCDwill be transformed intoABCDbefore any calculation. This is equivalent to setting the duration of all states to 1 sample.
- stat
- Returns:
- T
arrayof shape(n_cluster, n_cluster) Array of transition probability values from one label to another. First axis indicates state
"from". Second axis indicates state"to".
- T
- compute_parameters(norm_gfp=True, return_dist=False)#
Compute microstate parameters.
Warning
When working with
Epochs, this method will put together segments of all epochs. This could lead to wrong interpretation especially on state durations. To avoid this behaviour, make sure to set thereject_edgesparameter toTruewhen creating the segmentation.- Parameters:
- norm_gfp
bool If True, the global field power (GFP) is normalized.
- return_dist
bool If True, return the parameters distributions.
- norm_gfp
- Returns:
- dict
dict Dictionaries containing microstate parameters as key/value pairs. Keys are named as follow:
'{microstate name}_{parameter name}'.Available parameters are listed below:
mean_corr: Mean correlation value for each time point assigned to a given state.gev: Global explained variance expressed by a given state. It is the sum of global explained variance values of each time point assigned to a given state.timecov: Time coverage, the proportion of time during which a given state is active. This metric is expressed as a ratio.meandurs: Mean durations of segments assigned to a given state. This metric is expressed in seconds (s).occurrences: Occurrences per second, the mean number of segment assigned to a given state per second. This metrics is expressed in segment per second.dist_corr(req.return_dist=True): Distribution of correlations values of each time point assigned to a given state.dist_gev(req.return_dist=True): Distribution of global explained variances values of each time point assigned to a given state.dist_durs(req.return_dist=True): Distribution of durations of each segments assigned to a given state. Each value is expressed in seconds (s).
- dict
- compute_transition_matrix(stat='probability', ignore_repetitions=True)#
Compute the observed transition matrix.
Count the number of transitions from one state to another and aggregate the result as statistic. Transition “from” and “to” unlabeled segments
-1are ignored.- Parameters:
- %(stat_transition)s
- %(ignore_repetitions)s
- Returns:
- %(transition_matrix)s
Notes
Warning
When working with
Epochs, this method will take into account transitions that occur between epochs. This could lead to wrong interpretation when working with discontinuous data. To avoid this behaviour, make sure to set thereject_edgesparameter toTruewhen predicting the segmentation.
- entropy(ignore_repetitions=False, log_base=2)#
Compute the Shannon entropy of the segmentation.
Compute the Shannon entropy[1] of the microstate symbolic sequence.
- Parameters:
- ignore_repetitions
bool If
True, ignores state repetitions. For example, the input sequenceAAABBCCDwill be transformed intoABCDbefore any calculation. This is equivalent to setting the duration of all states to 1 sample.- log_base
float|str The log base to use. If string: *
bits: log_base =2*natural: log_base =np.e*dits: log_base =10Default tobits.
- ignore_repetitions
- Returns:
- h
float The Shannon entropy.
- h
References
- plot(tmin=None, tmax=None, cmap=None, axes=None, cbar_axes=None, *, block=False, show=None, verbose=None)[source]#
Plot the segmentation.
- Parameters:
- tmin
float Start time of the raw data to use in seconds (must be >= 0).
- tmax
float|None End time of the raw data to use in seconds (cannot exceed data duration). If
None(default), the current end of the data is used.- cmap
str| colormap |None The colormap to use. If None,
viridisis used.- axes
Axes|None Either
Noneto create a new figure or axes on which the segmentation is plotted.- cbar_axes
Axes|None Axes on which to draw the colorbar, otherwise the colormap takes space from the main axes.
- block
bool Whether to halt program execution until the figure is closed.
- show
bool|None If True, the figure is shown. If None, the figure is shown if the matplotlib backend is interactive.
- verbose
int|str|bool|None Sets the verbosity level. The verbosity increases gradually between
"CRITICAL","ERROR","WARNING","INFO"and"DEBUG". If None is provided, the verbosity is set to"WARNING". If a bool is provided, the verbosity is set to"WARNING"for False and to"INFO"for True.
- tmin
- Returns:
- fig
Figure Matplotlib figure containing the segmentation.
- fig
- plot_cluster_centers(axes=None, *, block=False, show=None)#
Plot cluster centers as topographic maps.
- Parameters:
- axes
Axes|None Either
Noneto create a new figure or axes (or an array of axes) on which the topographic map should be plotted. If the number of microstates maps to plot is≥ 1, an array of axes of sizen_clustersshould be provided.- block
bool Whether to halt program execution until the figure is closed.
- show
bool|None If True, the figure is shown. If None, the figure is shown if the matplotlib backend is interactive.
- axes
- Returns:
- fig
Figure Matplotlib figure containing the topographic plots.
- fig
- property cluster_centers_#
Cluster centers (i.e topographies) used to compute the segmentation.
- Type: