File size: 5,171 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 | import Mathlib
import OAI.Combinatorics.MatchingCount.Algorithm.RationalEstimator
namespace OAI
namespace MatchingFPRAS.FiniteTrial
open Finset Enlargement Transport Switching
variable {G : GraphInput} {j K S : β} [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 _
def ScaleState.Balanced (hn : 2β€G.n) (s : ScaleState G j) : Prop := s.toReal.Balanced hn
omit [Nontrivial (Fin G.n)] in
lemma initial_balanced (hn : 2β€G.n) (he : Even G.n) : (initialScaleState G hn).Balanced hn :=
Trial.initial_balanced G hn he
noncomputable def stageData (p : Trial.Parameters G) (hj : jβ€p.K) (s : ScaleState G j)
(hs : s.Balanced p.hn) : StageData G.n p.K p.K where
hn:=p.hn
w a b:=(s.activity a b:β)
next a b:=(s.nextActivity a b:β)
positive a b:=by exact_mod_cast s.activity_pos a b
next_positive a b:=by exact_mod_cast s.nextActivity_pos a b
partition_positive:=by rw [s.activity_cast]; exact s.toReal.partition_pos p.even
lower:=by rw [s.activity_cast]; exact hs.1
upper:=by rw [s.activity_cast]; exact hs.2
cool_lower a b _:=by
have h:=(s.toReal.cooling a b).1
rw [βs.activity_cast,βs.nextActivity_cast] at h
exact h
cool_upper a b _:=by
have h:=(s.toReal.cooling a b).2
rw [βs.activity_cast,βs.nextActivity_cast] at h
exact h
cap:=by rw [s.activity_cast]; exact s.toReal.cap hj
stages:=p.K_pos
epsilon:=p.epsilon
epsilon_positive:=p.epsilon_real_pos
epsilon_lt_one:=p.epsilon_real_lt_one
theorem successful_update (p : Trial.Parameters G) (hj : jβ€p.K) (s : ScaleState G j)
(hs : s.Balanced p.hn) (x : Fin S β SourceMarked (fun a b=>(s.activity a b:β)) p.K)
(hx : StageGood (fun a b=>(s.activity a b:β)) (fun a b=>(s.nextActivity a b:β)) p.K p.sigma x) :
(s.update p.hn (RationalSource.sourceMarkedEquiv s.activity p.K β x)).Balanced p.hn β§
|(s.ratioEstimate (RationalSource.sourceMarkedEquiv s.activity p.K β x):β)/
(partition (Trial.raw G (j+1)) β
/partition (Trial.raw G j) β
)-1|β€(p.epsilon:β)/(100*p.K) := by
let c:=stageData p hj s hs
let obs : EmpiricalData c:=empiricalData c x hx
have hh:=actual_successful_stage c obs
dsimp only at hh
let y:=RationalSource.sourceMarkedEquiv s.activity p.K β x
have hm : (fun a b=>(s.matrix y a b:β))=Enlargement.estimateMatrix (Enlargement.sourceD (V:=Fin G.n) p.K) obs.dbar obs.zbar := by
rw [s.matrix_cast,sourceD_eq]
rfl
have hv : (fun i=>(s.updateVector p.hn y i:β))=
RealStage.scalingTrace c.hn (Enlargement.estimateMatrix (Enlargement.sourceD (V:=Fin G.n) p.K) obs.dbar obs.zbar) G.n := by
funext i
rw [ScaleState.updateVector,Counting.scalingTrace_cast,hm]
constructor
Β· unfold ScaleState.Balanced Trial.ScaleState.Balanced
rw [βScaleState.activity_cast,ScaleState.update_activity]
have ha : (fun a b=>((s.nextActivity a b*s.updateVector p.hn y a*s.updateVector p.hn y b:β):β))=
(fun a b=>c.next a b*(RealStage.scalingTrace c.hn (Enlargement.estimateMatrix
(Enlargement.sourceD (V:=Fin G.n) p.K) obs.dbar obs.zbar) G.n a)*
(RealStage.scalingTrace c.hn (Enlargement.estimateMatrix
(Enlargement.sourceD (V:=Fin G.n) p.K) obs.dbar obs.zbar) G.n b)) := by
funext a z
simp only [Rat.cast_mul,congrFun hv]
rfl
rw [ha]
exact β¨fun i=>(hh.2.1 i).1,fun i=>(hh.2.1 i).2β©
Β· rw [s.ratioEstimate_cast]
have hr : partition c.next β
/partition c.w β
=
partition (Trial.raw G (j+1)) β
/partition (Trial.raw G j) β
:= by
change partition (fun a b=>(s.nextActivity a b:β)) β
/partition (fun a b=>(s.activity a b:β)) β
=_
rw [s.nextActivity_cast,s.activity_cast,s.toReal.ratio]
rw [βhr]
exact hh.2.2
lemma ScaleState.ratioEstimate_nonneg (s : ScaleState G j)
(x : Fin S β SourceMarked (fun a b=>(s.activity a b:β)) K) :
0 β€ s.ratioEstimate (RationalSource.sourceMarkedEquiv s.activity K β x) := by
have h : (0:β)β€(s.ratioEstimate (RationalSource.sourceMarkedEquiv s.activity K β x):β) := by
rw [s.ratioEstimate_cast]
unfold RealStage.ratioEstimate
split_ifs with h
Β· apply div_nonneg _ h.le
unfold Enlargement.sampleAverage
apply div_nonneg _ (Nat.cast_nonneg S)
apply sum_nonneg
intro i _
exact (observableD_range_off (fun a b=>(s.activity a b:β)) (fun a b=>(s.nextActivity a b:β))
(fun a b=>by exact_mod_cast s.activity_pos a b)
(fun a b=>by exact_mod_cast (s.nextActivity_pos a b).le)
(fun a b _=>by have h:=(s.toReal.cooling a b).2; rw [βs.activity_cast,βs.nextActivity_cast] at h; exact h) K (x i)).1
Β· norm_num
exact_mod_cast h
end MatchingFPRAS.FiniteTrial
end OAI
|