File size: 6,345 Bytes
a2ee19a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | import OAI.Probability.MatroidProphet.Main
import OAI.Probability.MatroidSecretary.Selection.SafeSpecification
namespace OAI
namespace MatroidProphet
open Finset
variable {α : Type*} [Fintype α] [DecidableEq α]
/-- The stronger half-loss estimate explicitly obtained in the source proof.
The named lemma then enlarges the loss from `|D_h|/(2κ)` to `|D_h|/κ`. -/
theorem safeSampleCount_half_loss
(M : Matroid α) (hE : M.E = Set.univ)
(κ : ℕ) (hκ : 0 < κ) (D : ℕ → Set α) (G : ℕ → Finset α)
(hG : Pairwise (fun i j => Disjoint (G i) (G j)))
(q : α → ℝ) (hq0 : ∀ e, 0 ≤ q e) (hq1 : ∀ e, q e ≤ 1)
(h : ℕ) (I : Finset α) (hI : M.Indep (I : Set α)) :
(((2 : ℝ) ^ 12)⁻¹) / 4 * I.card - (D h).ncard / (2 * (κ : ℝ)) ≤
bitsExpectation q univ (fun C => bitsExpectation q univ (fun T =>
fairParityExpectation (safeSampleCount M hE κ D G h I C T))) := by
have hpre := safeCountBeforeParity_lower M hE κ hκ D G hG q hq0 hq1 h I hI
have heq : bitsExpectation q univ (fun C => bitsExpectation q univ (fun T =>
fairParityExpectation (safeSampleCount M hE κ D G h I C T))) =
bitsExpectation q univ (fun C =>
bitsExpectation q univ (safeCountBeforeParity M hE κ D G h I C)) / 2 := by
simp only [safeSampleCount_fair_parity, div_eq_mul_inv]
simp_rw [bitsExpectation_mul_right]
rw [heq]
have hloss : ((D h).ncard : ℝ) / (2 * (κ : ℝ)) =
((D h).ncard : ℝ) / (κ : ℝ) / 2 := by ring
rw [hloss]
linarith
end MatroidProphet
namespace MatroidProphet.MainAlgorithm
open Finset
variable {n : ℕ}
attribute [local instance] Classical.propDecidable
/-- The fixed-density safety estimate with the exact density-sample loss. -/
theorem listedSafeStatistic_exact_density
(M : Matroid (Fin n)) (hE : M.E = Set.univ)
(κ : ℕ) (hκ : 0 < κ) (d : MainMasks n) (s : Fin n → Option ℤ) (i : ℤ)
(Y : Set (Fin n)) (hY : Y ⊆ (trueGroup M d s i : Set (Fin n)))
(hI : M.Indep Y) (q : Fin n → ℝ)
(hq0 : ∀ e, 0 ≤ q e) (hq1 : ∀ e, q e ≤ 1) :
exitThreshold / 4 * ((d.D : Set (Fin n)) ∩ Y).ncard -
(d.D ∩ trueGroup M d s i).card / (κ : ℝ) ≤
bitsExpectation q univ (fun C => bitsExpectation q univ (fun T =>
fairParityExpectation (fun p =>
(listedSafeStatistic M hE κ (withMasks d d.D C T) s i Y
(boolParity p) : ℝ)))) := by
by_cases hi : i ∈ groups M d s
· have hsafe := safeLayerStatistic_lower M hE κ hκ (groupMask M d s d.D)
(groupGround M d s) (groupGround_disjoint M d s) q hq0 hq1
((groups M d s).idxOf i) (trueGroup M d s i : Set (Fin n))
((d.D : Set (Fin n)) ∩ Y) (Set.inter_subset_right.trans hY)
(hI.subset Set.inter_subset_right)
rw [groupMask_at_key M d s d.D _ i (groups_get?_idxOf M d s i hi),
Set.ncard_coe_finset] at hsafe
simpa only [listedSafeStatistic_guards M hE κ d s i Y,
hi, exitThreshold] using hsafe
· have hempty := unlisted_density_inter_empty M d s i hi Y hY
have hzero (C T : Finset (Fin n)) (p : Bool) :
listedSafeStatistic M hE κ (withMasks d d.D C T) s i Y
(boolParity p) = 0 := by
change (if i ∈ groups M d s then _ else 0) = 0
rw [ite_eq_right hi]
simp only [hempty, Set.ncard_empty, Nat.cast_zero, mul_zero, zero_sub,
hzero, fairParityExpectation, zero_add, zero_div, bitsExpectation_const]
exact neg_nonpos.mpr (div_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _))
/-- Restricting the comparison set to this true group does not change its
safe-label statistic. This permits the source's global independent set `Y`. -/
theorem listedSafeStatistic_inter_trueGroup
(M : Matroid (Fin n)) (hE : M.E = Set.univ) (κ : ℕ)
(d : MainMasks n) (s : Fin n → Option ℤ) (i : ℤ)
(Y : Set (Fin n)) (ε : Fin 2) :
listedSafeStatistic M hE κ d s i
(Y ∩ (trueGroup M d s i : Set (Fin n))) ε =
listedSafeStatistic M hE κ d s i Y ε := by
unfold listedSafeStatistic
split_ifs
· unfold safeLayerStatistic
apply sum_congr rfl
intro b _
congr 1
ext e
simp only [safeLayerSet, Set.mem_sdiff, Set.mem_inter_iff]
constructor
· rintro ⟨⟨⟨heD, heY, _⟩, heL⟩, heN⟩
exact ⟨⟨⟨heD, heY⟩, heL⟩, heN⟩
· rintro ⟨⟨⟨heD, heY⟩, heL⟩, heN⟩
exact ⟨⟨⟨heD, heY, heL.1⟩, heL⟩, heN⟩
· rfl
/-- Source `lem:safe`, specialized to the manuscript's literal density
threshold and thinning rate, for the global independent comparison set.
It also covers an unlisted group, whose safe count is defined to be zero. -/
theorem safe_sampled_labels
(M : Matroid (Fin n)) (hE : M.E = Set.univ)
(d : MainMasks n) (s : Fin n → Option ℤ) (i : ℤ)
(Y : Set (Fin n)) (hI : M.Indep Y) :
exitThreshold / 4 *
((d.D : Set (Fin n)) ∩ (Y ∩ (trueGroup M d s i : Set (Fin n)))).ncard -
(d.D ∩ trueGroup M d s i).card / densityThreshold ≤
bitsExpectation (fun _ => thinningRate) univ (fun C =>
bitsExpectation (fun _ => thinningRate) univ (fun T =>
fairParityExpectation (fun p =>
(listedSafeStatistic M hE (2 ^ 100) (withMasks d d.D C T) s i Y
(boolParity p) : ℝ)))) := by
have hs := listedSafeStatistic_exact_density M hE (2 ^ 100) (by positivity)
d s i (Y ∩ (trueGroup M d s i : Set (Fin n))) Set.inter_subset_right
(hI.subset Set.inter_subset_left) (fun _ => thinningRate)
(fun _ => constants_positive.2.2.1.le)
(fun _ => by norm_num [thinningRate])
have heq (C T : Finset (Fin n)) (p : Bool) :
listedSafeStatistic M hE (2 ^ 100) (withMasks d d.D C T) s i
(Y ∩ (trueGroup M d s i : Set (Fin n))) (boolParity p) =
listedSafeStatistic M hE (2 ^ 100) (withMasks d d.D C T) s i Y
(boolParity p) := by
simpa only [trueGroup_withMasks] using
listedSafeStatistic_inter_trueGroup M hE (2 ^ 100)
(withMasks d d.D C T) s i Y (boolParity p)
simpa only [Nat.cast_pow, Nat.cast_ofNat, densityThreshold, heq] using hs
/-- Proof of the independently stated complete safe-label claim. -/
theorem safe_sampled_labels_claim : SafeSampleClaim := by
intro n M hE d s i Y hI
exact safe_sampled_labels M hE d s i Y hI
end MatroidProphet.MainAlgorithm
end OAI
|