File size: 5,932 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 | import Mathlib
import OAI.Probability.LogConcave.Numerics.Cost
namespace OAI
section
noncomputable section
namespace LogConcaveSampling.MeanTree
open MeasureTheory OracleCompiler OracleCompiler.Expression SeedCompiler
open scoped Classical BigOperators
variable {X : Type*} [MeasurableSpace X] {d : β}
def compileDeclaredRootShift (D A Af : β) (Mf Mi : β β β β SeedProgram d) :
(E : MeanTree X d) β (n : β) β DriftData E β Fin (compileDeclaredRoot D A Af Mf Mi E n).slots β β
| .node k b hb a r C,n,p =>
compileTermsShift D k a (fun i => compileDeclared D A Mi (C i) (r i/(2*D)))
(fun i => Mf (r i) (declaredNoise n Af)) (.noise b hb (declaredReserve n Af a))
(fun i => compileDeclaredShift D A Mi (C i) (r i/(2*D)) (p.2 i))
(fun i => inverseChildShift D (r i) ((p.2 i).root (C i)) (Mf (r i) (declaredNoise n Af)))
(fun _ => 0)
def RootShiftReady (D A Af : β) (Pf Pi : β β β β Prop) : MeanTree X d β β β Prop
| .node _ _ _ _ r C,n => βi,r iβ 0 β§ Pf (r i) (declaredNoise n Af) β§ ShiftReady D A Pi (C i) (r i/(2*D))
theorem compileDeclaredRoot_equivariant (D A Af : β) (hD : 0<D)
(P : Bool β β β β β Prop) (M : Bool β β β β β SeedProgram d)
(hv : βs r Ο,P s r Ο β (βj,(M s r Ο).shift j^2) β€ D^2)
(hM : βs r Ο,P s r Ο β βΞ,(M s r Ο).program.Equivariant
(moveSeed (fun x => x+r β’ Ξ) (M s r Ο).shift Ξ) id)
(f : Point d β X β X) (E : MeanTree X d) (n : β) (p : DriftData E)
(hp : DriftValid f E p) (hr : RootShiftReady D A Af (P true) (P false) E n) :
βΞ,(compileDeclaredRoot D A Af (M true) (M false) E n).compile.Equivariant
(moveSeed (f Ξ) (compileDeclaredRootShift D A Af (M true) (M false) E n p) Ξ)
(fun y => y+p.root E β’ Ξ) := by
cases E with | node k b hb a r C =>
intro Ξ
apply compileTerms_equivariant
Β· intro i
exact compileDeclared_equivariant D A hD (P false) (M false) (hv false) (hM false)
f (C i) (r i/(2*D)) (p.2 i) (hp.2 i) (hr i).2.2 Ξ
Β· intro i
exact transformed_mean_equivariant (M true (r i) (declaredNoise n Af)).program
(hr i).1 _ _ ((normalized_shift_bound hD _ (hv _ _ _ (hr i).2.1)).trans_lt (by norm_num))
(hM _ _ _ (hr i).2.1) ((p.2 i).root (C i)) Ξ
Β· exact noise_equivariant b hb _ p.1 (f Ξ) Ξ (hp.1 Ξ)
theorem compileDeclaredRoot_size (D A Af : β)
(P : Bool β β β β β Prop) (M : Bool β β β β β SeedProgram d)
(S Q : β) (hM : βs r Ο,P s r Ο β (M s r Ο).slots β€ S β§ (M s r Ο).calls β€ Q)
(E : MeanTree X d) (n : β) (hr : RootShiftReady D A Af (P true) (P false) E n) :
(compileDeclaredRoot D A Af (M true) (M false) E n).slots β€ 1+cost E*(S+1) β§
(compileDeclaredRoot D A Af (M true) (M false) E n).calls β€ cost E*Q := by
cases E with | node k b hb a r C =>
have hc (i) := compileDeclared_size D A (P false) (M false) S Q (hM false) (C i) (r i/(2*D)) (hr i).2.2
have hm (i) := hM true (r i) (declaredNoise n Af) (hr i).2.1
constructor
Β· simp only [compileDeclaredRoot,slots_compileTerms,Expression.slots,cost]
apply Nat.add_le_add_left
rw [Finset.sum_mul]
apply Finset.sum_le_sum
intro i _
have hβ := (hc i).1
have hβ := (hm i).1
nlinarith
Β· simp only [compileDeclaredRoot,calls_compileTerms,Expression.calls,zero_add,cost,Finset.sum_mul]
apply Finset.sum_le_sum
intro i _
have hβ := (hc i).2
have hβ := (hm i).2
nlinarith
theorem compileDeclaredRootShift_energy_bound {D A Af R B : β} (hD : 0<D) (hR : 0β€R) (hB : 0β€B)
(P : Bool β β β β β Prop) (M : Bool β β β β β SeedProgram d)
(hv : βs r Ο,P s r Ο β (βj,(M s r Ο).shift j^2) β€ D^2)
(hBv : βs r Ο,P s r Ο β (βj,(M s r Ο).shift j^2) β€ B)
(E : MeanTree X d) (n : β) (p : DriftData E)
(hr : RootShiftReady D A Af (P true) (P false) E n) (hg : DriftBound R E p) :
(βj,compileDeclaredRootShift D A Af (M true) (M false) E n p j^2) β€ (cost E:β)*(4*R^2*B) := by
cases E with | node k b hb a r C =>
change (βj,compileTermsShift D 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 i => compileDeclaredShift D A (M false) (C i) (r i/(2*D)) (p.2 i))
(fun i => inverseChildShift D (r i) ((p.2 i).root (C i)) (M true (r i) (declaredNoise n Af)))
(fun _ => 0) j^2) β€ _
rw [compileTermsShift_energy]
simp only [zero_pow (by decide : (2:β)β 0),Finset.sum_const_zero,zero_add,cost,Nat.cast_sum,Nat.cast_add,Nat.cast_one,Finset.sum_mul]
apply Finset.sum_le_sum
intro i _
have hc := compileDeclaredShift_energy_bound hD hR hB (P false) (M false) (hv false) (hBv false)
(C i) (r i/(2*D)) (p.2 i) (hr i).2.2 (hg i).2
have hi := inverse_shift_energy (fun j => (M true (r i) (declaredNoise n Af)).shift j/(2*D))
(M true (r i) (declaredNoise n Af)).shift (normalized_shift_bound hD _ (hv _ _ _ (hr i).2.1))
(((p.2 i).root (C i))/(r i))
have hs := hBv _ _ _ (hr i).2.1
have hh : (((p.2 i).root (C i))/(r i))^2 β€ R^2 := by
simpa only [sq_abs] using pow_le_pow_leftβ (abs_nonneg _) (hg i).1 2
have hm := mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left hh (by norm_num : (0:β)β€4)) hB
have hv' := mul_le_mul_of_nonneg_left hs (show 0β€4*(((p.2 i).root (C i))/(r i))^2 by positivity)
change (βj,compileDeclaredShift D A (M false) (C i) (r i/(2*D)) (p.2 i) j^2)+
(βj,inverseChildShift D (r i) ((p.2 i).root (C i)) (M true (r i) (declaredNoise n Af)) j^2) β€ _
change (βj,inverseChildShift D (r i) ((p.2 i).root (C i)) (M true (r i) (declaredNoise n Af)) j^2) β€ _ at hi
nlinarith
end LogConcaveSampling.MeanTree
end
end
end OAI
|