File size: 10,036 Bytes
e63eb7f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import OAI.Combinatorics.EditApproximation.Numerics.Numerics
import OAI.Combinatorics.EditApproximation.Definitions


namespace OAI

/-!
# The actual fixed-block action hull

Coordinates are precisely the child/state pairs occurring in a finite band.
Each action assigns its fixed rational child mass to one state per child.
This verifies the probability, coverage and block-mass hypotheses used by
the numerical optimizer and optimistic entropy regret.
-/

namespace EditApproximation

open Finset





theorem action_coordinate_mem {β σ : Type*} [Fintype β] [DecidableEq β] [DecidableEq σ]
    (band : Finset (β → σ)) {action : β → σ} (haction : action ∈ band) (child : β) :
    (child, action child) ∈ bandCoordinates band := by
  apply mem_biUnion.mpr
  exact ⟨action, haction, mem_image.mpr ⟨child, mem_univ _, rfl⟩⟩

theorem actionVector_probability {β σ : Type*} [Fintype β] [Nonempty β]
    [DecidableEq β] [DecidableEq σ] (band : Finset (β → σ))
    (mass : β → ℚ) (hpos : ∀ child, 0 < mass child)
    {action : β → σ} (haction : action ∈ band) :
    (∀ coordinate ∈ bandCoordinates band, (0 : ℝ) ≤ actionVector mass action coordinate) ∧
      (∑ coordinate ∈ bandCoordinates band, (actionVector mass action coordinate : ℝ)) = 1 := by
  have htotal : (0 : ℚ) < ∑ child, mass child := sum_pos (fun child _ => hpos child) univ_nonempty
  constructor
  · intro coordinate _
    unfold actionVector
    split_ifs
    · exact_mod_cast (div_pos (hpos _) htotal).le
    · norm_num
  · have hsubset : (univ.image fun child => (child, action child)) ⊆ bandCoordinates band := by
      intro coordinate hc
      obtain ⟨child, _, rfl⟩ := mem_image.mp hc
      exact action_coordinate_mem band haction child
    have hsum : (∑ coordinate ∈ bandCoordinates band, (actionVector mass action coordinate : ℝ)) =
        ∑ coordinate ∈ univ.image (fun child => (child, action child)),
          (actionVector mass action coordinate : ℝ) := by
      symm
      apply sum_subset hsubset
      intro coordinate _ hnot
      have hne : coordinate.2 ≠ action coordinate.1 := by
        intro heq
        exact hnot (mem_image.mpr ⟨coordinate.1, mem_univ _, Prod.ext rfl heq.symm⟩)
      simp only [actionVector, ite_eq_right hne, Rat.cast_zero]
    rw [hsum, sum_image]
    · simp only [actionVector, ite_true, Rat.cast_div]
      rw [← sum_div]
      have hcast : (∑ child, (mass child : ℝ)) = ((∑ child, mass child : ℚ) : ℝ) := by
        norm_cast
      rw [hcast]
      exact div_self (by exact_mod_cast htotal.ne')
    · intro i _ j _ hij
      exact congrArg Prod.fst hij

theorem actionVector_coordinate_coverage {β σ : Type*} [Fintype β] [Nonempty β]
    [DecidableEq β] [DecidableEq σ] (band : Finset (β → σ))
    (mass : β → ℚ) (hpos : ∀ child, 0 < mass child) :
    ∀ coordinate ∈ bandCoordinates band, ∃ action ∈ band,
      (0 : ℝ) < actionVector mass action coordinate := by
  intro coordinate hcoordinate
  obtain ⟨action, ha, hcoordinate⟩ := mem_biUnion.mp hcoordinate
  obtain ⟨child, _, heq⟩ := mem_image.mp hcoordinate
  subst coordinate
  refine ⟨action, ha, ?_⟩
  simp only [actionVector, ite_true]
  have htotal : (0 : ℚ) < ∑ child, mass child := sum_pos (fun child _ => hpos child) univ_nonempty
  exact_mod_cast div_pos (hpos child) htotal

theorem actionVector_block_mass {β σ : Type*} [Fintype β] [DecidableEq β] [DecidableEq σ]
    (band : Finset (β → σ)) (mass : β → ℚ)
    {action : β → σ} (haction : action ∈ band) (child : β) :
    (∑ coordinate ∈ bandCoordinates band with coordinate.1 = child,
      (actionVector mass action coordinate : ℝ)) =
        (mass child / (∑ i, mass i) : ℚ) := by
  rw [sum_eq_single (child, action child)]
  · simp only [actionVector, ite_true]
  · intro coordinate hc hne
    have hchild : coordinate.1 = child := (mem_filter.mp hc).2
    have hstate : coordinate.2 ≠ action child := by
      intro hstate
      exact hne (Prod.ext hchild hstate)
    simp only [actionVector, hchild, ite_eq_right hstate, Rat.cast_zero]
  · intro hnot
    exact False.elim (hnot (mem_filter.mpr ⟨action_coordinate_mem band haction child, rfl⟩))

theorem actionVector_inner_product {β σ : Type*} [Fintype β]
    [DecidableEq β] [DecidableEq σ] (band : Finset (β → σ))
    (mass : β → ℚ) (gain : β × σ → ℝ)
    {action : β → σ} (haction : action ∈ band) :
    (∑ coordinate ∈ bandCoordinates band, gain coordinate * (actionVector mass action coordinate : ℝ)) =
      ∑ child, gain (child, action child) * (mass child / (∑ i, mass i) : ℚ) := by
  have hsubset : (univ.image fun child => (child, action child)) ⊆ bandCoordinates band := by
    intro coordinate hc
    obtain ⟨child, _, rfl⟩ := mem_image.mp hc
    exact action_coordinate_mem band haction child
  have hsum : (∑ coordinate ∈ bandCoordinates band,
      gain coordinate * (actionVector mass action coordinate : ℝ)) =
        ∑ coordinate ∈ univ.image (fun child => (child, action child)),
          gain coordinate * (actionVector mass action coordinate : ℝ) := by
    symm
    apply sum_subset hsubset
    intro coordinate _ hnot
    have hne : coordinate.2 ≠ action coordinate.1 := by
      intro heq
      exact hnot (mem_image.mpr ⟨coordinate.1, mem_univ _, Prod.ext rfl heq.symm⟩)
    simp only [actionVector, ite_eq_right hne, Rat.cast_zero, mul_zero]
  rw [hsum, sum_image]
  · simp only [actionVector, ite_true]
  · intro i _ j _ hij
    exact congrArg Prod.fst hij

/-- The coordinate normalization translates entropy gains exactly into
the unnormalized costs of a band action. -/
theorem actionVector_cost_identity {β σ : Type*} [Fintype β] [Nonempty β]
    [DecidableEq β] [DecidableEq σ] (band : Finset (β → σ))
    (mass : β → ℚ) (hpos : ∀ child, 0 < mass child) (cost : β × σ → ℝ)
    {action : β → σ} (haction : action ∈ band) :
    -((∑ child, mass child : ℚ) : ℝ) *
      (∑ coordinate ∈ bandCoordinates band,
        (-cost coordinate / (mass coordinate.1 : ℝ)) * (actionVector mass action coordinate : ℝ)) =
          ∑ child, cost (child, action child) := by
  rw [actionVector_inner_product band mass _ haction, mul_sum]
  apply sum_congr rfl
  intro child _
  have hmass : (mass child : ℝ) ≠ 0 := by exact_mod_cast (hpos child).ne'
  have htotal : ((∑ child, mass child : ℚ) : ℝ) ≠ 0 := by
    exact_mod_cast (sum_pos (fun child _ => hpos child) univ_nonempty).ne'
  rw [Rat.cast_div]
  field_simp

theorem band_block_nonempty {β σ : Type*} [Fintype β] [DecidableEq β] [DecidableEq σ]
    (band : Finset (β → σ)) (hband : band.Nonempty) (child : β) :
    ((bandCoordinates band).filter fun coordinate => coordinate.1 = child).Nonempty := by
  obtain ⟨action, ha⟩ := hband
  exact ⟨(child, action child), mem_filter.mpr ⟨action_coordinate_mem band ha child, rfl⟩⟩

theorem band_hull_block_mass {β σ : Type*} [Fintype β] [DecidableEq β] [DecidableEq σ]
    (band : Finset (β → σ)) (mass : β → ℚ) (child : β)
    (p : β × σ → ℝ)
    (hp : p ∈ convexHull ℝ (rationalVertexSet (band.toList.map (actionVector mass)))) :
    (∑ coordinate ∈ bandCoordinates band with coordinate.1 = child, p coordinate) =
      (mass child / (∑ i, mass i) : ℚ) := by
  let targetMass : ℝ := (mass child / (∑ i, mass i) : ℚ)
  have hconvex : Convex ℝ {q : β × σ → ℝ |
      (∑ coordinate ∈ bandCoordinates band with coordinate.1 = child, q coordinate) =
        targetMass} := by
    intro x hx y hy a b _ _ hab
    change (∑ coordinate ∈ bandCoordinates band with coordinate.1 = child,
      (a * x coordinate + b * y coordinate)) = targetMass
    rw [sum_add_distrib, ← mul_sum, ← mul_sum, hx, hy]
    calc
      a * targetMass + b * targetMass = (a + b) * targetMass := by ring
      _ = targetMass := by rw [hab, one_mul]
  have hsubset : rationalVertexSet (band.toList.map (actionVector mass)) ⊆
      {q : β × σ → ℝ |
        (∑ coordinate ∈ bandCoordinates band with coordinate.1 = child, q coordinate) =
          targetMass} := by
    rintro _ ⟨vertex, hv, rfl⟩
    obtain ⟨action, ha, rfl⟩ := List.mem_map.mp hv
    exact actionVector_block_mass band mass (mem_toList.mp ha) child
  exact convexHull_min hsubset hconvex hp

theorem band_entropy_optimizer {β σ : Type*} [Fintype β] [Nonempty β]
    [DecidableEq β] [DecidableEq σ] (band : Finset (β → σ)) (hband : band.Nonempty)
    (mass : β → ℚ) (hpos : ∀ child, 0 < mass child)
    (linear : β × σ → ℚ) (H : ℕ) (hH : 4 ≤ H) :
    let coordinates := bandCoordinates band
    let vertices := band.toList.map (actionVector mass)
    ∃ maximizer ∈ convexHull ℝ (rationalVertexSet vertices),
      IsMaxOn (entropyValue coordinates 1 (fun i => (linear i : ℝ)))
        (convexHull ℝ (rationalVertexSet vertices)) maximizer ∧
      (∑ i ∈ coordinates, |(finiteRationalOptimizer coordinates vertices linear
        (H + coordinates.card + 2) ((H + coordinates.card + 2) ^ 80) i : ℝ) - maximizer i|) ≤
          1 / (H : ℝ) ^ 3 := by
  dsimp only
  have hvertices : band.toList.map (actionVector mass) ≠ [] := by
    obtain ⟨action, ha⟩ := hband
    intro hnil
    have hmem : actionVector mass action ∈ band.toList.map (actionVector mass) :=
      List.mem_map.mpr ⟨action, mem_toList.mpr ha, rfl⟩
    simp only [hnil, List.not_mem_nil] at hmem
  apply finite_entropy_optimizer _ _ _ _ hvertices hH
  · intro p hp
    obtain ⟨action, ha, rfl⟩ := List.mem_map.mp hp
    exact actionVector_probability band mass hpos (mem_toList.mp ha)
  · intro coordinate hc
    obtain ⟨action, ha, hpositive⟩ := actionVector_coordinate_coverage band mass hpos coordinate hc
    exact ⟨actionVector mass action, List.mem_map.mpr ⟨action, mem_toList.mpr ha, rfl⟩, hpositive⟩

end EditApproximation

end OAI