goofi v3.0.0

LempelZiv

LZ76 complexity: how much a signal repeats itself.

Explore this node in the cookbook →

LempelZiv py
data
complexity
Type name
signal:LempelZiv
Plane
signal
Tags
analysis
Language
python
Tier
in-process
Bundle
complexity
Source
node-bundles/complexity/lempel_ziv.py
Availability
available

Slots

SlotDirectionType
datainputARRAY
complexityoutputARRAY

Parameters

lz

NameTypeDefaultRangeDoc
thresholdstringmedianmedian | meanWhat each sample is called high or low against before the sequence is counted.
normalizebooltrueDivide by the complexity a random sequence of the same length would have.

Source

The current source of this node, as it stands in the goofi repository at node-bundles/complexity/lempel_ziv.py.

node-bundles/complexity/lempel_ziv.py
"""LempelZiv — LZ76 complexity, the EEG regularity measure, from antropy.

The last axis is time and it is what the measure consumes: `[C, T]` in, `[C]` out. Every axis
before it survives, because a complexity per channel is still a value per channel.
"""

import antropy
import numpy as np
import goofi


class LempelZiv(goofi.Node):
    """LZ76 complexity: how much a signal repeats itself."""

    TAGS = ["analysis"]
    INPUTS = {"data": goofi.InputSlot(goofi.DataType.ARRAY, required=True)}
    OUTPUTS = {"complexity": goofi.DataType.ARRAY}
    PARAMS = {
        "lz": {
            "threshold": goofi.StringParam(
                "median",
                ["median", "mean"],
                doc="What each sample is called high or low against before the sequence is counted.",
            ),
            "normalize": goofi.BoolParam(
                True, doc="Divide by the complexity a random sequence of the same length would have."
            ),
        }
    }

    def process(self, data):
        p = self.params.lz

        def lz(x):
            level = np.median(x) if p.threshold == "median" else np.mean(x)
            return antropy.lziv_complexity((x > level).astype(int), normalize=p.normalize)

        x = np.asarray(data.data, dtype=np.float64)
        return np.apply_along_axis(lz, -1, x).astype(np.float32), data.drop_axis(-1)

← All nodes