Skip to content

Factor count

lzsuite.complexity

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

Count completed LZ76 phrases 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.

Returns:

  • counts ( int or ndarray ) –

    Python int for a 1D input; otherwise an integer array with axis removed. Counts follow the backend's completed-phrase convention.

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

Constant sequences have count 1. A final copied tail can appear in factor boundaries without adding to the count. Raw counts depend on sequence length and encoding; h provides entropy-rate normalization.

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

factorization : Factor count and boundary positions. h : Normalized entropy density.

Examples:

>>> import numpy as np
>>> import lzsuite as lzs
>>> lzs.complexity(np.array(list("banana")))
3
>>> lzs.complexity(np.ones((32, 2), dtype=int), n_jobs=1).tolist()
[1, 1]