math / data /lean /OAI /Probability /LogConcave /OraclePrograms /CircuitParameters.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
5.11 kB
import Mathlib
import OAI.Probability.LogConcave.OraclePrograms.RoutineKind
import OAI.Probability.LogConcave.Numerics.CompileDeclaredRootShift
import OAI.Probability.LogConcave.OraclePrograms.TerminalMeanProgram
import OAI.Probability.LogConcave.Sampling.SampleCorrelation
namespace OAI
section
noncomputable section
namespace LogConcaveSampling.OracleCompiler
open MeanTree Quadrature
open scoped Classical
structure CircuitParameters where
n : β„•
m : β„•
N : β„•
nc : β„•
Nc : β„•
T : ℝ
h : ℝ
ψ : ℝ
v : ℝ
D : ℝ
A : ℝ
Af : ℝ
T_lower : 1/2≀T
T_upper : T<1
h_pos : 0<h
v_nonneg : 0≀v
angle_bound : βˆ€j : Fin (m+1),|ψ*angleNodes m j|≀v
angle_small : v^2≀Real.sqrt (1-T^2)
namespace CircuitParameters
variable (C : CircuitParameters) {d : β„•}
def meanEndpoint : ProbabilityNode C.T C.h (C.n+1) :=
probabilityEndpoint (by linarith [C.T_lower]) C.T_upper C.h_pos (C.n+1)
def meanTree (r Οƒ : ℝ) : MeanTree (MeanInput d) d :=
literalMean r C.T C.h C.ψ Οƒ C.n C.m C.N C.nc C.Nc C.meanEndpoint
def meanDrift (r Οƒ : ℝ) (hr : 0<r) : DriftData (C.meanTree (d:=d) r Οƒ) :=
(literalMean_drift hr C.T_lower C.T_upper C.h_pos C.v_nonneg C.angle_small C.angle_bound C.meanEndpoint).choose
lemma meanDrift_spec (r Οƒ : ℝ) (hr : 0<r) :
DriftValid (meanInputMove r C.T) (C.meanTree (d:=d) r Οƒ) (C.meanDrift r Οƒ hr) ∧
(C.meanDrift (d:=d) r Οƒ hr).root _=0 ∧ DriftBound 3 _ (C.meanDrift (d:=d) r Οƒ hr) :=
(literalMean_drift hr C.T_lower C.T_upper C.h_pos C.v_nonneg C.angle_small C.angle_bound C.meanEndpoint).choose_spec
def sampleEndpoint (Ξ· : ℝ) (hΞ· : 0<Ξ·) (hΞ·1 : η≀1) :
ProbabilityNode (sampleCorrelation Ξ·) C.h (C.n+1) :=
probabilityEndpoint (by linarith [(sampleCorrelation_properties hΞ· hΞ·1).1])
(sampleCorrelation_properties hΞ· hΞ·1).2.1 C.h_pos (C.n+1)
def sampleTree (r Ξ· : ℝ) (hΞ· : 0<Ξ·) (hΞ·1 : η≀1) : MeanTree (SampleInput d) d :=
literalSample r (sampleCorrelation Ξ·) C.h (C.n+1) C.N (C.sampleEndpoint Ξ· hΞ· hΞ·1)
def sampleDrift (r Ξ· : ℝ) (hr : 0<r) (hΞ· : 0<Ξ·) (hΞ·1 : η≀1) :
DriftData (C.sampleTree (d:=d) r Ξ· hΞ· hΞ·1) :=
(literalSample_drift hr (Nat.succ_pos C.n)
(by linarith [(sampleCorrelation_properties hΞ· hΞ·1).1])
(sampleCorrelation_properties hΞ· hΞ·1).2.1 C.h_pos (C.sampleEndpoint Ξ· hΞ· hΞ·1)).choose
def meanCenterBudget (r Οƒ : ℝ) : ℝ := C.A*(r/Οƒ+r^2)
def sampleCenterBudget (r : ℝ) : ℝ := C.A*r^2
def sampleFinalBudget (r : ℝ) : ℝ := C.Af*r
def meanFrom (Mf Mi : ℝ β†’ ℝ β†’ SeedProgram d) (S : ℝ β†’ ℝ β†’ ReservedProgram d)
(r Οƒ : ℝ) : SeedProgram d :=
if hr : 0<r then
let E := C.meanTree r Οƒ
let p := C.meanDrift r Οƒ hr
let noise := Real.sqrt 3*Οƒ/2
let B := compileDeclaredRoot C.D (C.meanCenterBudget r Οƒ) C.Af Mf Mi E noise
let v := compileDeclaredRootShift C.D (C.meanCenterBudget r Οƒ) C.Af Mf Mi E noise p
let R := Real.sqrt (1-C.T^2)
let anchor := S r (R/C.T)
meanParent anchor.full B (anchor.extraShift (-2*R/C.T)) v C.T
else terminalMeanProgram d r Οƒ
def sampleFrom (Mf Mi : ℝ β†’ ℝ β†’ SeedProgram d) (r Ξ· : ℝ) : ReservedProgram d :=
if hv : 0<r ∧ 0<Ξ· ∧ η≀1 then
let E := C.sampleTree r Ξ· hv.2.1 hv.2.2
let p := C.sampleDrift r Ξ· hv.1 hv.2.1 hv.2.2
let noise := Ξ·/Real.sqrt 2
let B := compileDeclaredRoot C.D (C.sampleCenterBudget r) (C.sampleFinalBudget r) Mf Mi E noise
let v := compileDeclaredRootShift C.D (C.sampleCenterBudget r) (C.sampleFinalBudget r) Mf Mi E noise p
sampleParent B v (sampleCorrelation Ξ·) Ξ·
else terminalReservedProgram d r Ξ·
end CircuitParameters
def RoutineValue (d : β„•) : RoutineKind β†’ Type
| .mean => ℝ β†’ ℝ β†’ SeedProgram d
| .sample => ℝ β†’ ℝ β†’ ReservedProgram d
def constructRoutine (d : β„•) (C : CircuitParameters) {t : ℝ} (ht : 0<t) (hs : t≀1/44)
(L : RoutineLabel) : RoutineValue d L.kind :=
if _ : L.terminal then
match L.kind with
| .mean => terminalMeanProgram d
| .sample => terminalReservedProgram d
else
match hk : L.kind with
| .mean => C.meanFrom
(constructRoutine d C ht hs ⟨.mean,L.b+t,L.p⟩)
(constructRoutine d C ht hs ⟨.mean,L.b-10*t,L.p-1/4⟩)
(constructRoutine d C ht hs ⟨.sample,L.b-10*t,L.p-1/4⟩)
| .sample => C.sampleFrom
(constructRoutine d C ht hs ⟨.mean,L.b,L.p⟩)
(constructRoutine d C ht hs ⟨.mean,L.b-10*t,L.p-1/4⟩)
termination_by L.rank t
decreasing_by
all_goals apply RoutineStep.rank_lt ht hs (by assumption)
Β· simpa only [←hk] using (RoutineStep.meanFinal (t:=t) L.b L.p)
Β· simpa only [←hk] using (RoutineStep.internal (t:=t) RoutineKind.mean RoutineKind.mean L.b L.p)
Β· simpa only [←hk] using (RoutineStep.internal (t:=t) RoutineKind.mean RoutineKind.sample L.b L.p)
Β· simpa only [←hk] using (RoutineStep.sampleFinal (t:=t) L.b L.p)
Β· simpa only [←hk] using (RoutineStep.internal (t:=t) RoutineKind.sample RoutineKind.mean L.b L.p)
end LogConcaveSampling.OracleCompiler
end
end
end OAI