File size: 6,968 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 Mathlib
import OAI.Combinatorics.MatchingCount.Algorithm.GuardProbability
namespace OAI
namespace MatchingFPRAS.FiniteTrial
open Transport Enlargement Variation Adaptive Amplification Finset
open scoped Classical
variable {G : GraphInput} [Nontrivial (Fin G.n)]
attribute [local instance] NumberedHierarchy.labelOrder sym2Order bagEdgeOrder bagEdgeFintype
attribute [local instance] UnitRefresh.Computable.allowedDec prodOrder sumOrder
noncomputable local instance (w : Fin G.n β Fin G.n β β) (K : β) :
DecidableEq (SourceLabel (fun x y=>(w x y:β)) K) := Classical.decEq _
noncomputable local instance (w : Fin G.n β Fin G.n β β) (K : β) :
Fintype (BagEdge (sourceBags (fun x y=>(w x y:β)) K)) := Fintype.ofFinite _
noncomputable local instance (w : Fin G.n β Fin G.n β β) (K : β) :
Fintype (SourceMarked (fun x y=>(w x y:β)) K) := Fintype.ofFinite _
noncomputable def guardBits (p : Trial.Parameters G) : β := 16*oneBits p
noncomputable def ScaleState.drawGuard (p : Trial.Parameters G) (s : ScaleState G p.K) :
(Fin (guardBits p) β Bool) β GuardSamples p s :=
(fun b i=>s.drawOne p le_rfl (b i)) β matrixBitsEquiv 16 (oneBits p)
lemma ScaleState.drawGuard_law (p : Trial.Parameters G) (s : ScaleState G p.K) :
imageLaw (s.drawGuard p)=(guardLaw p s).mass := by
unfold ScaleState.drawGuard
erw [imageLaw_comp_equiv,imageLaw_componentwise]
rw [ScaleState.drawOne_law]
rfl
lemma ScaleState.drawGuard_no_certificate (p : Trial.Parameters G) (s : ScaleState G p.K)
(hZ : Z G = 0) (b : Fin (guardBits p) β Bool) : Β¬guardPass p s (s.drawGuard p b) := by
dsimp only [guardBits] at b
dsimp only [guardPass, ScaleState.drawGuard, guardBits, Function.comp_apply]
simp only [s.drawOne_certificate_zero p le_rfl hZ, lt_self_iff_false, exists_const, not_false_eq_true]
noncomputable def guardedBits (p : Trial.Parameters G) : β := p.K*stageBits p+guardBits p
noncomputable def drawGuarded (p : Trial.Parameters G) :
(Fin (guardedBits p) β Bool) β GuardedTrial p :=
fun b =>
let c := pairBitsEquiv (p.K*stageBits p) (guardBits p) b
let x := drawLayer p p.K le_rfl c.1
β¨x,((layers p p.K le_rfl).state x).drawGuard p c.2β©
lemma drawGuarded_law (p : Trial.Parameters G) : imageLaw (drawGuarded p)=(guardedLaw p).mass := by
change imageLaw ((fun c : (Fin (p.K*stageBits p) β Bool) Γ (Fin (guardBits p) β Bool) =>
(β¨drawLayer p p.K le_rfl c.1,
((layers p p.K le_rfl).state (drawLayer p p.K le_rfl c.1)).drawGuard p c.2β© : GuardedTrial p)) β
pairBitsEquiv (p.K*stageBits p) (guardBits p)) = _
erw [imageLaw_comp_equiv]
change imageLaw _ = sigmaLift (layers p p.K le_rfl).law.mass (fun x=>(guardLaw p ((layers p p.K le_rfl).state x)).mass)
rw [imageLaw_sigma_pair (drawLayer p p.K le_rfl) (fun x=>((layers p p.K le_rfl).state x).drawGuard p)]
simp_rw [ScaleState.drawGuard_law]
rw [drawLayer_law]
noncomputable def guardedBitOutput (p : Trial.Parameters G) : (Fin (guardedBits p) β Bool) β β :=
guardedOutput p β drawGuarded p
lemma guardedBitOutput_nonneg (p : Trial.Parameters G) (b : Fin (guardedBits p) β Bool) :
0β€guardedBitOutput p b := guardedOutput_nonneg p _
theorem guardedBitOutput_zero (p : Trial.Parameters G) (hZ : Z G=0) (b : Fin (guardedBits p) β Bool) :
guardedBitOutput p b=0 := by
unfold guardedBitOutput drawGuarded
simp only [Function.comp_apply, guardedOutput]
exact ite_eq_right (ScaleState.drawGuard_no_certificate p _ hZ _)
noncomputable def guardedAmplifiedBits (p : Trial.Parameters G) (Ξ΄ : β) : β :=
(2*halfRepetitions Ξ΄+1)*guardedBits p
noncomputable def drawGuardedTrials (p : Trial.Parameters G) (Ξ΄ : β) :
(Fin (guardedAmplifiedBits p Ξ΄) β Bool) β Fin (2*halfRepetitions Ξ΄+1) β GuardedTrial p :=
(fun bits i=>drawGuarded p (bits i)) β matrixBitsEquiv (2*halfRepetitions Ξ΄+1) (guardedBits p)
lemma drawGuardedTrials_law (p : Trial.Parameters G) (Ξ΄ : β) :
imageLaw (drawGuardedTrials p Ξ΄)=((guardedLaw p).iid (2*halfRepetitions Ξ΄+1)).mass := by
unfold drawGuardedTrials
erw [imageLaw_comp_equiv,imageLaw_componentwise]
rw [drawGuarded_law]
rfl
noncomputable def guardedAmplifiedOutput (p : Trial.Parameters G) (Ξ΄ : β)
(x : Fin (2*halfRepetitions Ξ΄+1) β GuardedTrial p) : β := median (fun i=>guardedOutput p (x i))
noncomputable def guardedAmplifiedBitOutput (p : Trial.Parameters G) (Ξ΄ : β) :
(Fin (guardedAmplifiedBits p Ξ΄) β Bool) β β := guardedAmplifiedOutput p Ξ΄ β drawGuardedTrials p Ξ΄
lemma guardedAmplifiedBitOutput_nonneg (p : Trial.Parameters G) (Ξ΄ : β)
(b : Fin (guardedAmplifiedBits p Ξ΄) β Bool) : 0β€guardedAmplifiedBitOutput p Ξ΄ b :=
median_nonneg _ (fun _=>guardedOutput_nonneg p _)
omit [Nontrivial (Fin G.n)] in
lemma median_eq_of_constant {k : β} (x : Fin (2*k+1) β β) (a : β) (hx : β i,x i=a) : median x=a := by
unfold median sortedValue
have hp := List.mergeSort_perm (List.ofFn x) (Β· β€ Β·)
have hm : (sortedList x)[k]'(by rw [sortedList_length]; omega) β List.ofFn x :=
hp.mem_iff.mp (List.getElem_mem _)
obtain β¨i,hiβ© := List.mem_ofFn.mp hm
rw [βhi, hx]
theorem guardedAmplifiedBitOutput_zero (p : Trial.Parameters G) (hZ : Z G=0) (Ξ΄ : β)
(b : Fin (guardedAmplifiedBits p Ξ΄) β Bool) : guardedAmplifiedBitOutput p Ξ΄ b=0 := by
apply median_eq_of_constant
intro i
exact guardedBitOutput_zero p hZ _
noncomputable def guardedAccurateBits (p : Trial.Parameters G) (Ξ΄ : β) : Finset (Fin (guardedAmplifiedBits p Ξ΄) β Bool) :=
univ.filter fun b=>Accurate p (guardedAmplifiedBitOutput p Ξ΄ b)
theorem guardedAmplifiedBitOutput_success (p : Trial.Parameters G) (hZ : 0<Z G) (Ξ΄ : β) (hΞ΄ : 0<Ξ΄) :
((guardedAccurateBits p Ξ΄).card:β)/(2:β)^(guardedAmplifiedBits p Ξ΄)β₯1-Ξ΄ := by
have hf := median_delta (guardedLaw p) (guardedOutput p) ((1-p.epsilon)*(Z G:β))
((1+p.epsilon)*(Z G:β)) (guarded_trial_failure p hZ) Ξ΄ hΞ΄
have hc:=event_complement ((guardedLaw p).iid (2*halfRepetitions Ξ΄+1)).mass
(fun x=>Accurate p (guardedAmplifiedOutput p Ξ΄ x))
rw [Law.total] at hc
have hh : 1-(Ξ΄:β) β€ event ((guardedLaw p).iid (2*halfRepetitions Ξ΄+1)).mass
(fun x=>Accurate p (guardedAmplifiedOutput p Ξ΄ x)) := by
change event _ (fun x=>Β¬Accurate p (guardedAmplifiedOutput p Ξ΄ x))β€(Ξ΄:β) at hf
linarith only [hc,hf]
rw [βdrawGuardedTrials_law,event_imageLaw] at hh
have he : Fintype.card (Fin (guardedAmplifiedBits p Ξ΄) β Bool)=2^(guardedAmplifiedBits p Ξ΄) := by simp
rw [he] at hh
change 1-(Ξ΄:β) β€ ((guardedAccurateBits p Ξ΄).card:β)/(2^(guardedAmplifiedBits p Ξ΄):β) at hh
have hr : ((1-Ξ΄:β):β) β€ (((((guardedAccurateBits p Ξ΄).card:β)/(2:β)^(guardedAmplifiedBits p Ξ΄)):β):β) := by
push_cast
simpa only [Nat.cast_pow,Nat.cast_ofNat] using hh
exact Rat.cast_le.mp hr
end MatchingFPRAS.FiniteTrial
end OAI
|