Documentation

CslibFrontier.Foundations.Data.Finset.TopSelection

Selecting largest coordinates and rounding an approximate indicator #

List.selectLargest sorts a finite list by decreasing weight and keeps its first k entries. It is executable when its weights have a decidable linear order, including integer weights.

The rounding theorem bounds the number of missed coordinates when selecting a set of the correct cardinality by largest score. If the scores are close to a scaled indicator in squared Euclidean distance, the selected set has small symmetric difference from its support. The proof pairs each missed coordinate with an incorrectly selected coordinate.

def List.selectLargest {α : Type u_1} {β : Type u_2} [DecidableEq α] [LinearOrder β] (weight : α → β) (k : ℕ) (xs : List α) :

Sort by decreasing weight and select the first k entries, breaking ties by the order chosen by merge sort. A duplicate-free input yields min k xs.length selected elements.

theorem List.card_selectLargest {α : Type u_1} {β : Type u_2} [DecidableEq α] [LinearOrder β] (weight : α → β) (k : ℕ) {xs : List α} (hxs : xs.Nodup) :
(selectLargest weight k xs).card = min k xs.length

On a duplicate-free input, selection has the expected cardinality.

theorem List.weight_le_of_notMem_selectLargest {α : Type u_1} {β : Type u_2} [DecidableEq α] [LinearOrder β] (weight : α → β) (k : ℕ) (xs : List α) {i j : α} (hi : i ∈ xs) (hinot : i ∉ selectLargest weight k xs) (hj : j ∈ selectLargest weight k xs) :
weight i ≤ weight j

Every selected weight is at least every omitted weight from the input list.

theorem Finset.card_sdiff_mul_sq_le_sum_sq {ι : Type u_1} [Fintype ι] [DecidableEq ι] (S T : Finset ι) (x : ι → ℝ) {a : ℝ} (ha : 0 ≤ a) (hcard : S.card = T.card) (horder : ∀ i ∉ T, ∀ j ∈ T, x i ≤ x j) :
↑(S \ T).card * a ^ 2 ≤ 2 * ∑ i : ι, (x i - if i ∈ S then a else 0) ^ 2

Rounding a real score vector by its largest coordinates. If S and T have the same cardinality and the scores on T dominate those outside T, the squared error from the scaled indicator of S controls the number of missed elements. This statement also covers negative scores; the indicator height a is nonnegative.

theorem Finset.sixteen_mul_card_sdiff_le_of_sum_sq_le {ι : Type u_1} [Fintype ι] [DecidableEq ι] (S T : Finset ι) (x : ι → ℝ) {a : ℝ} {k : ℕ} (ha : 0 ≤ a) (hscale : ↑k * a ^ 2 = 1) (hcard : S.card = T.card) (horder : ∀ i ∉ T, ∀ j ∈ T, x i ≤ x j) (herror : ∑ i : ι, (x i - if i ∈ S then a else 0) ^ 2 ≤ 1 / 32) :
16 * (S \ T).card ≤ k

A squared error of at most 1 / 32 from a normalized indicator suffices for the one-sixteenth overlap bound used in clique recovery. The normalization equation separates this finite rounding argument from the construction of a unit indicator vector.