Caution

You're reading an old version of this documentation. If you want up-to-date information, please have a look at 0.10.2.

librosa.sequence.transition_local

librosa.sequence.transition_local(n_states, width, window='triangle', wrap=False)[source]

Construct a localized transition matrix.

The transition matrix will have the following properties:

  • transition[i, j] = 0 if |i - j| > width

  • transition[i, i] is maximal

  • transition[i, i - width//2 : i + width//2] has shape window

This type of transition matrix is appropriate for state spaces that discretely approximate continuous variables, such as in fundamental frequency estimation.

Parameters:
n_statesint > 1

The number of states

widthint >= 1 or iterable

The maximum number of states to treat as “local”. If iterable, it should have length equal to n_states, and specify the width independently for each state.

windowstr, callable, or window specification

The window function to determine the shape of the “local” distribution.

Any window specification supported by filters.get_window will work here.

Note

Certain windows (e.g., ‘hann’) are identically 0 at the boundaries, so and effectively have width-2 non-zero values. You may have to expand width to get the desired behavior.

wrapbool

If True, then state locality |i - j| is computed modulo n_states. If False (default), then locality is absolute.

Returns:
transitionnp.ndarray [shape=(n_states, n_states)]

The transition matrix

Examples

Triangular distributions with and without wrapping

>>> librosa.sequence.transition_local(5, 3, window='triangle', wrap=False)
array([[0.667, 0.333, 0.   , 0.   , 0.   ],
       [0.25 , 0.5  , 0.25 , 0.   , 0.   ],
       [0.   , 0.25 , 0.5  , 0.25 , 0.   ],
       [0.   , 0.   , 0.25 , 0.5  , 0.25 ],
       [0.   , 0.   , 0.   , 0.333, 0.667]])
>>> librosa.sequence.transition_local(5, 3, window='triangle', wrap=True)
array([[0.5 , 0.25, 0.  , 0.  , 0.25],
       [0.25, 0.5 , 0.25, 0.  , 0.  ],
       [0.  , 0.25, 0.5 , 0.25, 0.  ],
       [0.  , 0.  , 0.25, 0.5 , 0.25],
       [0.25, 0.  , 0.  , 0.25, 0.5 ]])

Uniform local distributions with variable widths and no wrapping

>>> librosa.sequence.transition_local(5, [1, 2, 3, 3, 1], window='ones', wrap=False)
array([[1.   , 0.   , 0.   , 0.   , 0.   ],
       [0.5  , 0.5  , 0.   , 0.   , 0.   ],
       [0.   , 0.333, 0.333, 0.333, 0.   ],
       [0.   , 0.   , 0.333, 0.333, 0.333],
       [0.   , 0.   , 0.   , 0.   , 1.   ]])