Hub.lean
Lean 4 source, lean/DataMiningAsObservation/Hub.lean at commit bccca4f. Appendix C, Machine-checked statements, says what each file proves. All Lean files.
/-
Hub.lean. Equations 10.3 and 0.17, hubs.
A hub is a row retrieved as a nearest neighbour far more often than chance allows, a count
above the Poisson ceiling. Since the counts over a corpus sum to the slots handed out, the
number of rows with count above `c` is at most the slots over `c + 1`, so hubs are few by
arithmetic and not by luck. Whether a row is a hub depends on the queries and the retrieval
rule alone, which is the sense in which hubness is a query property.
-/
import Mathlib
import DataMiningAsObservation.Hubness
namespace DMO.Hub
open Finset DMO.Hubness
variable {ι α : Type*} [DecidableEq α]
/-- The hubs of a corpus under the queries `Q`, the rows whose count exceeds the ceiling `c`. -/
def hubs (Q : Finset ι) (top : ι → Finset α) (X : Finset α) (c : ℕ) : Finset α :=
X.filter fun x => c < count Q top x
/-- **Hubs are few by arithmetic.** With `k` slots per query, at most `k |Q| / (c + 1)` rows
can have count above `c`. -/
theorem card_hubs_le (Q : Finset ι) (top : ι → Finset α) (X : Finset α) (k : ℕ)
(hk : ∀ q ∈ Q, (top q).card = k) (hX : ∀ q ∈ Q, top q ⊆ X) (c : ℕ) :
(hubs Q top X c).card * (c + 1) ≤ k * Q.card := by
have htotal := sum_count_eq Q top X k hk hX
calc (hubs Q top X c).card * (c + 1)
= ∑ x ∈ hubs Q top X c, (c + 1) := by rw [Finset.sum_const, smul_eq_mul]
_ ≤ ∑ x ∈ hubs Q top X c, count Q top x := by
apply Finset.sum_le_sum
intro x hx
exact (Finset.mem_filter.1 hx).2
_ ≤ ∑ x ∈ X, count Q top x :=
Finset.sum_le_sum_of_subset_of_nonneg (Finset.filter_subset _ _) fun _ _ _ => Nat.zero_le _
_ = k * Q.card := htotal
/-- **Hubness is a query property.** Two query sets that retrieve the same lists have the
same hubs. -/
theorem hubs_congr (Q : Finset ι) (top top' : ι → Finset α) (h : ∀ q ∈ Q, top q = top' q)
(X : Finset α) (c : ℕ) : hubs Q top X c = hubs Q top' X c := by
unfold hubs
apply Finset.filter_congr
intro x _
rw [count_congr Q top top' h x]
/-- **A higher ceiling names fewer hubs.** -/
theorem hubs_anti (Q : Finset ι) (top : ι → Finset α) (X : Finset α) (c c' : ℕ) (h : c ≤ c') :
hubs Q top X c' ⊆ hubs Q top X c :=
Finset.monotone_filter_right X fun _ _ hx => lt_of_le_of_lt h hx
/-- **No queries, no hubs.** -/
theorem hubs_empty (top : ι → Finset α) (X : Finset α) (c : ℕ) : hubs (∅ : Finset ι) top X c = ∅ := by
unfold hubs count
simp
end DMO.Hub