File size: 4,760 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 | import Mathlib
import OAI.Computability.VertexCover.Analysis.BatchGradientForm
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
def affineSign (b : Bool) : ℝ := if b then 1 else -1
@[simp] theorem affineSign_true : affineSign true = 1 := rfl
@[simp] theorem affineSign_false : affineSign false = -1 := rfl
theorem norm_select_affine (Φ : LabelCover) {d : ℕ} (x : Φ.Coordinate d → ℝ) :
∃ I, Φ.Compatible I ∧ ∃ e : Bool,
Φ.compatibilityNorm x = affineSign e * Φ.selectionForm I x := by
obtain ⟨I, hI, heq⟩ := (Φ.compatibleSelections d).exists_mem_eq_sup'
(Φ.compatibleSelections_nonempty d) (fun I => |∑ p ∈ I, x p|)
change Φ.compatibilityNorm x = |∑ p ∈ I, x p| at heq
rw [← Φ.selectionForm_apply] at heq
refine ⟨I, (Φ.mem_compatibleSelections I).mp hI, ?_⟩
by_cases h : 0 ≤ Φ.selectionForm I x
· refine ⟨true, ?_⟩
simpa only [affineSign_true, one_mul, ← Φ.selectionForm_apply, abs_of_nonneg h] using heq
· refine ⟨false, ?_⟩
simpa only [affineSign_false, neg_one_mul, ← Φ.selectionForm_apply,
abs_of_neg (lt_of_not_ge h)] using heq
abbrev AffineIndex (Φ : LabelCover) {d : ℕ} (A : Finset (Φ.Coordinate d → ℝ)) :=
A × (Φ.compatibleSelections d) × Bool × Bool
noncomputable def affineSlope (Φ : LabelCover) {d : ℕ} (seed : Φ.Seeds d)
(J : Finset (Fin d)) {A : Finset (Φ.Coordinate d → ℝ)}
(i : Φ.AffineIndex A) : Φ.BatchWeights J →L[ℝ] ℝ :=
affineSign i.2.2.2 • (Φ.selectionForm i.2.1.val).comp (Φ.batchSumCLM seed J)
noncomputable def affineOffset (Φ : LabelCover) {d : ℕ}
(c0 : Φ.Coordinate d → ℝ) {A : Finset (Φ.Coordinate d → ℝ)}
(i : Φ.AffineIndex A) : ℝ :=
affineSign i.2.2.2 * Φ.selectionForm i.2.1.val (c0 - affineSign i.2.2.1 • i.1.val)
theorem affine_value (Φ : LabelCover) {d : ℕ} (seed : Φ.Seeds d)
(J : Finset (Fin d)) (c0 : Φ.Coordinate d → ℝ)
{A : Finset (Φ.Coordinate d → ℝ)} (i : Φ.AffineIndex A) (s : Φ.BatchWeights J) :
Φ.affineSlope seed J i s + Φ.affineOffset c0 i =
affineSign i.2.2.2 * Φ.selectionForm i.2.1.val
(c0 + Φ.batchSum seed J s - affineSign i.2.2.1 • i.1.val) := by
simp only [affineSlope, affineOffset, smul_apply,
ContinuousLinearMap.comp_apply, Φ.batchSumCLM_apply, smul_eq_mul, map_sub, map_add]
ring
theorem distance_plus_select (Φ : LabelCover) {d : ℕ} (seed : Φ.Seeds d)
(J : Finset (Fin d)) (c0 : Φ.Coordinate d → ℝ)
(A : Finset (Φ.Coordinate d → ℝ)) (hA : A.Nonempty) (s : Φ.BatchWeights J) :
∃ i : Φ.AffineIndex A, Φ.distanceTo A hA (c0 + Φ.batchSum seed J s) =
Φ.affineSlope seed J i s + Φ.affineOffset c0 i := by
classical
obtain ⟨z, hz, heq⟩ := A.exists_mem_eq_inf' hA
(fun z => Φ.compatibilityNorm (c0 + Φ.batchSum seed J s - z))
obtain ⟨I, hI, e, hnorm⟩ := Φ.norm_select_affine (c0 + Φ.batchSum seed J s - z)
let i : Φ.AffineIndex A := (⟨z,hz⟩, ⟨I,(Φ.mem_compatibleSelections I).mpr hI⟩, true,e)
change Φ.distanceTo A hA (c0 + Φ.batchSum seed J s) = _ at heq
refine ⟨i, ?_⟩
rw [Φ.affine_value]
simpa only [i, affineSign_true, one_smul] using heq.trans hnorm
theorem distance_minus_select (Φ : LabelCover) {d : ℕ} (seed : Φ.Seeds d)
(J : Finset (Fin d)) (c0 : Φ.Coordinate d → ℝ)
(A : Finset (Φ.Coordinate d → ℝ)) (hA : A.Nonempty) (s : Φ.BatchWeights J) :
∃ i : Φ.AffineIndex A, Φ.distanceTo A hA (-(c0 + Φ.batchSum seed J s)) =
Φ.affineSlope seed J i s + Φ.affineOffset c0 i := by
classical
obtain ⟨z, hz, heq⟩ := A.exists_mem_eq_inf' hA
(fun z => Φ.compatibilityNorm (-(c0 + Φ.batchSum seed J s)-z))
have heq' : Φ.distanceTo A hA (-(c0 + Φ.batchSum seed J s)) =
Φ.compatibilityNorm (c0 + Φ.batchSum seed J s + z) := by
change _ = _ at heq
rw [show -(c0 + Φ.batchSum seed J s)-z =
-(c0 + Φ.batchSum seed J s + z) by abel, Φ.norm_neg] at heq
exact heq
obtain ⟨I, hI, e, hnorm⟩ := Φ.norm_select_affine (c0 + Φ.batchSum seed J s + z)
let i : Φ.AffineIndex A := (⟨z,hz⟩, ⟨I,(Φ.mem_compatibleSelections I).mpr hI⟩, false,e)
refine ⟨i, ?_⟩
rw [Φ.affine_value]
simpa only [i, affineSign_false, neg_one_smul, sub_neg_eq_add] using heq'.trans hnorm
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
|