ptwm
ptwm.entropy
Shannon entropy utilities for compressed-tensor analysis.
ptwm.entropy
Shannon entropy utilities for compressed-tensor analysis.
ptwm.entropy
python/ptwm/entropy/__init__.py:1module ptwm.entropyShannon entropy utilities for compressed-tensor analysis.
These functions produce "before entropy coder" measurements on plane bytes.
They are deliberately codec-agnostic: :func:`shannon` runs on arbitrary byte
buffers, and :func:`per_plane` folds over a list of
:class:`~ptwm.preprocessing.Plane` objects.
ptwm.entropy.histogram
python/ptwm/entropy/__init__.py:32def histogram(data: bytes | memoryview) -> np.ndarray256-bin byte-frequency histogram as a ``uint32`` NumPy array.
ptwm.entropy.joint_histogram
python/ptwm/entropy/__init__.py:38def joint_histogram(a: bytes | memoryview | np.ndarray, b: bytes | memoryview | np.ndarray) -> np.ndarrayReturn the 256x256 joint byte-frequency histogram of paired byte streams.
The result has shape ``(256, 256)`` and dtype ``uint64``; ``out[i, j]``
counts positions where ``a`` has value ``i`` and ``b`` has value ``j``.
Requires ``len(a) == len(b)``.
ptwm.entropy.mutual_information
python/ptwm/entropy/__init__.py:68def mutual_information(joint: np.ndarray) -> floatMutual information ``I(A; B)`` in bits/byte from a joint histogram.
``joint`` must be the ``(256, 256)`` output of :func:`joint_histogram`.
Computes ``H(A) + H(B) - H(A, B)`` from the marginals and the joint.
Returns exactly ``0.0`` for empty input.
ptwm.entropy.per_plane
python/ptwm/entropy/__init__.py:27def per_plane(planes: Sequence[Plane]) -> list[float]Shannon entropy per plane, in the order given.
ptwm.entropy.shannon
python/ptwm/entropy/__init__.py:22def shannon(data: bytes | memoryview) -> floatBase-2 Shannon entropy of ``data`` in bits/byte. Empty input yields 0.0.