File size: 6,505 Bytes
92416a2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import Mathlib
import OAI.Computability.VertexCover.Analysis.ZeroMemIncidenceHull
import OAI.Computability.VertexCover.Analysis.DistanceMinusSelect
import OAI.Computability.VertexCover.Analysis.AeRegular

namespace OAI

section
section
section
section
section
section
section
section
section
section
section
section
section
section
section
section
section
section
section
section
section
section
section
section
section
section
section
section
section
section
section
section
namespace VertexCover.LabelCover
open MeasureTheory

theorem separator_continuous (Φ : LabelCover) {d : ℕ}
    (A : Finset (Φ.Coordinate d → ℝ)) (hA : A.Nonempty) :
    Continuous (Φ.separator A hA) :=
  ((Φ.distanceTo_continuous A hA).comp continuous_neg |>.sub
    (Φ.distanceTo_continuous A hA)).div_const 2

noncomputable def batchFunction (Φ : LabelCover) {d : ℕ} (seed : Φ.Seeds d)
    (J : Finset (Fin d)) (c0 : Φ.Coordinate d → ℝ)
    (A : Finset (Φ.Coordinate d → ℝ)) (hA : A.Nonempty) (s : Φ.BatchWeights J) : ℝ :=
  Φ.separator A hA (c0 + Φ.batchSum seed J s)

theorem batchFunction_continuous (Φ : LabelCover) {d : ℕ} (seed : Φ.Seeds d)
    (J : Finset (Fin d)) (c0 : Φ.Coordinate d → ℝ)
    (A : Finset (Φ.Coordinate d → ℝ)) (hA : A.Nonempty) :
    Continuous (Φ.batchFunction seed J c0 A hA) :=
  (Φ.separator_continuous A hA).comp
    (continuous_const.add (Φ.batchSumCLM seed J).continuous)

theorem batchFunction_hasFDerivAt (Φ : LabelCover) {d : ℕ} (seed : Φ.Seeds d)
    (J : Finset (Fin d)) (c0 : Φ.Coordinate d → ℝ)
    (A : Finset (Φ.Coordinate d → ℝ)) (hA : A.Nonempty) (s : Φ.BatchWeights J)
    (hs : VertexCover.AffineSelector.Regular (Φ.affineSlope seed J)
      (Φ.affineOffset c0 (A := A)) s) :
    ∃ im ip : Φ.AffineIndex A, HasFDerivAt (Φ.batchFunction seed J c0 A hA)
      ((1/2 : ℝ) • (Φ.affineSlope seed J im - Φ.affineSlope seed J ip)) s := by
  have hc : Continuous (fun s : Φ.BatchWeights J => c0 + Φ.batchSum seed J s) :=
    continuous_const.add (Φ.batchSumCLM seed J).continuous
  obtain ⟨ip, hp⟩ := VertexCover.AffineSelector.hasFDerivAt _ _
    ((Φ.distanceTo_continuous A hA).comp hc)
    (Φ.distance_plus_select seed J c0 A hA) hs
  obtain ⟨im, hm⟩ := VertexCover.AffineSelector.hasFDerivAt _ _
    ((Φ.distanceTo_continuous A hA).comp hc.neg)
    (Φ.distance_minus_select seed J c0 A hA) hs
  refine ⟨im, ip, ?_⟩
  have heq : Φ.batchFunction seed J c0 A hA = (fun y => (1/2 : ℝ) *
      (Φ.distanceTo A hA (-(c0 + Φ.batchSum seed J y)) -
        Φ.distanceTo A hA (c0 + Φ.batchSum seed J y))) := by
    funext y
    unfold batchFunction separator
    ring
  rw [heq]
  exact (hm.sub hp).const_mul (1/2 : ℝ)

def BatchGradientValid (Φ : LabelCover) {d : ℕ} (seed : Φ.Seeds d)
    (J : Finset (Fin d)) (g : Φ.BatchWeights J) : Prop :=
  ∃ G ∈ Φ.incidenceHull seed, ∀ (j : J) k, g j k = G j k

theorem signed_incidence_mem (Φ : LabelCover) {d : ℕ} (seed : Φ.Seeds d)
    {I : Finset (Φ.Coordinate d)} (hI : Φ.Compatible I) (e : Bool) :
    affineSign e • Φ.incidence seed I ∈ Φ.incidenceHull seed := by
  apply subset_convexHull ℝ
  cases e
  · exact ⟨I, hI, Or.inr (by simp)⟩
  · exact ⟨I, hI, Or.inl (by simp)⟩

