Skip to content

Discretization API

Use registered names or callables without importing implementation modules. Built-in rules are described separately.

lzsuite.discretize

discretize(data, method='mean', **kwargs)

Apply a registered or callable discretizer to one numeric sequence.

Parameters:

  • data (array_like) –

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

  • method (str or callable, default: 'mean' ) –

    Registered label or function. Built-ins are mean, median, bins, quantile, and permutation. A custom callable receives a copy of the numeric input and may change the output length.

  • **kwargs (dict, default: {} ) –

    Keyword arguments forwarded to the selected method, such as n_bins, order, delay, or a custom threshold.

Returns:

  • labels ( numpy.ndarray of integers ) –

    Nonempty 1D integer or boolean labels. Original observations are not mutated by the method; its input is copied before invocation.

Raises:

  • TypeError –

    If input is not real numeric data, method is not a name/callable, or the method returns noninteger or multidimensional output.

  • ValueError –

    If input is empty, nonfinite, or not 1D, the method name is unknown, or its output is empty. Method-specific validation also applies.

Notes

There is no 256-category restriction at this stage. Analysis functions warn and merge categories if the prepared alphabet exceeds 256 symbols. Numeric labels do not need to be contiguous or start at zero.

See Also

available_discretizers : List registered labels. register_discretizer : Add a reusable custom method. h : Apply a method independently across an array.

Examples:

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

lzsuite.available_discretizers

available_discretizers()

List the registered discretization names in sorted order.

Returns:

  • names ( tuple of str ) –

    Built-in and user-registered labels available in this Python process.

See Also

register_discretizer : Add or replace a named method. discretize : Run a method on a 1D signal.

Examples:

>>> import lzsuite as lzs
>>> "mean" in lzs.available_discretizers()
True

lzsuite.register_discretizer

register_discretizer(name, function=None, *, replace=False)

Register a named discretizer directly or as a decorator.

Parameters:

  • name (str) –

    Nonempty registry label, used as discretization=name in analysis calls or method=name in discretize.

  • function (callable, default: None ) –

    Numeric 1D-to-integer-1D function. Omit to obtain a decorator. Its output may differ in length from its input.

  • replace (bool, default: False ) –

    Allow replacing an existing label, including a built-in method.

Returns:

  • registered ( callable ) –

    The supplied function unchanged, or a decorator if no function was supplied. Registration lasts for the current Python process only.

Raises:

  • TypeError –

    If the supplied function is not callable.

  • ValueError –

    If the name is empty or already exists without replace=True.

Notes

The callable's input/output contract is checked when it is used. Array preparation invokes it in the parent process before parallel native calculations, so locally defined functions work in IPython.

See Also

discretize : Invoke a registered name or a callable. available_discretizers : Inspect current names.

Examples:

>>> import lzsuite as lzs
>>> @lzs.register_discretizer("positive", replace=True)
... def positive(values):
...     return (values > 0).astype(int)
>>> lzs.discretize([-1., 0., 2.], "positive").tolist()
[0, 0, 1]