Download data/lean/OAI/Probability/Localization/Model.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 9.11 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/Localization/Model.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Probability/Localization/Model.lean
-
curl -L -o Model.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/Localization/Model.lean
9.11 kB
| import Mathlib | |
| namespace OAI | |
| open MeasureTheory ProbabilityTheory Set | |
| open scoped BigOperators ENNReal | |
| namespace RepeatedLocalization | |
| abbrev Coordinate (n : β) := Fin n β β | |
| abbrev GaussianBlock (n : β) := Fin (n / 16) β Fin (n + 1) β β | |
| abbrev Label (n : β) := Fin (n / 16) β β | |
| abbrev History (N t : β) := Fin t β Fin N | |
| abbrev Cell (n : β) := Ξ£ J : β, Fin n β Fin (2 ^ J) | |
| instance cellMeasurableSpace (n : β) : MeasurableSpace (Cell n) := β€ | |
| noncomputable def initialCube (n : β) : Set (Coordinate n) := | |
| Set.pi Set.univ (fun _ => Set.Ico (-1 / (2 * Real.sqrt n)) (1 / (2 * Real.sqrt n))) | |
| noncomputable def cubePrior (n : β) : Measure (Coordinate n) := | |
| ProbabilityTheory.cond volume (initialCube n) | |
| noncomputable def chart {n : β} (z : Coordinate n) : Fin (n + 1) β β := | |
| Fin.lastCases (Real.sqrt (1 - β a, (z a) ^ 2)) z | |
| noncomputable def cellSet {n : β} (Q : Cell n) : Set (Coordinate n) := | |
| {z | β a, -1 / (2 * Real.sqrt n) + (Q.2 a : β) / (Real.sqrt n * (2 : β) ^ Q.1) β€ z a β§ | |
| z a < -1 / (2 * Real.sqrt n) + ((Q.2 a : β) + 1) / (Real.sqrt n * (2 : β) ^ Q.1)} | |
| def rootCell (n : β) : Cell n := β¨0, fun _ => 0β© | |
| noncomputable def gaussianBlockLaw (n : β) : Measure (GaussianBlock n) := | |
| Measure.pi (fun _ => Measure.pi (fun _ => gaussianReal 0 1)) | |
| noncomputable def exactLabel {n : β} (X : GaussianBlock n) (z : Coordinate n) : Label n := | |
| fun row => β a, X row a * chart z a | |
| structure BlockRule (n N : β) where | |
| prob : (GaussianBlock n Γ Label n) β Fin N β β | |
| measurable_prob : β w, Measurable (fun data => prob data w) | |
| nonneg : β data w, 0 β€ prob data w | |
| sum_one : β data, β w, prob data w = 1 | |
| abbrev Rules (n N t : β) := β i : Fin t, History N i.val β BlockRule n N | |
| def past {N t : β} (w : History N t) (i : Fin t) : History N i.val := | |
| fun j => w β¨j.val, Nat.lt_trans j.isLt i.isLtβ© | |
| def through {N t : β} (w : History N t) (i : Fin t) : History N (i.val + 1) := | |
| fun j => w β¨j.val, Nat.lt_of_lt_of_le j.isLt i.isLtβ© | |
| noncomputable def blockProbability {n N : β} (rule : BlockRule n N) | |
| (z : Coordinate n) (w : Fin N) : β := | |
| β« X, rule.prob (X, exactLabel X z) w βgaussianBlockLaw n | |
| noncomputable def historyLikelihood {n N t : β} (rules : Rules n N t) | |
| (z : Coordinate n) (w : History N t) : β := | |
| β i, blockProbability (rules i (past w i)) z (w i) | |
| noncomputable def experimentLaw {n N t : β} (rules : Rules n N t) : | |
| Measure (Coordinate n Γ History N t) := | |
| β w : History N t, | |
| ((cubePrior n).withDensity (fun z => ENNReal.ofReal (historyLikelihood rules z w))).map | |
| (fun z => (z, w)) | |
| abbrev Disclosure (n N t : β) := β i : Fin t, Coordinate n β History N (i.val + 1) β Cell n | |
| def ValidDisclosure {n N t : β} (Q : Disclosure n N t) : Prop := | |
| (β i, Measurable (fun zh : Coordinate n Γ History N (i.val + 1) => Q i zh.1 zh.2)) β§ | |
| (β i, (Set.range (fun zh : Coordinate n Γ History N (i.val + 1) => Q i zh.1 zh.2)).Finite) β§ | |
| (β z β initialCube n, β w : History N t, β i, | |
| z β cellSet (Q i z (through w i)) β§ cellSet (Q i z (through w i)) β initialCube n) β§ | |
| (β z β initialCube n, β w : History N t, β i j : Fin t, i β€ j β | |
| cellSet (Q j z (through w j)) β cellSet (Q i z (through w i))) | |
| noncomputable def transcriptMap {n N t : β} (Q : Disclosure n N t) | |
| (zw : Coordinate n Γ History N t) : Coordinate n Γ (History N t Γ (Fin t β Cell n)) := | |
| (zw.1, (zw.2, fun i => Q i zw.1 (through zw.2 i))) | |
| noncomputable def augmentedLaw {n N t : β} (rules : Rules n N t) (Q : Disclosure n N t) := | |
| (experimentLaw rules).map (transcriptMap Q) | |
| noncomputable def mutualInformation {Ξ± Ξ² : Type*} [MeasurableSpace Ξ±] [MeasurableSpace Ξ²] | |
| (ΞΌ : Measure (Ξ± Γ Ξ²)) : ββ₯0β := | |
| InformationTheory.klDiv ΞΌ ((ΞΌ.map Prod.fst).prod (ΞΌ.map Prod.snd)) | |
| noncomputable def finalLevel {n N t : β} (Q : Disclosure n N t) | |
| (zw : Coordinate n Γ History N t) : β := | |
| if ht : 0 < t then | |
| let i : Fin t := β¨t - 1, by omegaβ© | |
| (Q i zw.1 (through zw.2 i)).1 | |
| else 0 | |
| def MainStatement : Prop := | |
| β c : β, 0 < c β§ β nβ : β, β Cβ : β, 0 < Cβ β | |
| β C : β, 0 < C β§ β (n N t : β), nβ β€ n β 1 β€ N β β rules : Rules n N t, | |
| (2 / (n / 8 : β) + Real.exp (-c * (n / 16 : β))) * Real.log N β€ Cβ * (n + 1) β | |
| β Q : Disclosure n N t, ValidDisclosure Q β§ | |
| mutualInformation (augmentedLaw rules Q) β€ ENNReal.ofReal (C * (n + 1) * t) β§ | |
| (β« zw, (finalLevel Q zw : β) βexperimentLaw rules) β€ C * t | |
| namespace FiniteEntropy | |
| noncomputable def uniformCell {n : β} (Q : Cell n) : Measure (Coordinate n) := | |
| ProbabilityTheory.cond volume (cellSet Q) | |
| def Descendant {n : β} (Q R : Cell n) : Prop := | |
| Q.1 β€ R.1 β§ cellSet R β cellSet Q | |
| noncomputable def threshold (n h : β) : β := (2:β)^(-(n:β)*h/2) | |
| def Heavy {n : β} (P : Measure (Coordinate n)) (Q R : Cell n) : Prop := | |
| Descendant Q R β§ Q.1 < R.1 β§ threshold n (R.1-Q.1) < (P (cellSet R)).toReal | |
| def FirstHeavy {n : β} (P : Measure (Coordinate n)) (Q R : Cell n) : Prop := | |
| Heavy P Q R β§ β E : Cell n, Heavy P Q E β Descendant E R β E = R | |
| noncomputable def residual {n : β} (P : Measure (Coordinate n)) (Q : Cell n) : Set (Coordinate n) := | |
| cellSet Q \ β R : {R : Cell n // FirstHeavy P Q R}, cellSet R.val | |
| abbrev Letter (n : β) := Option (Cell n) | |
| abbrev Log (n : β) := List (Letter n) | |
| instance logMeasurableSpace (n : β) : MeasurableSpace (Log n) := β€ | |
| noncomputable def branch {n : β} (P : Measure (Coordinate n)) (Q : Cell n) : Letter n β Set (Coordinate n) := by | |
| classical | |
| exact fun | |
| | none => residual P Q | |
| | some R => if FirstHeavy P Q R then cellSet R else β | |
| noncomputable def attemptLetter {n : β} (P : Measure (Coordinate n)) (Q : Cell n) | |
| (z : Coordinate n) : Letter n := by | |
| classical | |
| exact if h : β R : Cell n, FirstHeavy P Q R β§ z β cellSet R then some h.choose else none | |
| structure State (n : β) where | |
| cell : Cell n | |
| event : Set (Coordinate n) | |
| stopped : Bool | |
| noncomputable def update {n : β} (P : Measure (Coordinate n)) (s : State n) (a : Letter n) : State n := | |
| if s.stopped then s else | |
| let ΞΌ := ProbabilityTheory.cond P s.event | |
| let E := branch ΞΌ s.cell a | |
| { cell := a.getD s.cell | |
| event := s.event β© E | |
| stopped := if a = none then decide ((1/2:β) β€ (ΞΌ E).toReal) else false } | |
| noncomputable def state {n : β} (P : Measure (Coordinate n)) (Q : Cell n) (h : Log n) : State n := | |
| h.foldl (update P) β¨Q,cellSet Q,falseβ© | |
| noncomputable def run {n : β} (P : Measure (Coordinate n)) (Q : Cell n) : β β Coordinate n β Log n | |
| | 0, _ => [] | |
| | N+1, z => | |
| let h := run P Q N z | |
| let s := state P Q h | |
| if s.stopped then h else | |
| h ++ [attemptLetter (ProbabilityTheory.cond P s.event) s.cell z] | |
| def Terminates {n : β} (P : Measure (Coordinate n)) (Q : Cell n) (z : Coordinate n) : Prop := | |
| β N, (state P Q (run P Q N z)).stopped = true | |
| noncomputable def attempts {n : β} (P : Measure (Coordinate n)) (Q : Cell n) (z : Coordinate n) : β := by | |
| classical | |
| exact if h : Terminates P Q z then Nat.find h else 0 | |
| noncomputable def terminalLog {n : β} (P : Measure (Coordinate n)) (Q : Cell n) (z : Coordinate n) : Log n := | |
| run P Q (attempts P Q z) z | |
| noncomputable def terminalCell {n : β} (P : Measure (Coordinate n)) (Q : Cell n) (h : Log n) : Cell n := | |
| (state P Q h).cell | |
| noncomputable def terminalLaw {n : β} (P : Measure (Coordinate n)) (Q : Cell n) (h : Log n) : Measure (Coordinate n) := | |
| ProbabilityTheory.cond P {z | terminalLog P Q z = h} | |
| noncomputable def depth {n : β} (P : Measure (Coordinate n)) (Q : Cell n) (z : Coordinate n) : β := | |
| (terminalCell P Q (terminalLog P Q z)).1-Q.1 | |
| def Regular {n : β} (P : Measure (Coordinate n)) (Q : Cell n) : Prop := | |
| P (cellSet Q) = 1 β§ β R : Cell n, Descendant Q R β Q.1 < R.1 β | |
| (P (cellSet R)).toReal β€ 2 * threshold n (R.1-Q.1) | |
| def FiniteEntropyStatement : Prop := | |
| β nβ : β, β n : β, nβ β€ n β β Q : Cell n, β P : Measure (Coordinate n), | |
| IsProbabilityMeasure P β P βͺ uniformCell Q β InformationTheory.klDiv P (uniformCell Q) β β β | |
| (βα΅ z βP, Terminates P Q z) β§ Measurable (terminalLog P Q) β§ | |
| (β h : Log n, P {z | terminalLog P Q z = h} β 0 β | |
| Descendant Q (terminalCell P Q h) β§ Regular (terminalLaw P Q h) (terminalCell P Q h)) β§ | |
| Integrable (fun z => (depth P Q z : β)) P β§ | |
| Integrable (fun z => (attempts P Q z : β)) P β§ | |
| (β« z,(attempts P Q z : β) βP) β€ 2*(1+β« z,(depth P Q z : β) βP) β§ | |
| (β«β» z,InformationTheory.klDiv (terminalLaw P Q (terminalLog P Q z)) | |
| (uniformCell (terminalCell P Q (terminalLog P Q z))) βP) + | |
| ENNReal.ofReal ((Real.log 2/4)*n*(β« z,(depth P Q z : β) βP)) β€ | |
| InformationTheory.klDiv P (uniformCell Q) + ENNReal.ofReal (2/Real.exp 1) | |
| end FiniteEntropy | |
| end RepeatedLocalization | |
| end OAI | |