File size: 5,108 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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | 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
|