math / data /lean /OAI /Probability /LogConcave /Numerics /BaseVariation.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
5.63 kB
import Mathlib
import OAI.Probability.LogConcave.Numerics.CompileDeclaredRootShift
namespace OAI
section
noncomputable section
namespace LogConcaveSampling.MeanTree
open MeasureTheory OracleCompiler OracleCompiler.Expression
open scoped Classical BigOperators
variable {X : Type*} [MeasurableSpace X] {d : β„•}
def BaseVariation (B : ℝ) (x y : X) : MeanTree X d β†’ Prop
| .node _ b _ _ _ C => β€–b x-b yβ€– ≀ B ∧ βˆ€i,BaseVariation B x y (C i)
lemma compileTerms_variation (D : ℝ) (V : Point d β†’ ℝ) (k : β„•) (a : Fin k β†’ ℝ)
(C : Fin k β†’ Expression X d) (M : Fin k β†’ SeedProgram d) (E : Expression X d)
(B : Fin k β†’ ℝ) (L H : ℝ) (hL : 0≀L) (x y : X)
(hc : βˆ€i g,β€–(C i).eval V x g-(C i).eval V y gβ€– ≀ B i)
(hm : βˆ€i u v g,β€–(M i).program.run V (u,g)-(M i).program.run V (v,g)β€– ≀ L*β€–u-vβ€–)
(he : βˆ€g,β€–E.eval V x g-E.eval V y gβ€– ≀ H) :
βˆ€g,β€–(compileTerms D k a C M E).eval V x g-(compileTerms D k a C M E).eval V y gβ€– ≀
(βˆ‘i,|a i| *(L*B i))+H := by
induction k with
| zero => simpa [compileTerms] using he
| succ k ih =>
intro g
have ht := ih (fun i => a i.succ) (fun i => C i.succ) (fun i => M i.succ)
(fun i => B i.succ) (fun i => hc i.succ) (fun i => hm i.succ) (rightBlock g)
have hhead := (hm 0 _ _ ((M 0).damping D (middleBlock g))).trans
(mul_le_mul_of_nonneg_left (hc 0 (leftBlock g)) hL)
change β€–a 0 β€’ _+_-(a 0 β€’ _+_)β€– ≀ _
rw [show βˆ€u v w z : Point d,u+v-(w+z)=(u-w)+(v-z) by intros; abel]
apply (norm_add_le _ _).trans
rw [←smul_sub,norm_smul,Real.norm_eq_abs,Fin.sum_univ_succ]
have hh := mul_le_mul_of_nonneg_left hhead (abs_nonneg (a 0))
linarith
theorem compileDeclared_variation {D A L B : ℝ} (hL : 0≀L) (hB : 0≀B)
(hLA : L*A ≀ 1) (V : Point d β†’ ℝ) (P : ℝ β†’ ℝ β†’ Prop) (M : ℝ β†’ ℝ β†’ SeedProgram d)
(hm : βˆ€r Ο„,P r Ο„ β†’ βˆ€u v g,β€–(M r Ο„).program.run V (u,g)-(M r Ο„).program.run V (v,g)β€– ≀ L*β€–u-vβ€–)
(E : MeanTree X d) (n : ℝ) (x y : X) (hE : BaseVariation B x y E)
(hw : weight E ≀ A) (hcenters : centersBound A E) (hr : ShiftReady D A P E n) :
βˆ€g,β€–(compileDeclared D A M E n).eval V x g-(compileDeclared D A M E n).eval V y gβ€– ≀
((depth E:ℝ)+1)*B := by
induction E generalizing n with | node k b hb a r C ih =>
have hc (i : Fin k) (g) := ih i (r i/(2*D)) (hE.2 i) (hcenters i).1 (hcenters i).2 (hr i).2.2 g
have hd (i : Fin k) : (depth (C i):ℝ)+1 ≀ (depth (node k b hb a r C):ℝ) := by
exact_mod_cast (Finset.le_sup (f:=fun j => depth (C j)+1) (Finset.mem_univ i))
have hct (i : Fin k) (g) : β€–(compileDeclared D A M (C i) (r i/(2*D))).eval V x g-
(compileDeclared D A M (C i) (r i/(2*D))).eval V y gβ€– ≀ (depth (node k b hb a r C):ℝ)*B :=
(hc i g).trans (mul_le_mul_of_nonneg_right (hd i) hB)
have hh := compileTerms_variation D V k a (fun i => compileDeclared D A M (C i) (r i/(2*D)))
(fun i => M (r i) (declaredNoise n A)) (.noise b hb (declaredReserve n A a))
(fun _ => (depth (node k b hb a r C):ℝ)*B) L B hL x y hct
(fun i => hm _ _ (hr i).2.1) (fun g => by simpa only [Expression.eval,add_sub_add_right_eq_sub] using hE.1)
intro g
apply (hh g).trans
rw [←Finset.sum_mul]
have hs : (βˆ‘i,|a i|)*L ≀ 1 := calc
_ ≀ A*L := mul_le_mul_of_nonneg_right hw hL
_ ≀ 1 := by simpa only [mul_comm] using hLA
have hd0 : 0 ≀ (depth (node k b hb a r C):ℝ)*B := by positivity
have hmult := mul_le_mul_of_nonneg_right hs hd0
nlinarith
theorem compileDeclaredRoot_variation {D A Af L Li B Bf : ℝ} (hL : 0≀L) (hLi : 0≀Li)
(hB : 0≀B) (hLA : Li*A ≀ 1) (V : Point d β†’ ℝ)
(P : Bool β†’ ℝ β†’ ℝ β†’ Prop) (M : Bool β†’ ℝ β†’ ℝ β†’ SeedProgram d)
(hm : βˆ€r Ο„,P true r Ο„ β†’ βˆ€u v g,β€–(M true r Ο„).program.run V (u,g)-(M true r Ο„).program.run V (v,g)β€– ≀ L*β€–u-vβ€–)
(hmi : βˆ€r Ο„,P false r Ο„ β†’ βˆ€u v g,β€–(M false r Ο„).program.run V (u,g)-(M false r Ο„).program.run V (v,g)β€– ≀ Li*β€–u-vβ€–)
(E : MeanTree X d) (n : ℝ) (x y : X)
(hE : BaseVariation B x y E) (hbase : β€–base E x-base E yβ€– ≀ Bf)
(hw : weight E ≀ Af) (hcenters : centersBound A E)
(hr : RootShiftReady D A Af (P true) (P false) E n) :
βˆ€g,β€–(compileDeclaredRoot D A Af (M true) (M false) E n).eval V x g-
(compileDeclaredRoot D A Af (M true) (M false) E n).eval V y gβ€– ≀
Af*L*(depth E:ℝ)*B+Bf := by
cases E with | node k b hb a r C =>
have hd (i : Fin k) : (depth (C i):ℝ)+1 ≀ (depth (node k b hb a r C):ℝ) := by
exact_mod_cast (Finset.le_sup (f:=fun j => depth (C j)+1) (Finset.mem_univ i))
have hc (i : Fin k) (g) := (compileDeclared_variation hLi hB hLA V (P false) (M false)
hmi (C i) (r i/(2*D)) x y (hE.2 i) (hcenters i).1 (hcenters i).2 (hr i).2.2 g).trans
(mul_le_mul_of_nonneg_right (hd i) hB)
have hh := compileTerms_variation D V k a (fun i => compileDeclared D A (M false) (C i) (r i/(2*D)))
(fun i => M true (r i) (declaredNoise n Af)) (.noise b hb (declaredReserve n Af a))
(fun _ => (depth (node k b hb a r C):ℝ)*B) L Bf hL x y hc
(fun i => hm _ _ (hr i).2.1) (fun g => by simpa only [Expression.eval,add_sub_add_right_eq_sub,base] using hbase)
intro g
apply (hh g).trans
rw [←Finset.sum_mul]
change (βˆ‘ i, |a i|) ≀ Af at hw
have hm := mul_le_mul_of_nonneg_right hw (show 0 ≀ L*((depth (node k b hb a r C):ℝ)*B) by positivity)
nlinarith
end LogConcaveSampling.MeanTree
end
end
end OAI