File size: 10,441 Bytes
f205175
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
import OAI.Probability.DilutedSpin.InsertionPoint
import OAI.Probability.DilutedSpin.TowerSum

namespace OAI

section
namespace DilutedSpinGlass
namespace KernelTower
variable {Ω Λ Ω' Λ' : Type} [Fintype Ω] [Fintype Λ] [Fintype Ω'] [Fintype Λ']

lemma Projects.refl (n : ℕ) (T : KernelTower Ω n) : Projects id n T T := by
  induction n with
  | zero => trivial
  | succ n ih => exact ⟨fun _ => rfl,fun a => ih (T.2 a)⟩

lemma Projects.comp {π : Ω → Λ} {ρ : Λ → Ω'} (n : ℕ)
    {T : KernelTower Ω n} {U : KernelTower Λ n} {V : KernelTower Ω' n}
    (h : Projects π n T U) (g : Projects ρ n U V) : Projects (ρ ∘ π) n T V := by
  induction n with
  | zero => trivial
  | succ n ih =>
    refine ⟨?_,fun a => ih (h.2 a) (g.2 (π a))⟩
    intro f
    exact (h.1 (f ∘ ρ)).trans (g.1 f)

lemma Projects.prod {π : Ω → Ω'} {ρ : Λ → Λ'} (n : ℕ)
    {T : KernelTower Ω n} {T' : KernelTower Ω' n}
    {U : KernelTower Λ n} {U' : KernelTower Λ' n}
    (h : Projects π n T T') (g : Projects ρ n U U') :
    Projects (fun z : Ω×Λ => (π z.1,ρ z.2)) n (prod n T U) (prod n T' U') := by
  induction n with
  | zero => trivial
  | succ n ih =>
    refine ⟨?_,fun a => ih (h.2 a.1) (g.2 a.2)⟩
    intro f
    change (T.1.bind (fun _ => U.1)).expect (fun z => f (π z.1,ρ z.2)) =
      (T'.1.bind (fun _ => U'.1)).expect f
    rw [FiniteLaw.expect_bind,FiniteLaw.expect_bind]
    have he : (fun a => U.1.expect (fun b => f (π a,ρ b)))=
        (fun a => U'.1.expect (fun b => f (π a,b))) := by
      funext a
      exact g.1 (fun b => f (π a,b))
    rw [he]
    exact h.1 (fun a => U'.1.expect (fun b => f (a,b)))

lemma pi_prod_projects {ι : Type} [Fintype ι] [DecidableEq ι]
    (n : ℕ) (T : ι → KernelTower Ω n) (U : ι → KernelTower Λ n) (c : ι) :
    Projects (fun z : ι → Ω×Λ => (fun i => (z i).1,(z c).2)) n
      (pi n (fun i => prod n (T i) (U i))) (prod n (pi n T) (U c)) := by
  induction n with
  | zero => trivial
  | succ n ih =>
    refine ⟨?_,fun a => ih (fun i => (T i).2 (a i).1) (fun i => (U i).2 (a i).2)⟩
    intro f
    change (FiniteLaw.pi (fun i => (T i).1.bind (fun _ => (U i).1))).expect
      (fun z => f (fun i => (z i).1,(z c).2)) =
      ((FiniteLaw.pi (fun i => (T i).1)).bind (fun _ => (U c).1)).expect f
    rw [FiniteLaw.expect_pi_bind]
    rw [FiniteLaw.expect_bind]
    apply FiniteLaw.expect_congr
    intro a
    exact FiniteLaw.expect_pi_marginal (fun i => (U i).1) c (fun b => f (a,b))

lemma Projects.pi {ι : Type} [Fintype ι] [DecidableEq ι]
    {π : ι → Ω → Λ} (n : ℕ) {T : ι → KernelTower Ω n} {U : ι → KernelTower Λ n}
    (h : ∀ i,Projects (π i) n (T i) (U i)) :
    Projects (fun x i => π i (x i)) n (pi n T) (pi n U) := by
  induction n with
  | zero => trivial
  | succ n ih => exact ⟨FiniteLaw.Projects.pi (fun i => (h i).1),fun a => ih (fun i => (h i).2 (a i))⟩

omit [Fintype Ω] [Fintype Λ] [Fintype Ω'] in
lemma pathMap_comp (π : Ω → Λ) (ρ : Λ → Ω') (n : ℕ) (y : FinitePath Ω n) :
    pathMap (ρ ∘ π) n y=pathMap ρ n (pathMap π n y) := by
  induction n with
  | zero => rfl
  | succ n ih => exact Prod.ext rfl (ih y.2)

end KernelTower
end DilutedSpinGlass

end

section
namespace DilutedSpinGlass.PrescribedTree
open scoped BigOperators
variable {Ω Λ R ι : Type} [Fintype Ω] [Fintype Λ] [Fintype R]
    [Fintype ι] [DecidableEq ι] {n : ℕ}

lemma prod_pi_sample_expect (S : PrescribedTree n) (T : KernelTower Ω n)
    (U : ι → KernelTower Λ n) (g : (ι → Sample Λ S) → Sample Ω S → ℝ) :
    (S.sampleLaw (KernelTower.prod n T (KernelTower.piTower n U))).expect
      (fun w => g (fun j => sampleMap (fun x : ι → Λ => x j) S (sampleSnd S w))
        (sampleFst S w)) =
    (S.sampleLaw T).expect (fun old =>
      (FiniteLaw.pi (fun j => S.sampleLaw (U j))).expect (fun fresh => g fresh old)) := by
  rw [sampleExpect_prod]
  apply FiniteLaw.expect_congr
  intro old
  rw [sampleExpect_piTower]
  apply FiniteLaw.expect_congr
  intro a
  simp only [sampleFst_pair,sampleSnd_pair,sampleMap_pi]

/-- Each new label is independently sampled, including its root, on the same
prescribed replica tree as the old system. -/
lemma common_sample_expect (S : PrescribedTree n) (T : KernelTower Ω n)
    (Q : FiniteLaw R) (U : R → KernelTower Λ n)
    (g : (ι → R×Sample Λ S) → Sample Ω S → ℝ) :
    (FiniteLaw.pi (fun _ : ι => Q)).expect (fun r =>
      (S.sampleLaw (KernelTower.prod n T (KernelTower.piTower n (fun j : ι => U (r j))))).expect
        (fun w => g (fun j => (r j,sampleMap (fun x : ι → Λ => x j) S (sampleSnd S w)))
          (sampleFst S w))) =
    (S.sampleLaw T).expect (fun old =>
      (FiniteLaw.pi (fun _ : ι => Q.bind (fun r => S.sampleLaw (U r)))).expect
        (fun fresh => g fresh old)) := by
  let H (r : ι → R) (old : Sample Ω S) :=
    (FiniteLaw.pi (fun j : ι => S.sampleLaw (U (r j)))).expect
      (fun a => g (fun j => (r j,a j)) old)
  calc
    _ = (FiniteLaw.pi (fun _ : ι => Q)).expect (fun r => (S.sampleLaw T).expect (H r)) := by
      apply FiniteLaw.expect_congr
      intro r
      exact prod_pi_sample_expect S T (fun j => U (r j))
        (fun a old => g (fun j => (r j,a j)) old)
    _ = (S.sampleLaw T).expect (fun old => (FiniteLaw.pi (fun _ : ι => Q)).expect (fun r => H r old)) :=
      FiniteLaw.expect_comm _ _ _
    _ = _ := by
      apply FiniteLaw.expect_congr
      intro old
      exact (FiniteLaw.expect_pi_bind (fun _ : ι => Q) (fun _ r => S.sampleLaw (U r))
        (fun fresh => g fresh old)).symm

omit [Fintype Ω] in
lemma leafProduct_eq_fin_prod (S : PrescribedTree n) (D : FinitePath Ω n → ℝ)
    (w : Sample Ω S) :
    leafProduct S D w=∏ a : Fin (Fintype.card S.Leaf),D (S.pathAt ((Fintype.equivFin S.Leaf).symm a) w) := by
  rw [leafProduct_eq_prod]
  exact Fintype.prod_equiv (Fintype.equivFin S.Leaf) _ _ (fun a => by simp)

noncomputable def mixedTreeD {p N : ℕ} (z : InteractionSample p) (sel : Fin p → Bool)
    (V : FinitePath Ω n → Fin N → Spin) (x : R → FinitePath Λ n → ℝ)
    (r : Fin p → R) (i : Fin p → Fin N) (w : FinitePath (Ω × (Fin p → Λ)) n) : ℝ :=
  mixedFactor z sel (fun l => V (KernelTower.pathFst n w) (i l))
    (fun l => x (r l) (KernelTower.pathMap (fun a : Fin p → Λ => a l) n (KernelTower.pathSnd n w)))

omit [Fintype Ω] [Fintype Λ] [Fintype R] in
lemma mixedTree_leafProduct {p N : ℕ} (S : PrescribedTree n)
    (z : InteractionSample p) (sel : Fin p → Bool)
    (V : FinitePath Ω n → Fin N → Spin) (x : R → FinitePath Λ n → ℝ)
    (r : Fin p → R) (i : Fin p → Fin N) (w : Sample (Ω × (Fin p → Λ)) S) :
    leafProduct S (fun y => -mixedTreeD z sel V x r i y) w=
      ∏ a : Fin (Fintype.card S.Leaf),-mixedFactor z sel
        (fun l => V (S.pathAt ((Fintype.equivFin S.Leaf).symm a) (sampleFst S w)) (i l))
        (fun l => x (r l) (S.pathAt ((Fintype.equivFin S.Leaf).symm a)
          (sampleMap (fun a : Fin p → Λ => a l) S (sampleSnd S w)))) := by
  rw [leafProduct_eq_fin_prod]
  simp only [mixedTreeD,pathAt_sampleMap,pathAt_sampleFst,pathAt_sampleSnd]

lemma common_tree_sample {p N : ℕ} [NeZero N] (S : PrescribedTree n) (T : KernelTower Ω n)
    (Q : FiniteLaw R) (U : R → KernelTower Λ n)
    (V : FinitePath Ω n → Fin N → Spin) (x : R → FinitePath Λ n → ℝ)
    (z : InteractionSample p) (sel : Fin p → Bool) (i : Fin p → Fin N) :
    (FiniteLaw.pi (fun _ : Fin p => Q)).expect (fun r =>
      (S.sampleLaw (KernelTower.prod n T (KernelTower.piTower n (fun j : Fin p => U (r j))))).expect
        (leafProduct S (fun y => -mixedTreeD z sel V x r i y))) =
    (S.sampleLaw T).expect (fun old =>
      (FiniteLaw.pi (fun _ : Fin p => Q.bind (fun r => S.sampleLaw (U r)))).expect
        (fun fresh => ∏ a : Fin (Fintype.card S.Leaf),-mixedFactor z sel
          (fun l => V (S.pathAt ((Fintype.equivFin S.Leaf).symm a) old) (i l))
          (fun l => x (fresh l).1 (S.pathAt ((Fintype.equivFin S.Leaf).symm a) (fresh l).2)))) := by
  rw [← common_sample_expect]
  apply FiniteLaw.expect_congr
  intro r
  apply FiniteLaw.expect_congr
  intro w
  exact mixedTree_leafProduct S z sel V x r i w

lemma common_tree_point {p N : ℕ} [NeZero N] (S : PrescribedTree n) (T : KernelTower Ω n)
    (Q : FiniteLaw R) (U : R → KernelTower Λ n)
    (V : FinitePath Ω n → Fin N → Spin) (x : R → FinitePath Λ n → ℝ)
    (z : InteractionSample p) (sel : Fin p → Bool) :
    (FiniteLaw.pi (fun _ : Fin p => (FiniteLaw.uniform : FiniteLaw (Fin N)))).expect (fun i =>
      (FiniteLaw.pi (fun _ : Fin p => Q)).expect (fun r =>
        (S.sampleLaw (KernelTower.prod n T (KernelTower.piTower n (fun j : Fin p => U (r j))))).expect
          (leafProduct S (fun y => -mixedTreeD z sel V x r i y)))) =
    (S.sampleLaw T).expect (fun old => insertionPoint z
      (fun i a => V (S.pathAt ((Fintype.equivFin S.Leaf).symm a) old) i)
      (Q.bind (fun r => S.sampleLaw (U r)))
      (fun w a => x w.1 (S.pathAt ((Fintype.equivFin S.Leaf).symm a) w.2)) sel) := by
  let F (i : Fin p → Fin N) (old : Sample Ω S) :=
    (FiniteLaw.pi (fun _ : Fin p => Q.bind (fun r => S.sampleLaw (U r)))).expect
      (fun fresh => ∏ a : Fin (Fintype.card S.Leaf),-mixedFactor z sel
        (fun l => V (S.pathAt ((Fintype.equivFin S.Leaf).symm a) old) (i l))
        (fun l => x (fresh l).1 (S.pathAt ((Fintype.equivFin S.Leaf).symm a) (fresh l).2)))
  calc
    _ = (FiniteLaw.pi (fun _ : Fin p => (FiniteLaw.uniform : FiniteLaw (Fin N)))).expect
        (fun i => (S.sampleLaw T).expect (F i)) := by
      apply FiniteLaw.expect_congr
      intro i
      exact common_tree_sample S T Q U V x z sel i
    _ = (S.sampleLaw T).expect (fun old =>
        (FiniteLaw.pi (fun _ : Fin p => (FiniteLaw.uniform : FiniteLaw (Fin N)))).expect
          (fun i => F i old)) := FiniteLaw.expect_comm _ _ _
    _ = _ := by
      apply FiniteLaw.expect_congr
      intro old
      exact (FiniteLaw.expect_pi_bind
        (fun _ : Fin p => (FiniteLaw.uniform : FiniteLaw (Fin N)))
        (fun _ _ => Q.bind (fun r => S.sampleLaw (U r)))
        (fun w => ∏ a : Fin (Fintype.card S.Leaf),-mixedFactor z sel
          (fun l => V (S.pathAt ((Fintype.equivFin S.Leaf).symm a) old) (w l).1)
          (fun l => x (w l).2.1 (S.pathAt ((Fintype.equivFin S.Leaf).symm a) (w l).2.2)))).symm

end DilutedSpinGlass.PrescribedTree

end

end OAI