Entropy and adjacency mass
Lax263307.Entropy · concepts/Lax263307/Entropy.lean · lax-263307
No public endorsements yet.
Loading review…
Sign in with ORCIDNatural Language Statement
Definition
For a probability vector on vertices, its entropy in bits is
with zero summands at zero probabilities. Its adjacency mass in a graph is
where ordered adjacent pairs are counted, so each edge contributes twice.
Concept map
Lean source view on GitHub
| 1 | import Mathlib.Analysis.SpecialFunctions.Log.NegMulLog |
| 2 | import Mathlib.Analysis.SpecialFunctions.Log.Base |
| 3 | import Mathlib.Combinatorics.SimpleGraph.Basic |
| 4 | |
| 5 | /-! |
| 6 | --- |
| 7 | title: Entropy and adjacency mass |
| 8 | type: definition |
| 9 | --- |
| 10 | For a probability vector on vertices, its entropy in bits is |
| 11 | |
| 12 | with zero summands at zero probabilities. Its adjacency mass in a graph is |
| 13 | |
| 14 | where ordered adjacent pairs are counted, so each edge contributes twice. |
| 15 | |
| 16 | # Formalization notes |
| 17 | |
| 18 | The auxiliary natural-log entropy differs by the positive factor . |
| 19 | Both definitions use mathlib's `negMulLog`, whose value at zero is zero. |
| 20 | The adjacency mass is an ordered sum, avoiding choices of edge orientations. |
| 21 | -/ |
| 22 | |
| 23 | namespace Lax263307.Entropy |
| 24 | |
| 25 | /-- A nonnegative vector with total mass one. -/ |
| 26 | def IsProbability {n : ℕ} (π : Fin n → ℝ) : Prop := |
| 27 | (∀ v, 0 ≤ π v) ∧ (∑ v, π v) = 1 |
| 28 | |
| 29 | /-- Entropy measured with natural logarithms. -/ |
| 30 | noncomputable def naturalEntropy {n : ℕ} (π : Fin n → ℝ) : ℝ := |
| 31 | ∑ v, Real.negMulLog (π v) |
| 32 | |
| 33 | /-- Shannon entropy in bits. -/ |
| 34 | noncomputable def entropy {n : ℕ} (π : Fin n → ℝ) : ℝ := |
| 35 | naturalEntropy π / Real.log 2 |
| 36 | |
| 37 | /-- Total product probability of ordered adjacent vertex pairs. -/ |
| 38 | noncomputable def adjacencyMass {n : ℕ} (G : SimpleGraph (Fin n)) |
| 39 | [DecidableRel G.Adj] (π : Fin n → ℝ) : ℝ := |
| 40 | ∑ u, ∑ v, if G.Adj u v then π u * π v else 0 |
| 41 | |
| 42 | /-- Sum of endpoint-cost products over unordered edges. -/ |
| 43 | noncomputable def edgeCost {n : ℕ} (G : SimpleGraph (Fin n)) |
| 44 | [DecidableRel G.Adj] (x : Fin n → ℝ) : ℝ := |
| 45 | adjacencyMass G x / 2 |
| 46 | |
| 47 | end Lax263307.Entropy |
| 48 |
Formalization notes
The auxiliary natural-log entropy differs by the positive factor . Both definitions use mathlib's , whose value at zero is zero. The adjacency mass is an ordered sum, avoiding choices of edge orientations.
Discussion
Ask a question or add context. Endorsements and structured flags are kept in the review panel above.
0 comments