File size: 6,391 Bytes
4a56cd6 | 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 | import OAI.Combinatorics.ContingencyTables.Counting.CompanionEstimatorWords
import OAI.Combinatorics.ContingencyTables.Transport.FiniteMedianConfidence
namespace OAI
/-! # Logarithmic confidence amplification of the actual weight estimator -/
namespace ContingencyTables.CompanionOracleDensity
open CompanionFactorialApplication ForestAssignmentSplit GridBoundary ResidualMixture FirstSuccess
open CommonBasesFPRAS FiniteMedianConfidence
open scoped BigOperators Classical
noncomputable section
variable {I J : Type*} [Fintype I] [Fintype J]
/-- Each complete estimator uses constant confidence; the requested
failure probability changes only the number of independent medians. -/
def medianEstimatorBits (A : Instance I J) (C K j : β) (epsilon delta : β) : β :=
repetitionCount delta * estimatorWordBits A C K j (innerTolerance (epsilon/2) j) 1
def medianEstimate (A : Instance I J) (C : β) (z : View A β β)
(K : β) (hK : 1 β€ K) (hW : 100*A.d*K β€ A.W) (j : β) (epsilon delta : β)
(v : Grid (I := Fin (dimension A)) K)
(bits : Fin (medianEstimatorBits A C K j epsilon delta) β Bool) : β :=
rationalMedian (List.ofFn (fun i : Fin (repetitionCount delta) =>
wordEstimate A C z K hK hW j (epsilon/2) 1 v
(oracleWalkWordEquiv (repetitionCount delta)
(estimatorWordBits A C K j (innerTolerance (epsilon/2) j) 1) bits i)))
theorem medianEstimate_success (A : Instance I J) (C : β) (hC : 0 < C) (z : View A β β)
(hz : BalancedBox.InBox (bounds A) z) (K : β) (hK : 1 β€ K) (hW : 100*A.d*K β€ A.W)
(hB : (K:β)=binWidth A C) (j : β) (hj : j β€ rationalHeight A C)
(epsilon delta : β) (he0 : 0 < epsilon) (he1 : epsilon < 1) (hd : 0 < delta)
(hPL : PublishedInputs.FiniteBoxPrekopaLeindler (dimension A))
(hCheeger : PublishedInputs.FiniteCheeger (Grid (I := Fin (dimension A)) K))
(v : Grid (I := Fin (dimension A)) K) :
1-(delta:β) β€ uniformAverage (fun bits : Fin (medianEstimatorBits A C K j epsilon delta) β Bool =>
if (1-(epsilon:β))*h A ((j:β)*C/height A C) z β€
(medianEstimate A C z K hK hW j epsilon delta v bits:β) β§
(medianEstimate A C z K hK hW j epsilon delta v bits:β) β€
(1+(epsilon:β))*h A ((j:β)*C/height A C) z
then (1:β) else 0) := by
have heh0 : 0 < epsilon/2 := by positivity
have heh1 : epsilon/2 < 1 := by linarith
have ht : 0 < h A ((j:β)*C/height A C) z := h_positive A _ _
have heR : (0:β) < epsilon := by exact_mod_cast he0
have hbase := wordEstimate_failure A C hC z hz K hK hW hB j hj (epsilon/2) 1 heh0 heh1
(by norm_num) hPL hCheeger v
have hbad : uniformAverage (fun bits : Fin (estimatorWordBits A C K j (innerTolerance (epsilon/2) j) 1) β Bool =>
if (wordEstimate A C z K hK hW j (epsilon/2) 1 v bits:β) <
(1-(epsilon:β)/2)*h A ((j:β)*C/height A C) z β¨
(1+(epsilon:β)/2)*h A ((j:β)*C/height A C) z <
(wordEstimate A C z K hK hW j (epsilon/2) 1 v bits:β)
then (1:β) else 0) β€ 5/16 := by
have hh : (1:β)/4 β€ 5/16 := by norm_num
apply le_trans ?_ hh
simpa only [Rat.cast_div,Rat.cast_ofNat,Rat.cast_one] using hbase
have hm := median_confidence_real
(wordEstimate A C z K hK hW j (epsilon/2) 1 v)
((1-(epsilon:β))*h A ((j:β)*C/height A C) z)
((1-(epsilon:β)/2)*h A ((j:β)*C/height A C) z)
((1+(epsilon:β)/2)*h A ((j:β)*C/height A C) z)
((1+(epsilon:β))*h A ((j:β)*C/height A C) z)
(by nlinarith) (by nlinarith) delta hd hbad
let test := fun xs : Fin (repetitionCount delta) β
(Fin (estimatorWordBits A C K j (innerTolerance (epsilon/2) j) 1) β Bool) =>
if (1-(epsilon:β))*h A ((j:β)*C/height A C) z β€
(rationalMedian (List.ofFn (fun i => wordEstimate A C z K hK hW j (epsilon/2) 1 v (xs i))):β) β§
(rationalMedian (List.ofFn (fun i => wordEstimate A C z K hK hW j (epsilon/2) 1 v (xs i))):β) β€
(1+(epsilon:β))*h A ((j:β)*C/height A C) z
then (1:β) else 0
have he := uniformAverage_equiv
(oracleWalkWordEquiv (repetitionCount delta)
(estimatorWordBits A C K j (innerTolerance (epsilon/2) j) 1)) test
change 1-(delta:β) β€ uniformAverage (fun bits => test
(oracleWalkWordEquiv (repetitionCount delta)
(estimatorWordBits A C K j (innerTolerance (epsilon/2) j) 1) bits))
exact hm.trans_eq he.symm
/-- Amplification also preserves the proved range on every word,
including statistically unsuccessful words. -/
theorem medianEstimate_range (A : Instance I J) (C : β) (hC : 0 < C) (z : View A β β)
(hz : BalancedBox.InBox (bounds A) z) (K : β) (hK : 1 β€ K) (hW : 100*A.d*K β€ A.W)
(hB : (K:β)=binWidth A C) (j : β) (hj : j β€ rationalHeight A C)
(epsilon delta : β) (he0 : 0 < epsilon) (he1 : epsilon < 1)
(v : Grid (I := Fin (dimension A)) K)
(bits : Fin (medianEstimatorBits A C K j epsilon delta) β Bool) :
(assignmentCount A:β)*(1/2:β)^j/16 β€
(medianEstimate A C z K hK hW j epsilon delta v bits:β) β§
(medianEstimate A C z K hK hW j epsilon delta v bits:β) β€ 8*assignmentCount A := by
let samples := List.ofFn (fun i : Fin (repetitionCount delta) =>
wordEstimate A C z K hK hW j (epsilon/2) 1 v
(oracleWalkWordEquiv (repetitionCount delta)
(estimatorWordBits A C K j (innerTolerance (epsilon/2) j) 1) bits i))
have hmem := rationalMedian_mem samples (by
dsimp only [samples]
rw [List.length_ofFn]
exact repetitionCount_pos delta)
obtain β¨i,hiβ© := List.mem_ofFn.mp hmem
have hr := wordEstimate_range A C hC z hz K hK hW hB j hj (epsilon/2) 1
(by positivity) (by linarith) (by norm_num) v
(oracleWalkWordEquiv (repetitionCount delta)
(estimatorWordBits A C K j (innerTolerance (epsilon/2) j) 1) bits i)
change _ β€ (rationalMedian samples:β) β§ (rationalMedian samples:β) β€ _
rw [βhi]
exact hr
/-- The exact bit budget grows linearly with the binary confidence
parameter, rather than with its reciprocal. -/
lemma medianEstimatorBits_eq (A : Instance I J) (C K j : β) (epsilon delta : β) :
medianEstimatorBits A C K j epsilon delta =
64*(delta.den.bits.length+1) *
estimatorWordBits A C K j (innerTolerance (epsilon/2) j) 1 := rfl
end
end ContingencyTables.CompanionOracleDensity
end OAI
|