Skip to content

Effective measure complexity

lzsuite.emc

emc(
    data,
    *,
    axis=0,
    discretization=None,
    discretization_kwargs=None,
    n_jobs=4,
    log_base=None,
    max_block_size=-1,
    method="chao-shen",
)

Estimate effective measure complexity E and its scale increments.

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.

  • max_block_size (int, default: -1 ) –

    Maximum byte-window range for E. Nonpositive values select the backend's automatic range; a positive value keeps that full range.

  • method (('chao-shen', 'shuffle'), default: 'chao-shen' ) –

    E estimator. This option is independent of discretization.

Returns:

  • scores ( float or ndarray ) –

    Python float for 1D input; otherwise a float array with axis removed. E is the final level of the fitted scale profile.

  • profiles ( list of float or numpy.ndarray ) –

    For 1D input, a list of nonnegative increments summing to E. Otherwise an object array of lists with the same shape as scores. Profile lengths can differ when the range is selected automatically.

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

Chao-Shen estimates block entropy from overlapping windows, subtracts l times the LZ76 rate estimate, then fits a nonnegative, nondecreasing profile. Automatic range selection uses the observed alphabet and stops at the earliest raw-profile maximum. A positive cap includes the whole requested range. Shuffle uses deterministic block-swapped surrogates and a different raw-profile formula. The estimators are not interchangeable. Keep encoding, length, base, method, and range consistent across comparisons.

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

h : LZ76 entropy-rate estimate. lz76 : Includes the actual range and E-method metadata.

Examples:

>>> import lzsuite as lzs
>>> periodic = [0, 0, 0, 1, 0, 1, 1, 1] * 256
>>> score, increments = lzs.emc(periodic, max_block_size=6)
>>> score >= 0 and abs(sum(increments) - score) < 1e-12
True