math / data /lean /OAI /Probability /LogConcave /OraclePrograms /PairDistBounds.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
13.9 kB
import Mathlib
import OAI.Probability.LogConcave.OraclePrograms.CircuitParameters
import OAI.Probability.LogConcave.OraclePrograms.MeanTreeBase
import OAI.Probability.LogConcave.OraclePrograms.CalibratedMeanCircuit
import OAI.Probability.LogConcave.Numerics.BaseVariationCenters
import OAI.Probability.LogConcave.Numerics.EvalLipschitz
namespace OAI
section
noncomputable section
namespace LogConcaveSampling.OracleCompiler.CircuitParameters
open MeanTree MeasureTheory Quadrature
open scoped Classical NNReal
variable (C : CircuitParameters) {d : β„•}
lemma pair_dist_bounds (z w : Point d Γ— Point d) :
β€–z.1-w.1‖≀dist z w ∧ β€–z.2-w.2‖≀dist z w := by
change β€–z.1-w.1‖≀ max (dist z.1 w.1) (dist z.2 w.2) ∧
β€–z.2-w.2‖≀ max (dist z.1 w.1) (dist z.2 w.2)
simp only [dist_eq_norm]
exact ⟨le_max_left _ _,le_max_right _ _⟩
lemma meanTree_anchorVariation {r Οƒ : ℝ} (hr : 0≀r) (x : Point d) (z w : Point d Γ— Point d) :
BaseVariation ((2*r+|Οƒ/2|)*dist z w) (x,z) (x,w) (C.meanTree r Οƒ) := by
have hg := literalMean_geometry (d:=d) (r:=r) (Οƒ:=Οƒ) (N:=C.N) (nc:=C.nc) (Nc:=C.Nc)
(by linarith [C.T_lower]) C.T_upper C.h_pos C.v_nonneg C.angle_bound C.meanEndpoint
have hd := pair_dist_bounds z w
apply baseVariation_of_centers
Β· rw [C.meanTree_base]
simp only [←smul_sub,norm_smul,Real.norm_eq_abs]
nlinarith [mul_le_mul_of_nonneg_left hd.2 (abs_nonneg (Οƒ/2)),mul_nonneg hr (dist_nonneg (x:=z) (y:=w))]
Β· exact centers_mono _ (fun r' b hb => by
have he := hb.variation hr C.T_upper.le (x,z) (x,w)
simp only [sub_self,norm_zero,zero_add] at he
nlinarith [mul_le_mul_of_nonneg_left (add_le_add hd.1 hd.2) hr,
mul_nonneg (abs_nonneg (Οƒ/2)) (dist_nonneg (x:=z) (y:=w))]) hg.2
lemma sampleTree_anchorVariation {r Ξ· : ℝ} (hr : 0≀r) (hΞ· : 0<Ξ·) (hΞ·1 : η≀1)
(x z w : Point d) :
BaseVariation ((r+|(sampleCorrelation η)⁻¹|)*dist z w) (x,z) (x,w)
(C.sampleTree r Ξ· hΞ· hΞ·1) := by
have hp := sampleCorrelation_properties hΞ· hΞ·1
have hg := literalSample_geometry (d:=d) (r:=r) (N:=C.N) (Nat.succ_pos C.n)
(by linarith [hp.1]) hp.2.1 C.h_pos (C.sampleEndpoint Ξ· hΞ· hΞ·1)
apply baseVariation_of_centers
Β· unfold sampleTree
rw [hg.1]
simp only [←smul_sub,norm_smul,Real.norm_eq_abs,dist_eq_norm]
nlinarith [mul_nonneg hr (norm_nonneg (z-w))]
Β· exact centers_mono _ (fun r' b hb => by
have he := hb.variation hr hp.2.1.le (x,z) (x,w)
simp only [sub_self,norm_zero,zero_add,add_zero] at he
rw [dist_eq_norm]
nlinarith [mul_nonneg (abs_nonneg ((sampleCorrelation η)⁻¹)) (norm_nonneg (z-w))]) hg.2
lemma meanTree_anchor_lipschitz {F : Point d β†’ ℝ} {lam : ℝβ‰₯0} (hF : Primitive F lam)
{r Οƒ : ℝ} (hr : 0<r) (hl : (lam:ℝ)*r^2≀1/4) (x : Point d) :
βˆƒK : ℝβ‰₯0,LipschitzWith K (fun z : Point d Γ— Point d => (C.meanTree r Οƒ).eval F (x,z)) := by
have hg := literalMean_geometry (d:=d) (r:=r) (Οƒ:=Οƒ) (N:=C.N) (nc:=C.nc) (Nc:=C.Nc)
(by linarith [C.T_lower]) C.T_upper C.h_pos C.v_nonneg C.angle_bound C.meanEndpoint
apply eval_exists_lipschitz hF (C.meanTree r Οƒ) (fun z => (x,z))
Β· rw [C.meanTree_base]
exact ⟨_,(lipschitzWith_smul (Οƒ/2)).comp LipschitzWith.prod_snd⟩
Β· apply centers_mono _ (fun r' b hb => ?_) hg.2
have hr' := hb.radius_pos hr (by linarith [C.T_lower]) C.T_upper
have hb' := hb.radius hr.le (by linarith [C.T_lower]) C.T_upper
have hs := mul_le_mul_of_nonneg_left (pow_le_pow_leftβ‚€ hr'.le hb'.2 2) lam.coe_nonneg
refine ⟨hr',hs.trans hl,?_⟩
obtain ⟨ρ,hρ,θ,hθ,he,rfl⟩ := hb
exact ⟨_,(LipschitzWith.const x).add ((lipschitzWith_smul (r*ρ)).comp
(((lipschitzWith_smul (Real.cos ΞΈ)).comp LipschitzWith.prod_fst).add
((lipschitzWith_smul (Real.sin θ)).comp LipschitzWith.prod_snd)))⟩
lemma sampleTree_anchor_lipschitz {F : Point d β†’ ℝ} {lam : ℝβ‰₯0} (hF : Primitive F lam)
{r Ξ· : ℝ} (hr : 0<r) (hΞ· : 0<Ξ·) (hΞ·1 : η≀1) (hl : (lam:ℝ)*r^2≀1/4) (x : Point d) :
βˆƒK : ℝβ‰₯0,LipschitzWith K (fun z : Point d => (C.sampleTree r Ξ· hΞ· hΞ·1).eval F (x,z)) := by
have hp := sampleCorrelation_properties hΞ· hΞ·1
have hg := literalSample_geometry (d:=d) (r:=r) (N:=C.N) (Nat.succ_pos C.n)
(by linarith [hp.1]) hp.2.1 C.h_pos (C.sampleEndpoint Ξ· hΞ· hΞ·1)
apply eval_exists_lipschitz hF (C.sampleTree r Ξ· hΞ· hΞ·1) (fun z => (x,z))
Β· unfold sampleTree
rw [hg.1]
exact ⟨_,lipschitzWith_smul ((sampleCorrelation η)⁻¹)⟩
Β· apply centers_mono _ (fun r' b hb => ?_) hg.2
have hr' := hb.radius_pos hr (by linarith [hp.1]) hp.2.1
have hb' := hb.radius hr.le (by linarith [hp.1]) hp.2.1
have hs := mul_le_mul_of_nonneg_left (pow_le_pow_leftβ‚€ hr'.le hb'.2 2) lam.coe_nonneg
refine ⟨hr',hs.trans hl,?_⟩
obtain ⟨ρ,hρ,θ,hθ,he,rfl⟩ := hb
exact ⟨_,(LipschitzWith.const x).add ((lipschitzWith_smul (r*ρ)).comp
((lipschitzWith_smul (Real.cos θ)).add ((lipschitzWith_smul (Real.sin θ)).comp (LipschitzWith.const 0))))⟩
lemma meanCompiled_anchor_lipschitz {r Οƒ Lf Li : ℝ} (hr : 0<r) (hΟƒ : 0<Οƒ)
(hψ : 0≀C.ψ) (hA : C.A=C.actualA) (hAf : C.Af=C.actualAf)
(hLf : 0≀Lf) (hLi : 0≀Li) (hsmall : Li*C.meanCenterBudget r σ≀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)‖≀Lf*β€–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β€–)
(n : ℝ) (hready : RootShiftReady C.D (C.meanCenterBudget r Οƒ) C.Af
(P true) (P false) (C.meanTree (d:=d) r Οƒ) n) (x : Point d) :
let E := compileDeclaredRoot C.D (C.meanCenterBudget r Οƒ) C.Af
(M true) (M false) (C.meanTree (d:=d) r Οƒ) n
βˆƒK : ℝ,0≀K ∧ βˆ€z w g,β€–E.eval V (x,z) g-E.eval V (x,w) g‖≀K*dist z w := by
have hw := C.meanTree_actual_weights (d:=d) hr hΟƒ hψ
rw [←hAf,←hA] at hw
have hAf0 : 0≀C.Af := by rw [hAf]; exact C.actualAf_pos.le
let b := 2*r+|Οƒ/2|
refine ⟨C.Af*Lf*(depth (C.meanTree (d:=d) r Οƒ):ℝ)*b+b,by dsimp [b]; positivity,?_⟩
intro z w g
have hv := C.meanTree_anchorVariation (Οƒ:=Οƒ) hr.le x z w
have hb : β€–base (C.meanTree r Οƒ) (x,z)-base (C.meanTree r Οƒ) (x,w)‖≀b*dist z w := by
generalize C.meanTree (d:=d) r Οƒ=E at hv ⊒
cases E
exact hv.1
have he := compileDeclaredRoot_variation hLf hLi (show 0≀b*dist z w by dsimp [b]; positivity)
hsmall V P M hm hmi (C.meanTree r Οƒ) n (x,z) (x,w) hv hb hw.1 hw.2 hready g
convert he using 1
dsimp [b]
ring
lemma sampleCompiled_anchor_lipschitz {r Ξ· Lf Li : ℝ} (hr : 0<r) (hΞ· : 0<Ξ·) (hΞ·1 : η≀1)
(hA : C.A=C.actualA) (hAf : C.Af=C.actualAf)
(hLf : 0≀Lf) (hLi : 0≀Li) (hsmall : Li*C.sampleCenterBudget r≀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)‖≀Lf*β€–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β€–)
(n : ℝ) (hready : RootShiftReady C.D (C.sampleCenterBudget r) (C.sampleFinalBudget r)
(P true) (P false) (C.sampleTree (d:=d) r Ξ· hΞ· hΞ·1) n) (x : Point d) :
let E := compileDeclaredRoot C.D (C.sampleCenterBudget r) (C.sampleFinalBudget r)
(M true) (M false) (C.sampleTree (d:=d) r Ξ· hΞ· hΞ·1) n
βˆƒK : ℝ,0≀K ∧ βˆ€z w g,β€–E.eval V (x,z) g-E.eval V (x,w) g‖≀K*dist z w := by
have hw := C.sampleTree_actual_weights (d:=d) hr hΞ· hΞ·1
rw [←hAf,←hA] at hw
have hAf0 : 0≀C.sampleFinalBudget r := by unfold sampleFinalBudget; rw [hAf]; positivity [C.actualAf_pos]
let b := r+|(sampleCorrelation η)⁻¹|
refine ⟨C.sampleFinalBudget r*Lf*(depth (C.sampleTree (d:=d) r Ξ· hΞ· hΞ·1):ℝ)*b+b,by dsimp [b]; positivity,?_⟩
intro z w g
have hv := C.sampleTree_anchorVariation hr.le hΞ· hΞ·1 x z w
have hb : β€–base (C.sampleTree r Ξ· hΞ· hΞ·1) (x,z)-base (C.sampleTree r Ξ· hΞ· hΞ·1) (x,w)‖≀b*dist z w := by
generalize C.sampleTree (d:=d) r η hη hη1=E at hv ⊒
cases E
exact hv.1
have he := compileDeclaredRoot_variation hLf hLi (show 0≀b*dist z w by dsimp [b]; positivity)
hsmall V P M hm hmi (C.sampleTree r Ξ· hΞ· hΞ·1) n (x,z) (x,w) hv hb hw.1 hw.2 hready g
convert he using 1 <;> (try simp only [sampleFinalBudget])
dsimp [b]
ring
end LogConcaveSampling.OracleCompiler.CircuitParameters
end
end
section
noncomputable section
namespace LogConcaveSampling.OracleCompiler.CircuitParameters
open MeasureTheory ProbabilityTheory MeanTree Quadrature Function
open scoped Classical NNReal
variable (C : CircuitParameters) {d : β„•}
lemma meanTree_eval {F : Point d β†’ ℝ} {lam : ℝβ‰₯0} (hF : Primitive F lam)
(r Οƒ : ℝ) (x : Point d) (y : Point d Γ— Point d) :
(C.meanTree r Οƒ).eval F (x,y)=
centeringMeanCircuit F x r C.T C.h C.ψ (Οƒ/2) C.n C.m C.N C.nc C.Nc C.meanEndpoint
((productPointEquiv d d).symm y) := by
unfold meanTree literalMean
rw [eval_meanCircuit hF (by linarith [C.T_lower]) C.T_upper C.h_pos]
simp only [eval_anchor]
lemma sampleTree_eval {F : Point d β†’ ℝ} {lam : ℝβ‰₯0} (hF : Primitive F lam)
(r Ξ· : ℝ) (hΞ· : 0<Ξ·) (hΞ·1 : η≀1) (x Y : Point d) :
(C.sampleTree r Ξ· hΞ· hΞ·1).eval F (x,Y)=
sampleMeanCircuit F x r (sampleCorrelation Ξ·) C.h (C.n+1) C.N (C.sampleEndpoint Ξ· hΞ· hΞ·1) Y := by
unfold sampleTree literalSample
rw [eval_scale,eval_forward hF (Nat.succ_pos C.n)
(by linarith [(sampleCorrelation_properties hΞ· hΞ·1).1])
(sampleCorrelation_properties hΞ· hΞ·1).2.1 C.h_pos]
simp only [eval_anchor,sampleMeanCircuit]
theorem meanTree_numerical {F : Point d β†’ ℝ} {lam : ℝβ‰₯0} (hF : Primitive F lam)
(x : Point d) {r Οƒ err : ℝ} (hr : 0<r) (hl : (lam:ℝ)*r^2≀1/4)
(hm : C.m=C.n) (hnc : C.nc=C.n) (hNc : C.Nc=C.N)
(hcert : CalibratedMeanCircuit (r:=r) (T:=C.T) (h:=C.h) (ψ:=C.ψ) (s:=Οƒ/2)
hF x hr (by linarith : (lam:ℝ)*r^2≀1/2) (by linarith [C.T_lower]) C.T_upper
C.h_pos C.n C.N err) :
βˆƒw : Point d Γ— Point d β†’ Point d,Measurable w ∧
((interpolationLaw F x r C.T).prod (stdGaussian (Point d))).map w=
(stdGaussian (Point d)).map (fun z => primitiveExpectedField F x r+(Οƒ/2) β€’ z) ∧
Integrable (fun z => β€–(C.meanTree r Οƒ).eval F (x,z)-w zβ€–^2)
((interpolationLaw F x r C.T).prod (stdGaussian (Point d))) ∧
(∫z,β€–(C.meanTree r Οƒ).eval F (x,z)-w zβ€–^2
βˆ‚(interpolationLaw F x r C.T).prod (stdGaussian (Point d)))≀
((Οƒ/2)*circuitD F x)^2*err := by
obtain ⟨X,hsi,hsb,hw,hlaw,hi,hnum⟩ := hcert
let wβ‚€ := stationaryMeanTarget hF x hr (by linarith : (lam:ℝ)*r^2≀1/2)
(by linarith [C.T_lower] : 0≀C.T) C.T_upper X
let w : Point d Γ— Point d β†’ Point d := fun z => wβ‚€ ((productPointEquiv d d).symm z)
have hw' : Measurable w := hw.comp (productPointEquiv d d).symm.continuous.measurable
have hjoint := centering_joint_law hF x hr.le (by linarith : (lam:ℝ)*r^2≀1/2)
(by linarith [C.T_lower]) C.T_upper
obtain ⟨K,hK⟩ := C.meanTree_anchor_lipschitz hF hr hl x
have hg : Measurable (fun z => (C.meanTree r Οƒ).eval F (x,z)) := hK.continuous.measurable
have hid : βˆ€y : Point (d+d),
(C.meanTree r Οƒ).eval F (x,productPointEquiv d d y)-w (productPointEquiv d d y)=
centeringMeanCircuit F x r C.T C.h C.ψ (Οƒ/2) C.n C.n C.N C.n C.N C.meanEndpoint y-wβ‚€ y := by
intro y
rw [C.meanTree_eval hF]
simp only [hm,hnc,hNc,w,ContinuousLinearEquiv.symm_apply_apply]
refine ⟨w,hw',?_,?_,?_⟩
Β· rw [←hjoint,Measure.map_map hw' (productPointEquiv d d).continuous.measurable]
simpa only [comp_def,w,ContinuousLinearEquiv.symm_apply_apply] using hlaw
Β· rw [←hjoint]
apply (integrable_map_measure (by fun_prop) (productPointEquiv d d).continuous.measurable.aemeasurable).mpr
simpa only [hid,comp_def,meanEndpoint,wβ‚€] using hi
Β· rw [←hjoint,integral_map (productPointEquiv d d).continuous.measurable.aemeasurable (by fun_prop)]
simpa only [hid,meanEndpoint,wβ‚€] using hnum
lemma meanTree_numerical_noisy {F : Point d β†’ ℝ} {lam : ℝβ‰₯0} (hF : Primitive F lam)
(x : Point d) {r Οƒ err : ℝ} (hr : 0<r) (hl : (lam:ℝ)*r^2≀1/4)
(hm : C.m=C.n) (hnc : C.nc=C.n) (hNc : C.Nc=C.N)
(hcert : CalibratedMeanCircuit (r:=r) (T:=C.T) (h:=C.h) (ψ:=C.ψ) (s:=Οƒ/2)
hF x hr (by linarith : (lam:ℝ)*r^2≀1/2) (by linarith [C.T_lower]) C.T_upper
C.h_pos C.n C.N err) :
βˆƒw : Point d Γ— Point d β†’ Point d,Measurable w ∧
(((interpolationLaw F x r C.T).prod (stdGaussian (Point d))).prod (stdGaussian (Point d))).map
(fun z => w z.1+(Real.sqrt 3*Οƒ/2) β€’ z.2)=
(stdGaussian (Point d)).map (fun z => primitiveExpectedField F x r+Οƒ β€’ z) ∧
Integrable (fun z => β€–(C.meanTree r Οƒ).eval F (x,z)-w zβ€–^2)
((interpolationLaw F x r C.T).prod (stdGaussian (Point d))) ∧
(∫z,β€–(C.meanTree r Οƒ).eval F (x,z)-w zβ€–^2
βˆ‚(interpolationLaw F x r C.T).prod (stdGaussian (Point d)))≀
((Οƒ/2)*circuitD F x)^2*err := by
obtain ⟨w,hw,hlaw,hi,hnum⟩ := C.meanTree_numerical hF x hr hl hm hnc hNc hcert
let := interpolationLaw_probability hF x hr.le (by linarith : (lam:ℝ)*r^2<1) C.T
refine ⟨w,hw,?_,hi,hnum⟩
apply law_add_gaussian _ w hw (primitiveExpectedField F x r) (Οƒ/2) (Real.sqrt 3*Οƒ/2) Οƒ _ hlaw
rw [div_pow,div_pow,mul_pow,Real.sq_sqrt (by norm_num : (0:ℝ)≀3)]
ring
end LogConcaveSampling.OracleCompiler.CircuitParameters
end
end
end OAI