File size: 9,117 Bytes
e320e82 | 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 | import OAI.Combinatorics.GraphThreshold.Basic
import Mathlib.Algebra.BigOperators.Field
import Mathlib.Algebra.Order.BigOperators.Group.Finset
import Mathlib.Data.Fintype.BigOperators
namespace OAI
noncomputable section
open scoped BigOperators
namespace LeanBlast.SecondKahnKalai
variable {X B : Type*} [DecidableEq X] [Fintype B]
def resamplingY (A : B → Finset X) (W : Finset X) (c : B) : Finset X := W ∪ A c
def resamplingNumerator (ν : FiniteLaw B) (A : B → Finset X) (ρ : ℝ)
(Y : Finset X) (b : B) : ℝ :=
if A b ⊆ Y then ν.weight b * (ρ⁻¹) ^ (A b).card else 0
/-- The actual normalizing density `Z(Y)`. -/
def resamplingZ (ν : FiniteLaw B) (A : B → Finset X) (ρ : ℝ)
(Y : Finset X) : ℝ :=
∑ b, resamplingNumerator ν A ρ Y b
def resamplingTargetWeight (ν : FiniteLaw B) (A : B → Finset X) (ρ : ℝ)
(W : Finset X) (c b : B) : ℝ :=
resamplingNumerator ν A ρ (resamplingY A W c) b /
resamplingZ ν A ρ (resamplingY A W c)
def resamplingWeight (ν : FiniteLaw B) (A : B → Finset X) (ρ : ℝ)
(W : Finset X) (cb : B × B) : ℝ :=
ν.weight cb.1 * resamplingTargetWeight ν A ρ W cb.1 cb.2
/-- The retained target fragment; no quotienting of the label indices occurs. -/
def resamplingFragment (A : B → Finset X) (W : Finset X) (b : B) : Finset X :=
A b \ W
theorem resamplingNumerator_nonneg (ν : FiniteLaw B) (A : B → Finset X)
{ρ : ℝ} (hρ : 0 ≤ ρ) (Y : Finset X) (b : B) :
0 ≤ resamplingNumerator ν A ρ Y b := by
unfold resamplingNumerator
split_ifs
· exact mul_nonneg (ν.nonneg b) (pow_nonneg (inv_nonneg.mpr hρ) _)
· exact le_rfl
theorem resamplingZ_nonneg (ν : FiniteLaw B) (A : B → Finset X)
{ρ : ℝ} (hρ : 0 ≤ ρ) (Y : Finset X) : 0 ≤ resamplingZ ν A ρ Y := by
exact Finset.sum_nonneg fun b _ => resamplingNumerator_nonneg ν A hρ Y b
theorem resamplingZ_pos (ν : FiniteLaw B) (A : B → Finset X)
{ρ : ℝ} (hν : ν.IsPositive) (hρ : 0 < ρ) (W : Finset X) (c : B) :
0 < resamplingZ ν A ρ (resamplingY A W c) := by
classical
have hc : 0 < resamplingNumerator ν A ρ (resamplingY A W c) c := by
rw [resamplingNumerator, resamplingY, ite_eq_left Finset.subset_union_right]
exact mul_pos (hν c) (pow_pos (inv_pos.mpr hρ) _)
exact lt_of_lt_of_le hc (Finset.single_le_sum
(fun b _ => resamplingNumerator_nonneg ν A hρ.le (resamplingY A W c) b)
(Finset.mem_univ c))
theorem resamplingTargetWeight_nonneg (ν : FiniteLaw B) (A : B → Finset X)
{ρ : ℝ} (hρ : 0 ≤ ρ) (W : Finset X) (c b : B) :
0 ≤ resamplingTargetWeight ν A ρ W c b :=
div_nonneg (resamplingNumerator_nonneg ν A hρ _ _)
(resamplingZ_nonneg ν A hρ _)
theorem resamplingWeight_nonneg (ν : FiniteLaw B) (A : B → Finset X)
{ρ : ℝ} (hρ : 0 ≤ ρ) (W : Finset X) (cb : B × B) :
0 ≤ resamplingWeight ν A ρ W cb :=
mul_nonneg (ν.nonneg _) (resamplingTargetWeight_nonneg ν A hρ W _ _)
theorem resamplingTargetWeight_total (ν : FiniteLaw B) (A : B → Finset X)
{ρ : ℝ} (hν : ν.IsPositive) (hρ : 0 < ρ) (W : Finset X) (c : B) :
(∑ b, resamplingTargetWeight ν A ρ W c b) = 1 := by
simp only [resamplingTargetWeight, ← Finset.sum_div]
exact div_self (resamplingZ_pos ν A hν hρ W c).ne'
theorem resampling_source_marginal (ν : FiniteLaw B) (A : B → Finset X)
{ρ : ℝ} (hν : ν.IsPositive) (hρ : 0 < ρ) (W : Finset X) (c : B) :
(∑ b, resamplingWeight ν A ρ W (c, b)) = ν.weight c := by
simp only [resamplingWeight, ← Finset.mul_sum,
resamplingTargetWeight_total ν A hν hρ W c, mul_one]
theorem resamplingWeight_total (ν : FiniteLaw B) (A : B → Finset X)
{ρ : ℝ} (hν : ν.IsPositive) (hρ : 0 < ρ) (W : Finset X) :
(∑ cb : B × B, resamplingWeight ν A ρ W cb) = 1 := by
rw [Fintype.sum_prod_type]
simp only [resampling_source_marginal ν A hν hρ W]
exact ν.total
def resamplingTargetLaw (ν : FiniteLaw B) (A : B → Finset X) (ρ : ℝ)
(W : Finset X) (c : B) (hν : ν.IsPositive) (hρ : 0 < ρ) : FiniteLaw B where
weight := resamplingTargetWeight ν A ρ W c
nonneg := resamplingTargetWeight_nonneg ν A hρ.le W c
total := resamplingTargetWeight_total ν A hν hρ W c
def resamplingLaw (ν : FiniteLaw B) (A : B → Finset X) (ρ : ℝ)
(W : Finset X) (hν : ν.IsPositive) (hρ : 0 < ρ) : FiniteLaw (B × B) where
weight := resamplingWeight ν A ρ W
nonneg := resamplingWeight_nonneg ν A hρ.le W
total := resamplingWeight_total ν A hν hρ W
@[simp] theorem resamplingLaw_weight (ν : FiniteLaw B) (A : B → Finset X) (ρ : ℝ)
(W : Finset X) (hν : ν.IsPositive) (hρ : 0 < ρ) (cb : B × B) :
(resamplingLaw ν A ρ W hν hρ).weight cb = resamplingWeight ν A ρ W cb := rfl
theorem resampling_expectation_source (ν : FiniteLaw B) (A : B → Finset X)
{ρ : ℝ} (hν : ν.IsPositive) (hρ : 0 < ρ) (W : Finset X) (f : B → ℝ) :
(resamplingLaw ν A ρ W hν hρ).expectation (fun cb => f cb.1) = ν.expectation f := by
simp only [FiniteLaw.expectation, resamplingLaw_weight, Fintype.sum_prod_type]
apply Finset.sum_congr rfl
intro c _
rw [← Finset.sum_mul, resampling_source_marginal ν A hν hρ W c]
theorem resampling_prob_source (ν : FiniteLaw B) (A : B → Finset X)
{ρ : ℝ} (hν : ν.IsPositive) (hρ : 0 < ρ) (W : Finset X) (P : B → Prop) :
(resamplingLaw ν A ρ W hν hρ).prob (fun cb => P cb.1) = ν.prob P := by
classical
simp only [FiniteLaw.prob, Fintype.sum_prod_type]
apply Finset.sum_congr rfl
intro c _
by_cases hc : P c
· simp only [ite_eq_left hc, resamplingLaw_weight, resampling_source_marginal ν A hν hρ W c]
· simp only [ite_eq_right hc, Finset.sum_const_zero]
theorem resamplingWeight_eq_zero_of_not_subset (ν : FiniteLaw B) (A : B → Finset X)
(ρ : ℝ) (W : Finset X) (c b : B) (hb : ¬A b ⊆ resamplingY A W c) :
resamplingWeight ν A ρ W (c, b) = 0 := by
simp [resamplingWeight, resamplingTargetWeight, resamplingNumerator, hb]
theorem resampling_target_subset_of_pos (ν : FiniteLaw B) (A : B → Finset X)
(ρ : ℝ) (W : Finset X) (c b : B)
(hcb : 0 < resamplingWeight ν A ρ W (c, b)) : A b ⊆ resamplingY A W c := by
by_contra hb
rw [resamplingWeight_eq_zero_of_not_subset ν A ρ W c b hb] at hcb
exact (lt_irrefl 0) hcb
omit [Fintype B] in
theorem resamplingFragment_subset_target (A : B → Finset X) (W : Finset X) (b : B) :
resamplingFragment A W b ⊆ A b := Finset.sdiff_subset
theorem resamplingFragment_subset_source (ν : FiniteLaw B) (A : B → Finset X)
(ρ : ℝ) (W : Finset X) (c b : B)
(hcb : 0 < resamplingWeight ν A ρ W (c, b)) :
resamplingFragment A W b ⊆ A c := by
intro x hx
have hx' := Finset.mem_sdiff.mp hx
rcases Finset.mem_union.mp (resampling_target_subset_of_pos ν A ρ W c b hcb hx'.1) with hW | hc
· exact (hx'.2 hW).elim
· exact hc
theorem resamplingFragment_subset_inter (ν : FiniteLaw B) (A : B → Finset X)
(ρ : ℝ) (W : Finset X) (c b : B)
(hcb : 0 < resamplingWeight ν A ρ W (c, b)) :
resamplingFragment A W b ⊆ A c ∩ A b :=
Finset.subset_inter (resamplingFragment_subset_source ν A ρ W c b hcb)
(resamplingFragment_subset_target A W b)
omit [Fintype B] in
/-- Every target label is recovered by adjoining its retained fragment to W. -/
theorem resamplingFragment_recovery (A : B → Finset X) (W : Finset X) (b : B) :
A b ⊆ W ∪ resamplingFragment A W b := by
intro x hx
by_cases hW : x ∈ W
· exact Finset.mem_union.mpr (Or.inl hW)
· exact Finset.mem_union.mpr (Or.inr (Finset.mem_sdiff.mpr ⟨hx, hW⟩))
omit [Fintype B] in
theorem resampling_target_subset_iff_fragment (A : B → Finset X)
(W : Finset X) (c b : B) :
A b ⊆ resamplingY A W c ↔ resamplingFragment A W b ⊆ A c := by
constructor
· intro h x hx
have hx' := Finset.mem_sdiff.mp hx
rcases Finset.mem_union.mp (h hx'.1) with hW | hc
· exact (hx'.2 hW).elim
· exact hc
· intro h x hx
by_cases hW : x ∈ W
· exact Finset.mem_union.mpr (Or.inl hW)
· exact Finset.mem_union.mpr (Or.inr (h (Finset.mem_sdiff.mpr ⟨hx, hW⟩)))
/-- The transition depends on W only through its intersections with the
labels, expressed equivalently by their retained fragments. -/
theorem resamplingWeight_congr_fragments (ν : FiniteLaw B) (A : B → Finset X)
(ρ : ℝ) {W W' : Finset X}
(hW : ∀ b, resamplingFragment A W b = resamplingFragment A W' b) (cb : B × B) :
resamplingWeight ν A ρ W cb = resamplingWeight ν A ρ W' cb := by
have hsub (c b : B) : A b ⊆ resamplingY A W c ↔ A b ⊆ resamplingY A W' c := by
rw [resampling_target_subset_iff_fragment, resampling_target_subset_iff_fragment, hW]
have hn (c b : B) :
resamplingNumerator ν A ρ (resamplingY A W c) b =
resamplingNumerator ν A ρ (resamplingY A W' c) b := by
simp only [resamplingNumerator, hsub]
simp only [resamplingWeight, resamplingTargetWeight, resamplingZ, hn]
end LeanBlast.SecondKahnKalai
end
end OAI
|