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 -1 are ignored.

Parameters:
labelsarray of shape (n_samples,) or (n_epochs, n_samples)

Microstates labels attributed to each sample, i.e. the segmentation.

n_clustersint

The number of clusters, i.e. the number of microstates.

statstr

Aggregate statistic to compute transitions. Can be:

  • count: show the number of observations of each transition.

  • probability or proportion: normalize count such as the probabilities along the first axis is always equal to 1.

  • percent: normalize count such as the probabilities along the first axis is always equal to 100.

ignore_repetitionsbool

If True, ignores state repetitions. For example, the input sequence AAABBCCD will be transformed into ABCD before any calculation. This is equivalent to setting the duration of all states to 1 sample.

Returns:
Tarray of 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".