theorem neg_signed_incidence_mem (Φ : LabelCover) {d : ℕ} (seed : Φ.Seeds d)
    {I : Finset (Φ.Coordinate d)} (hI : Φ.Compatible I) (e : Bool) :
    -(affineSign e • Φ.incidence seed I) ∈ Φ.incidenceHull seed := by
  apply subset_convexHull ℝ
  cases e
  · exact ⟨I, hI, Or.inl (by simp)⟩
  · exact ⟨I, hI, Or.inr (by simp)⟩

theorem batchGradient_affineSlope (Φ : LabelCover) {d : ℕ} (seed : Φ.Seeds d)
    (J : Finset (Fin d)) {A : Finset (Φ.Coordinate d → ℝ)}
    (i : Φ.AffineIndex A) (j : J) (k : Fin (Φ.WeightDimension d)) :
    Φ.batchGradient J (Φ.affineSlope seed J i) j k =
      affineSign i.2.2.2 * Φ.incidence seed i.2.1.val j k := by
  change affineSign i.2.2.2 *
    Φ.batchGradient J ((Φ.selectionForm i.2.1.val).comp (Φ.batchSumCLM seed J)) j k = _
  rw [Φ.batchGradient_form seed J ((Φ.mem_compatibleSelections _).mp i.2.1.property)]

theorem batchGradient_half_difference_valid (Φ : LabelCover) {d : ℕ}
    (seed : Φ.Seeds d) (J : Finset (Fin d)) {A : Finset (Φ.Coordinate d → ℝ)}
    (im ip : Φ.AffineIndex A) :
    Φ.BatchGradientValid seed J (Φ.batchGradient J
      ((1/2 : ℝ) • (Φ.affineSlope seed J im - Φ.affineSlope seed J ip))) := by
  let gm := affineSign im.2.2.2 • Φ.incidence seed im.2.1.val
  let gp := -(affineSign ip.2.2.2 • Φ.incidence seed ip.2.1.val)
  have hm := Φ.signed_incidence_mem seed
    ((Φ.mem_compatibleSelections _).mp im.2.1.property) im.2.2.2
  have hp := Φ.neg_signed_incidence_mem seed
    ((Φ.mem_compatibleSelections _).mp ip.2.1.property) ip.2.2.2
  refine ⟨(1/2 : ℝ) • gm + (1/2 : ℝ) • gp,
    (convex_convexHull ℝ _) hm hp (by norm_num) (by norm_num) (by norm_num), ?_⟩
  intro j k
  change (1/2 : ℝ) * (Φ.batchGradient J (Φ.affineSlope seed J im) j k -
    Φ.batchGradient J (Φ.affineSlope seed J ip) j k) = _
  rw [Φ.batchGradient_affineSlope, Φ.batchGradient_affineSlope]
  simp only [gm, gp, Pi.add_apply, Pi.smul_apply, Pi.neg_apply, smul_eq_mul]
  ring

noncomputable def canonicalGradient (Φ : LabelCover) {d : ℕ} (seed : Φ.Seeds d)
    (J : Finset (Fin d)) (c0 : Φ.Coordinate d → ℝ)
    (A : Finset (Φ.Coordinate d → ℝ)) (hA : A.Nonempty) (s : Φ.BatchWeights J) :
    Φ.BatchWeights J := by
  classical
  exact if VertexCover.AffineSelector.Regular (Φ.affineSlope seed J)
    (Φ.affineOffset c0 (A := A)) s then
      Φ.batchGradient J (fderiv ℝ (Φ.batchFunction seed J c0 A hA) s) else 0

theorem canonicalGradient_valid (Φ : LabelCover) {d : ℕ} (seed : Φ.Seeds d)
    (J : Finset (Fin d)) (c0 : Φ.Coordinate d → ℝ)
    (A : Finset (Φ.Coordinate d → ℝ)) (hA : A.Nonempty) (s : Φ.BatchWeights J) :
    Φ.BatchGradientValid seed J (Φ.canonicalGradient seed J c0 A hA s) := by
  classical
  unfold canonicalGradient
  split_ifs with hs
  · obtain ⟨im, ip, hder⟩ := Φ.batchFunction_hasFDerivAt seed J c0 A hA s hs
    rw [hder.fderiv]
    exact Φ.batchGradient_half_difference_valid seed J im ip
  · exact ⟨0, Φ.zero_mem_incidenceHull seed, fun _ _ => rfl⟩

end VertexCover.LabelCover


end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end

end OAI