librosa.sequence.transition_cycle¶
- librosa.sequence.transition_cycle(n_states, prob)[source]¶
Construct a cyclic transition matrix over
n_states
.The transition matrix will have the following properties:
transition[i, i] = p
transition[i, i + 1] = (1 - p)
This type of transition matrix is appropriate for state spaces with cyclical structure, such as metrical position within a bar. For example, a song in 4/4 time has state transitions of the form
1->{1, 2}, 2->{2, 3}, 3->{3, 4}, 4->{4, 1}.
- Parameters
- n_statesint > 1
The number of states
- probfloat in [0, 1] or iterable, length=n_states
If a scalar, this is the probability of a self-transition.
If a vector of length
n_states
,p[i]
is the probability of self-transition in statei
- Returns
- transitionnp.ndarray [shape=(n_states, n_states)]
The transition matrix
Examples
>>> librosa.sequence.transition_cycle(4, 0.9) array([[0.9, 0.1, 0. , 0. ], [0. , 0.9, 0.1, 0. ], [0. , 0. , 0.9, 0.1], [0.1, 0. , 0. , 0.9]])