File size: 6,233 Bytes
e5a97c6 | 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 | import OAI.Combinatorics.PerfectMatching.SeparableLower
namespace OAI
universe u_1 u_2
section
noncomputable section
open scoped BigOperators
namespace MatchingEntropy
theorem entropy_le_subprob_crossEntropy {I : Type*} [Fintype I] {p q : I → ℝ}
(hp : ∀ i, 0 ≤ p i) (hpsum : ∑ i, p i ≤ 1) (hq : q ∈ probabilitySimplex I)
(hsupp : ∀ i, p i=0 → q i=0) :
entropy q ≤ -∑ i, q i*Real.log (p i) := by
have hterm : ∀ i, Real.negMulLog (q i) ≤ -(q i*Real.log (p i))+p i-q i := by
intro i
by_cases hi : p i=0
· simp [hi,hsupp i hi]
· simpa only [neg_mul] using negMulLog_tangent (hq.1 i)
(lt_of_le_of_ne (hp i) (Ne.symm hi))
have hh := Finset.sum_le_sum (s := Finset.univ) fun i _ => hterm i
simp only [Finset.sum_sub_distrib,Finset.sum_add_distrib,Finset.sum_neg_distrib,hq.2] at hh
change entropy q ≤ -(∑ i, q i*Real.log (p i))+(∑ i,p i)-1 at hh
linarith
variable {V : Type u_1} {E : Type u_2} [Fintype V] [Fintype E] [DecidableEq V] [DecidableEq E]
namespace LooplessGraph
def matchingBits (G : LooplessGraph V E) (M : G.Matching) : E → Bool :=
fun e => decide (e ∈ M.val)
omit [Fintype V] [Fintype E] [DecidableEq V] in
theorem matchingBits_injective (G : LooplessGraph V E) : Function.Injective G.matchingBits := by
intro M N h
apply Subtype.ext
ext e
have he := congrFun h e
simpa only [matchingBits,decide_eq_decide] using he
end LooplessGraph
def productBoolean (x : E → ℝ) (b : E → Bool) : ℝ :=
∏ e, if b e then x e else 1-x e
omit [Fintype V] [DecidableEq V] [DecidableEq E] in
theorem productBoolean_nonneg {x : E → ℝ} (hx : ∀ e, x e ∈ Set.Icc (0:ℝ) 1)
(b : E → Bool) : 0 ≤ productBoolean x b := by
apply Finset.prod_nonneg
intro e _
split
· exact (hx e).1
· exact sub_nonneg.mpr (hx e).2
omit [Fintype V] [DecidableEq V] in
theorem productBoolean_sum (x : E → ℝ) : (∑ b : E → Bool, productBoolean x b)=1 := by
unfold productBoolean
rw [← Fintype.prod_sum (fun e (b : Bool) => if b then x e else 1-x e)]
simp
omit [Fintype V] [DecidableEq V] in
theorem matchingBoolean_sum_le (G : LooplessGraph V E) {x : E → ℝ}
(hx : ∀ e, x e ∈ Set.Icc (0:ℝ) 1) :
(∑ M, productBoolean x (G.matchingBits M)) ≤ 1 := by
rw [← productBoolean_sum x]
classical
calc
_ = ∑ b ∈ Finset.univ.image G.matchingBits, productBoolean x b := by
rw [Finset.sum_image]
intro M _ N _ h
exact G.matchingBits_injective h
_ ≤ _ := Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _)
(fun b _ _ => productBoolean_nonneg hx b)
omit [Fintype V] [DecidableEq V] in
theorem matching_boolean_factor_pos (G : LooplessGraph V E) {x : E → ℝ}
{p : G.Matching → ℝ} (hp : p ∈ G.feasibleLaws x) {M : G.Matching} (hM : 0<p M) (e : E) :
0<(if G.matchingBits M e then x e else 1-x e) := by
unfold LooplessGraph.matchingBits
by_cases he : e ∈ M.val
· simp only [he,decide_true,ite_true]
have hh := Finset.single_le_sum (f := fun N => p N*G.indicator N e)
(s := Finset.univ) (fun N _ => mul_nonneg (hp.1.1 N) (G.indicator_nonneg N e))
(Finset.mem_univ M)
have hm : G.indicator M e=1 := by simp [LooplessGraph.indicator,he]
rw [hm,mul_one] at hh
change p M ≤ G.mean p e at hh
rw [hp.2] at hh
exact hM.trans_le hh
· simp only [he,decide_false]
have hh := Finset.single_le_sum (f := fun N => p N*(1-G.indicator N e))
(s := Finset.univ) (fun N _ => mul_nonneg (hp.1.1 N)
(sub_nonneg.mpr (G.indicator_le_one N e))) (Finset.mem_univ M)
have hm : G.indicator M e=0 := by simp [LooplessGraph.indicator,he]
simp only [hm,sub_zero,mul_one,mul_sub,Finset.sum_sub_distrib,hp.1.2] at hh
change p M ≤ 1-G.mean p e at hh
rw [hp.2] at hh
exact hM.trans_le hh
omit [Fintype V] [DecidableEq V] in
theorem matching_entropy_le_binary (G : LooplessGraph V E) {x : E → ℝ}
{p : G.Matching → ℝ} (hp : p ∈ G.feasibleLaws x) : entropy p ≤ binaryEntropy x := by
have hx := G.coordinate_mem_Icc ((G.mem_polytope_iff x).mpr ⟨p,hp⟩)
have hprod (M : G.Matching) (hM : 0<p M) : 0<productBoolean x (G.matchingBits M) :=
Finset.prod_pos (fun e _ => matching_boolean_factor_pos G hp hM e)
have hcross := entropy_le_subprob_crossEntropy
(fun M => productBoolean_nonneg hx (G.matchingBits M)) (matchingBoolean_sum_le G hx) hp.1
(fun M hzero => le_antisymm (le_of_not_gt (fun hM => (ne_of_gt (hprod M hM)) hzero)) (hp.1.1 M))
have hlog (M : G.Matching) : p M*Real.log (productBoolean x (G.matchingBits M)) =
∑ e, p M*(G.indicator M e*Real.log (x e)+(1-G.indicator M e)*Real.log (1-x e)) := by
by_cases hzero : p M=0
· simp [hzero]
· have hpos : 0<p M := lt_of_le_of_ne (hp.1.1 M) (Ne.symm hzero)
rw [productBoolean,Real.log_prod (fun e _ => ne_of_gt (matching_boolean_factor_pos G hp hpos e)),
Finset.mul_sum]
apply Finset.sum_congr rfl
intro e _
simp only [LooplessGraph.matchingBits,LooplessGraph.indicator]
by_cases he : e ∈ M.val <;> simp [he]
have heq : -(∑ M, p M*Real.log (productBoolean x (G.matchingBits M)))=binaryEntropy x := by
simp_rw [hlog]
rw [Finset.sum_comm]
have he (e : E) : (∑ M, p M*(G.indicator M e*Real.log (x e)+
(1-G.indicator M e)*Real.log (1-x e)))=
x e*Real.log (x e)+(1-x e)*Real.log (1-x e) := by
simp_rw [mul_add,← mul_assoc,Finset.sum_add_distrib,← Finset.sum_mul]
have hmean : (∑ M,p M*G.indicator M e)=x e := congrFun hp.2 e
have hbar : (∑ M,p M*(1-G.indicator M e))=1-x e := by
simp_rw [mul_sub,mul_one,Finset.sum_sub_distrib,hp.1.2,hmean]
rw [hmean,hbar]
simp_rw [he]
rw [Finset.sum_add_distrib,neg_add_rev]
dsimp only [binaryEntropy]
rw [entropy_eq,entropy_eq]
ring
rwa [heq] at hcross
omit [Fintype V] [DecidableEq V] in
theorem maxMatchingEntropy_le_binary (G : LooplessGraph V E) (x : E → ℝ)
(hx : x ∈ G.polytope) : maxMatchingEntropy G x ≤ binaryEntropy x := by
obtain ⟨p,hp,hopt⟩ := maxMatchingEntropy_attained G hx
rw [← hopt]
exact matching_entropy_le_binary G hp
end MatchingEntropy
end
end
end OAI
|