Information Entropy (cross-cutting/numerics/information-entropy)
Use when the task is the information-theoretic content of a symbol
distribution for aerospace data-channel work: the Shannon entropy in
bits per symbol of a measured count distribution or a stated
probability mass function, the binary entropy function for a
two-symbol source, the uniform-distribution entropy bound as log2 of
the symbol count, and the minimum source-coding bit rate of a symbol
stream as entropy times symbol rate. This leaf is the pure
information-measure utility of the numerics pack: deterministic,
stdlib only, no RNG. It pairs with
flight-test-operations/planning/pcm-telemetry-decommutation, where the
recovered channel symbol stream is the stream whose entropy and
minimum bit rate this leaf sizes. It does NOT fit probability models,
estimate frequency spectra, sample or estimate densities, or build
coding trees: the numerics siblings below own those operations.
Domain quick reference
- Shannon entropy: H = -sum(p_i * log2(p_i)) bits per symbol over the
normalized probabilities; a zero-probability symbol contributes
0 * log2(0) = 0. Raw counts are normalized by their total first, so
counts and probabilities give identical results.
- Binary entropy function: b(p) = -p log2(p) - (1-p) log2(1-p) for a
two-symbol source with symbol probability p. Endpoints give
b(0) = b(1) = 0 (fully deterministic source) and the peak is
b(0.5) = 1 bit. The function is symmetric, b(p) = b(1-p).
- Uniform bound: H_uniform = log2(N) for N symbols, the maximum
entropy any distribution over N symbols can reach, so
H <= log2(N) always. Redundancy against the bound is
1 - H / log2(N): 0 for a uniform source, 1 for a deterministic one.
- Minimum source-coding bit rate: R_min = H * r bits per second for a
stream of r symbols per second. Shannon source coding says the
average code length per symbol cannot go below H, so R_min is the
floor bit rate the data channel must carry and quantization must
respect.
- Units: bits per symbol for entropy, symbols per second for the
symbol rate, bits per second (bps) for the minimum bit rate.
- NACA TR-824 anchors the numerics-pack reference convention; the
relations above are standard information-theory methodology,
summary-only.
Workflow
- Assemble the symbol distribution of the data channel: raw symbol
counts from a measurement window, or the probability mass function
when it is known directly.
- Run shannon_entropy on the distribution to get entropy_bits and the
normalized probabilities; the function accepts counts or
probabilities and normalizes internally.
- For a two-symbol source (single bit per symbol, on-off channel),
run binary_entropy with the probability of one symbol instead.
- Run uniform_entropy with the symbol count to get the log2 upper
bound for the comparison.
- Size the channel floor: min_bit_rate with the per-symbol entropy
and the symbol rate in symbols per second.
- For the consolidated verdict, run entropy_summary with the
distribution and symbol rate: entropy, symbol count, uniform bound,
redundancy, and minimum bit rate in one dict.
- Confirm the deterministic checks with the contract test
scripts/test_information_entropy.py.
Worked example
A telemetry data channel carries four symbol classes with p = [0.5,
0.25, 0.125, 0.125] at 1000 symbols per second (module outputs shown).
- shannon_entropy(p) returns entropy_bits 1.75 bits per symbol and
normalized [0.5, 0.25, 0.125, 0.125]; the same call on counts
[4, 2, 1, 1] returns the same 1.75 bits.
- binary_entropy(0.9) returns 0.4689955935892811, 0.4690 bits within
the worked-example bound; binary_entropy(0.5) returns exactly 1.0.
- uniform_entropy(4) returns 2.0 bits and uniform_entropy(8) returns
3.0 bits, the log2 upper bounds.
- min_bit_rate(1.75, 1000.0) returns 1750.0 bps.
- entropy_summary(p, 1000.0) returns entropy_bits 1.75, n_symbols 4,
uniform_bound_bits 2.0, redundancy 0.125 (1 - 1.75/2), and
min_bit_rate_bps 1750.0.
- The same channel carrying a uniform 8-symbol source at 1000 symbols
per second needs min_bit_rate(3.0, 1000.0) = 3000 bps, so the
four-symbol message reduces the channel floor by 42 percent
((3000 - 1750) / 3000 = 0.4167).
- A skew distribution [0.9, 0.05, 0.03, 0.02] gives 0.6175431233120147
bits per symbol, well below the 2.0 bit bound for 4 symbols.
Pitfalls
- Feeding any negative probability or count, or a zero-sum input: the
module raises ValueError, as it does for empty input and binary p
outside [0, 1].
- Expecting entropy above log2(N): H always lies between 0 and log2(N),
so a uniform 4-symbol source gives exactly 2.0 bits and skew sources
sit below (0.6175 for [0.9, 0.05, 0.03, 0.02]) - a result above the
bound means invalid input, not a dense source.
- Misreading binary_entropy at its endpoints: b(0.0) = b(1.0) = 0.0,
b(0.5) = 1.0 exactly, and the function is symmetric, b(p) = b(1-p).
- Treating counts and probabilities as interchangeable without the
normalization rule: counts normalize identically to probabilities
([5, 5] and [0.5, 0.5] both give 1.0 bit), but every entry must be
non-negative and the sum nonzero.
- Quoting the entropy as the channel rate: the floor is min_bit_rate =
entropy times symbol rate (1750 bps at 1000 symbols/s), and the
four-symbol saving over the uniform 8-symbol source (3000 bps) only
holds at the same symbol rate.
- Calling entropy_summary on fewer than 2 symbols or with a negative
entropy or symbol rate: it raises ValueError, and redundancy is only
meaningful in [0, 1] for a valid distribution (0 uniform, 1
deterministic).
Verification
- Confirm shannon_entropy([0.5, 0.25, 0.125, 0.125]) returns entropy
1.75 bits and that H is always between 0 and log2(N): deterministic
inputs give exactly 0, the uniform input equals uniform_entropy(N).
- Confirm counts normalize identically to probabilities:
[5, 5] gives 1.0 bit, the same as [0.5, 0.5].
- Confirm binary_entropy(0.5) = 1.0, endpoints binary_entropy(0.0)
and binary_entropy(1.0) = 0.0, and the symmetry b(p) = b(1-p).
- Confirm entropy_summary redundancy is 0 for a uniform source and 1
for a fully deterministic source, and sits in [0, 1] for every valid
distribution.
- Confirm ValueError rejection: empty input, any negative
probability or count, zero-sum input, binary p outside [0, 1],
uniform n_symbols below 1, negative entropy or symbol rate in
min_bit_rate, and entropy_summary on fewer than 2 symbols.
- Confirm determinism: identical inputs give identical outputs; the
module never uses random numbers.
- Run the contract test offline: python3
scripts/test_information_entropy.py (32 tests, deterministic).
Related leaves
- cross-cutting/numerics/probability-distributions: distribution
parameter estimation and pdf/cdf work, the model step that can feed
this leaf its probability mass function (no entropy there).
- cross-cutting/numerics/descriptive-statistics: location and spread
summaries of measured symbol counts before the entropy step.
- cross-cutting/numerics/monte-carlo-sampling: seeded random draws and
empirical density estimation, not information measures.
- cross-cutting/numerics/fast-fourier-transform and
cross-cutting/numerics/power-spectral-density: frequency-domain
spectra, a different content view from per-symbol information.
- cross-cutting/numerics/hypothesis-testing: significance tests on
symbol-count tables, complementary to the entropy summary.
- flight-test-operations/planning/pcm-telemetry-decommutation: recovers
the telemetry channel symbol stream whose entropy and minimum bit
rate this leaf computes.
Behavior contract (gate 3)
Run the deterministic contract test (stdlib unittest, offline):
python3 scripts/test_information_entropy.py
The test covers the spec worked-example anchors (Shannon entropy 1.75
bits for p = [0.5, 0.25, 0.125, 0.125], binary entropy 0.4690 at
p = 0.9, minimum bit rate 1750 bps at 1000 symbols per second, the
3000 bps uniform-8 comparison and its 42 percent reduction), the
identities (uniform distribution entropy equals log2(N), deterministic
sources give 0, b(0.5) = 1, endpoint and symmetry behavior of the
binary entropy function, counts matching probabilities), the
max-entropy bound H <= log2(N), dict key contracts, determinism, and
ValueError rejection of empty, negative, zero-sum, out-of-range and
sub-scale inputs. Runs in well under a second.
Compliance
- Standards referenced, not reproduced: NACA TR-824 anchors the
numerics-pack public-domain reference convention; Shannon entropy
and the source-coding bound are standard information-theory
methodology (paraphrase-only) per standards-map.yaml.
- compliance: STANDARDS-REF, gated: false.
1---2name: information-entropy3description: Use when you must compute the information content of a symbol distribution: the Shannon entropy in bits per symbol of a measured count distribution or probability mass function, the binary entropy function of a two-symbol source, the uniform-distribution entropy bound log2 of the symbol count, and the minimum source-coding bit rate as entropy times symbol rate. Produces the entropy, the uniform bound, the redundancy verdict against it, and the minimum bit rate that gates data-channel and quantization assessments. Pure Python stdlib, deterministic. Trigger: information-entropy, shannon-entropy, binary-entropy-function, source-coding-bound, information-content, telemetry symbol distribution, source coding bit rate, symbol distribution entropy.4license: Apache-2.05---67# Information Entropy (cross-cutting/numerics/information-entropy)89Use when the task is the information-theoretic content of a symbol10distribution for aerospace data-channel work: the Shannon entropy in11bits per symbol of a measured count distribution or a stated12probability mass function, the binary entropy function for a13two-symbol source, the uniform-distribution entropy bound as log2 of14the symbol count, and the minimum source-coding bit rate of a symbol15stream as entropy times symbol rate. This leaf is the pure16information-measure utility of the numerics pack: deterministic,17stdlib only, no RNG. It pairs with18flight-test-operations/planning/pcm-telemetry-decommutation, where the19recovered channel symbol stream is the stream whose entropy and20minimum bit rate this leaf sizes. It does NOT fit probability models,21estimate frequency spectra, sample or estimate densities, or build22coding trees: the numerics siblings below own those operations.2324## Domain quick reference2526- Shannon entropy: H = -sum(p_i * log2(p_i)) bits per symbol over the27 normalized probabilities; a zero-probability symbol contributes28 0 * log2(0) = 0. Raw counts are normalized by their total first, so29 counts and probabilities give identical results.30- Binary entropy function: b(p) = -p log2(p) - (1-p) log2(1-p) for a31 two-symbol source with symbol probability p. Endpoints give32 b(0) = b(1) = 0 (fully deterministic source) and the peak is33 b(0.5) = 1 bit. The function is symmetric, b(p) = b(1-p).34- Uniform bound: H_uniform = log2(N) for N symbols, the maximum35 entropy any distribution over N symbols can reach, so36 H <= log2(N) always. Redundancy against the bound is37 1 - H / log2(N): 0 for a uniform source, 1 for a deterministic one.38- Minimum source-coding bit rate: R_min = H * r bits per second for a39 stream of r symbols per second. Shannon source coding says the40 average code length per symbol cannot go below H, so R_min is the41 floor bit rate the data channel must carry and quantization must42 respect.43- Units: bits per symbol for entropy, symbols per second for the44 symbol rate, bits per second (bps) for the minimum bit rate.45- NACA TR-824 anchors the numerics-pack reference convention; the46 relations above are standard information-theory methodology,47 summary-only.4849## Workflow50511. Assemble the symbol distribution of the data channel: raw symbol52 counts from a measurement window, or the probability mass function53 when it is known directly.542. Run shannon_entropy on the distribution to get entropy_bits and the55 normalized probabilities; the function accepts counts or56 probabilities and normalizes internally.573. For a two-symbol source (single bit per symbol, on-off channel),58 run binary_entropy with the probability of one symbol instead.594. Run uniform_entropy with the symbol count to get the log2 upper60 bound for the comparison.615. Size the channel floor: min_bit_rate with the per-symbol entropy62 and the symbol rate in symbols per second.636. For the consolidated verdict, run entropy_summary with the64 distribution and symbol rate: entropy, symbol count, uniform bound,65 redundancy, and minimum bit rate in one dict.667. Confirm the deterministic checks with the contract test67 scripts/test_information_entropy.py.6869## Worked example7071A telemetry data channel carries four symbol classes with p = [0.5,720.25, 0.125, 0.125] at 1000 symbols per second (module outputs shown).7374- shannon_entropy(p) returns entropy_bits 1.75 bits per symbol and75 normalized [0.5, 0.25, 0.125, 0.125]; the same call on counts76 [4, 2, 1, 1] returns the same 1.75 bits.77- binary_entropy(0.9) returns 0.4689955935892811, 0.4690 bits within78 the worked-example bound; binary_entropy(0.5) returns exactly 1.0.79- uniform_entropy(4) returns 2.0 bits and uniform_entropy(8) returns80 3.0 bits, the log2 upper bounds.81- min_bit_rate(1.75, 1000.0) returns 1750.0 bps.82- entropy_summary(p, 1000.0) returns entropy_bits 1.75, n_symbols 4,83 uniform_bound_bits 2.0, redundancy 0.125 (1 - 1.75/2), and84 min_bit_rate_bps 1750.0.85- The same channel carrying a uniform 8-symbol source at 1000 symbols86 per second needs min_bit_rate(3.0, 1000.0) = 3000 bps, so the87 four-symbol message reduces the channel floor by 42 percent88 ((3000 - 1750) / 3000 = 0.4167).89- A skew distribution [0.9, 0.05, 0.03, 0.02] gives 0.617543123312014790 bits per symbol, well below the 2.0 bit bound for 4 symbols.9192## Pitfalls9394- Feeding any negative probability or count, or a zero-sum input: the95 module raises ValueError, as it does for empty input and binary p96 outside [0, 1].97- Expecting entropy above log2(N): H always lies between 0 and log2(N),98 so a uniform 4-symbol source gives exactly 2.0 bits and skew sources99 sit below (0.6175 for [0.9, 0.05, 0.03, 0.02]) - a result above the100 bound means invalid input, not a dense source.101- Misreading binary_entropy at its endpoints: b(0.0) = b(1.0) = 0.0,102 b(0.5) = 1.0 exactly, and the function is symmetric, b(p) = b(1-p).103- Treating counts and probabilities as interchangeable without the104 normalization rule: counts normalize identically to probabilities105 ([5, 5] and [0.5, 0.5] both give 1.0 bit), but every entry must be106 non-negative and the sum nonzero.107- Quoting the entropy as the channel rate: the floor is min_bit_rate =108 entropy times symbol rate (1750 bps at 1000 symbols/s), and the109 four-symbol saving over the uniform 8-symbol source (3000 bps) only110 holds at the same symbol rate.111- Calling entropy_summary on fewer than 2 symbols or with a negative112 entropy or symbol rate: it raises ValueError, and redundancy is only113 meaningful in [0, 1] for a valid distribution (0 uniform, 1114 deterministic).115116## Verification117118- Confirm shannon_entropy([0.5, 0.25, 0.125, 0.125]) returns entropy119 1.75 bits and that H is always between 0 and log2(N): deterministic120 inputs give exactly 0, the uniform input equals uniform_entropy(N).121- Confirm counts normalize identically to probabilities:122 [5, 5] gives 1.0 bit, the same as [0.5, 0.5].123- Confirm binary_entropy(0.5) = 1.0, endpoints binary_entropy(0.0)124 and binary_entropy(1.0) = 0.0, and the symmetry b(p) = b(1-p).125- Confirm entropy_summary redundancy is 0 for a uniform source and 1126 for a fully deterministic source, and sits in [0, 1] for every valid127 distribution.128- Confirm ValueError rejection: empty input, any negative129 probability or count, zero-sum input, binary p outside [0, 1],130 uniform n_symbols below 1, negative entropy or symbol rate in131 min_bit_rate, and entropy_summary on fewer than 2 symbols.132- Confirm determinism: identical inputs give identical outputs; the133 module never uses random numbers.134- Run the contract test offline: python3135 scripts/test_information_entropy.py (32 tests, deterministic).136137## Related leaves138139- cross-cutting/numerics/probability-distributions: distribution140 parameter estimation and pdf/cdf work, the model step that can feed141 this leaf its probability mass function (no entropy there).142- cross-cutting/numerics/descriptive-statistics: location and spread143 summaries of measured symbol counts before the entropy step.144- cross-cutting/numerics/monte-carlo-sampling: seeded random draws and145 empirical density estimation, not information measures.146- cross-cutting/numerics/fast-fourier-transform and147 cross-cutting/numerics/power-spectral-density: frequency-domain148 spectra, a different content view from per-symbol information.149- cross-cutting/numerics/hypothesis-testing: significance tests on150 symbol-count tables, complementary to the entropy summary.151- flight-test-operations/planning/pcm-telemetry-decommutation: recovers152 the telemetry channel symbol stream whose entropy and minimum bit153 rate this leaf computes.154155## Behavior contract (gate 3)156157Run the deterministic contract test (stdlib unittest, offline):158159 python3 scripts/test_information_entropy.py160161The test covers the spec worked-example anchors (Shannon entropy 1.75162bits for p = [0.5, 0.25, 0.125, 0.125], binary entropy 0.4690 at163p = 0.9, minimum bit rate 1750 bps at 1000 symbols per second, the1643000 bps uniform-8 comparison and its 42 percent reduction), the165identities (uniform distribution entropy equals log2(N), deterministic166sources give 0, b(0.5) = 1, endpoint and symmetry behavior of the167binary entropy function, counts matching probabilities), the168max-entropy bound H <= log2(N), dict key contracts, determinism, and169ValueError rejection of empty, negative, zero-sum, out-of-range and170sub-scale inputs. Runs in well under a second.171172## Compliance173174- Standards referenced, not reproduced: NACA TR-824 anchors the175 numerics-pack public-domain reference convention; Shannon entropy176 and the source-coding bound are standard information-theory177 methodology (paraphrase-only) per standards-map.yaml.178- compliance: STANDARDS-REF, gated: false.