PTWM
ptwm

ptwm.entropy

Shannon entropy utilities for compressed-tensor analysis.

ptwm.entropy

Shannon entropy utilities for compressed-tensor analysis.

pymodule

ptwm.entropy

python/ptwm/entropy/__init__.py:1
module ptwm.entropy

Shannon 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.
pyfunction

ptwm.entropy.histogram

python/ptwm/entropy/__init__.py:32
def histogram(data: bytes | memoryview) -> np.ndarray

256-bin byte-frequency histogram as a ``uint32`` NumPy array.

pyfunction

ptwm.entropy.joint_histogram

python/ptwm/entropy/__init__.py:38
def joint_histogram(a: bytes | memoryview | np.ndarray, b: bytes | memoryview | np.ndarray) -> np.ndarray

Return 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)``.
pyfunction

ptwm.entropy.mutual_information

python/ptwm/entropy/__init__.py:68
def mutual_information(joint: np.ndarray) -> float

Mutual 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.
pyfunction

ptwm.entropy.per_plane

python/ptwm/entropy/__init__.py:27
def per_plane(planes: Sequence[Plane]) -> list[float]

Shannon entropy per plane, in the order given.

pyfunction

ptwm.entropy.shannon

python/ptwm/entropy/__init__.py:22
def shannon(data: bytes | memoryview) -> float

Base-2 Shannon entropy of ``data`` in bits/byte. Empty input yields 0.0.