Skip to content

Built-in discretizers

Select these methods with lzs.discretize(data, method="...") or the discretization argument of an analysis function. Method options are passed directly to discretize, or through discretization_kwargs in array calls.

Mean (mean)

Binarize a sequence using its own mean.

Parameters:

  • data (array_like) –

    Nonempty, finite, real numeric 1D sequence. Strings, objects, complex values, and nonfinite observations are rejected.

Returns:

  • labels ( numpy.ndarray of uint8 ) –

    Array of the same length, with 1 strictly above the threshold and 0 at or below it. Constant signals produce only zeros.

Raises:

  • TypeError –

    If the input dtype or parameter type is unsupported.

  • ValueError –

    If the input is empty, nonfinite, not 1D, or a setting is invalid.

Notes

Available publicly through discretize(data, method="mean"). The threshold is fitted independently for each sequence in array calls.

Examples:

>>> import lzsuite as lzs
>>> lzs.discretize([0., 1., 2.], method="mean").tolist()
[0, 0, 1]

Median (median)

Binarize a sequence using its own median.

Parameters:

  • data (array_like) –

    Nonempty, finite, real numeric 1D sequence. Strings, objects, complex values, and nonfinite observations are rejected.

Returns:

  • labels ( numpy.ndarray of uint8 ) –

    Array of the same length, with 1 strictly above the threshold and 0 at or below it. Constant signals produce only zeros.

Raises:

  • TypeError –

    If the input dtype or parameter type is unsupported.

  • ValueError –

    If the input is empty, nonfinite, not 1D, or a setting is invalid.

Notes

Available publicly through discretize(data, method="median"). The threshold is fitted independently for each sequence in array calls.

Examples:

>>> import lzsuite as lzs
>>> lzs.discretize([0., 1., 2.], method="median").tolist()
[0, 0, 1]

Equal-width bins (bins)

Discretize observations with equally spaced edges over the sequence's range.

Parameters:

  • data (array_like) –

    Nonempty, finite, real numeric 1D sequence. Strings, objects, complex values, and nonfinite observations are rejected.

  • n_bins (int, default: 2 ) –

    Requested number of bins; must be a positive integer.

Returns:

  • labels ( numpy.ndarray of integers ) –

    One label per observation. Values exactly on internal edges enter the higher bin. Constant sequences produce only zeros.

Raises:

  • TypeError –

    If the input dtype or parameter type is unsupported.

  • ValueError –

    If the input is empty, nonfinite, not 1D, or a setting is invalid.

Notes

Available through discretize(data, method="bins"). Edges are fitted separately to each sequence; use a custom callable for fixed edges.

Examples:

>>> import lzsuite as lzs
>>> lzs.discretize([0., 1., 2., 3., 4.], method="bins", n_bins=2).tolist()
[0, 0, 1, 1, 1]

Quantile bins (quantile)

Discretize observations with empirical quantile edges.

Parameters:

  • data (array_like) –

    Nonempty, finite, real numeric 1D sequence. Strings, objects, complex values, and nonfinite observations are rejected.

  • n_bins (int, default: 2 ) –

    Requested number of bins; must be a positive integer.

Returns:

  • labels ( numpy.ndarray of integers ) –

    One label per observation. Values exactly on internal edges enter the higher bin. Constant sequences produce only zeros.

Raises:

  • TypeError –

    If the input dtype or parameter type is unsupported.

  • ValueError –

    If the input is empty, nonfinite, not 1D, or a setting is invalid.

Notes

Repeated quantile edges collapse, so requested bin counts and occupied bin counts can differ. Quantiles use NumPy's default linear interpolation. Available through discretize(data, method="quantile"). Edges are fitted separately to each sequence; use a custom callable for fixed edges.

Examples:

>>> import lzsuite as lzs
>>> lzs.discretize([0., 1., 2., 3., 4.], method="quantile", n_bins=2).tolist()
[0, 0, 1, 1, 1]

Ordinal patterns (permutation)

Encode delayed ordinal windows as lexicographic permutation ranks.

Parameters:

  • data (array_like) –

    Nonempty, finite, real numeric 1D sequence. Strings, objects, complex values, and nonfinite observations are rejected.

  • order (int, default: 3 ) –

    Number of observations per ordinal pattern, between 1 and 20. The upper bound ensures permutation ranks fit signed 64-bit integers.

  • delay (int, default: 1 ) –

    Positive spacing between observations within each window.

Returns:

  • labels ( numpy.ndarray of int64 ) –

    Lexicographic ranks, of length len(data) - (order - 1) * delay. Successive windows advance by one original observation.

Raises:

  • TypeError –

    If the input dtype or parameter type is unsupported.

  • ValueError –

    If the input is empty, nonfinite, not 1D, or a setting is invalid.

Notes

Equal values are ordered by their positions in the window, earlier first. This method creates a symbolic sequence; it does not compute permutation entropy. A window must fit within the supplied sequence. The backend's byte-alphabet warning is applied during analysis, not here: for example order 6 admits 720 possible patterns.

Examples:

>>> import lzsuite as lzs
>>> lzs.discretize([3., 1., 2., 4., 0.], "permutation", order=3).tolist()
[3, 0, 4]