pycrostates.segmentation.compute_transition_matrix#
- pycrostates.segmentation.compute_transition_matrix(labels, n_clusters, stat='probability', ignore_repetitions=True)[source]#
Compute the observed transition matrix.
Count the number of transitions from one state to another and aggregate the result as statistic. Transitions “from” and “to” unlabeled segments
-1are ignored.- Parameters:
- labels
arrayof shape(n_samples,)or(n_epochs, n_samples) Microstates labels attributed to each sample, i.e. the segmentation.
- n_clusters
int The number of clusters, i.e. the number of microstates.
- stat
str Aggregate statistic to compute transitions. Can be:
count: show the number of observations of each transition.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.
- labels
- 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