Skip to content

Entropy density

lzsuite.h

h(
    data,
    *,
    axis=0,
    discretization=None,
    discretization_kwargs=None,
    n_jobs=4,
    log_base=None,
)

Estimate normalized LZ76 entropy density along an array axis.

Parameters:

  • data (array_like) –

    Real numeric, boolean, Unicode-string, or byte-string array. Each position outside axis identifies one sequence. Floats default to per-sequence mean binarization; other supported dtypes are symbols.

  • axis (int, default: 0 ) –

    Axis containing successive observations. Negative axes are accepted.

  • discretization (str or callable, default: None ) –

    Registered method name or function applied to each numeric sequence. Overrides automatic mean binarization. Strings cannot be discretized.

  • discretization_kwargs (mapping of str to object, default: None ) –

    Keyword arguments passed to the selected discretizer. Custom methods receive an input copy and may return a different sequence length.

  • n_jobs (int, default: 4 ) –

    Maximum worker processes, capped by available CPUs and calculation count. Use 1 for inline execution or -1 for all available CPUs.

  • log_base (int, default: None ) –

    Logarithm base, at least 2. Defaults to the distinct-symbol count in each prepared sequence, with a minimum of 2 for constant data.

Returns:

  • entropy ( float or ndarray ) –

    Python float for a 1D input; otherwise a float array with axis removed. Singleton batch dimensions are preserved.

Raises:

  • TypeError –

    If the dtype, discretizer output, or parameter type is unsupported.

  • ValueError –

    If the sequence axis is empty, values are nonfinite, the axis or settings are invalid, or a custom discretizer returns no labels.

Warns:

  • RuntimeWarning –

    If more than 256 categories must be reduced to the byte alphabet. Categories then merge and results no longer faithfully represent the original alphabet.

Notes

For factor count C and prepared length n, h = C * log_b(n) / n. This is a finite-sequence entropy-rate estimate, not a symbol-histogram entropy. Finite-sample estimates can exceed 1; values are not clipped. Compare matched lengths, symbolizations, and logarithm units.

Preparation and discretization run in the caller. Native calculations use reusable joblib processes, with one Rayon thread per worker. The caller's Rayon configuration is unchanged. A single calculation runs inline. Use n_jobs=1 when process overhead outweighs useful work.

See Also

complexity : Unnormalized LZ76 factor count. emc : Effective measure complexity and scale increments. lz76 : Complete analysis dictionary.

Examples:

>>> import numpy as np
>>> import lzsuite as lzs
>>> lzs.h([0, 1, 0, 1, 0, 1, 0, 1])
0.75
>>> recordings = np.tile([0, 1], (128, 1))
>>> lzs.h(recordings, n_jobs=1).shape
(2,)