File size: 6,164 Bytes
4a56cd6 | 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 | import OAI.Combinatorics.PerfectMatching.EntropyUpper
import OAI.Combinatorics.PerfectMatching.DyadicEntropy
namespace OAI
universe u_1 u_2
section
noncomputable section
open Finset
namespace MatchingEntropy
variable {I : Type*} [Fintype I]
def expSum (a : I β β) : β := β i, Real.exp (a i)
def expLaw (a : I β β) (i : I) : β := Real.exp (a i)/expSum a
lemma expSum_pos [Nonempty I] (a : I β β) : 0<expSum a :=
sum_pos (fun i _ => Real.exp_pos (a i)) univ_nonempty
lemma expLaw_simplex [Nonempty I] (a : I β β) : expLaw aβprobabilitySimplex I := by
refine β¨fun i => (div_pos (Real.exp_pos _) (expSum_pos a)).le,?_β©
simp only [expLaw,βsum_div]
exact div_self (expSum_pos a).ne'
lemma log_expLaw [Nonempty I] (a : I β β) (i : I) :
Real.log (expLaw a i)=a i-Real.log (expSum a) := by
rw [expLaw,Real.log_div (Real.exp_ne_zero _) (expSum_pos a).ne',Real.log_exp]
lemma expLaw_cross [Nonempty I] (a : I β β) {p : I β β}
(hp : pβprobabilitySimplex I) :
-(β i,p i*Real.log (expLaw a i))=Real.log (expSum a)-β i,p i*a i := by
simp only [log_expLaw,mul_sub,sum_sub_distrib,βsum_mul,hp.2,one_mul]
ring
lemma expSum_variational_le [Nonempty I] (a : I β β) {p : I β β}
(hp : pβprobabilitySimplex I) : entropy p+β i,p i*a iβ€Real.log (expSum a) := by
have hh := entropy_le_crossEntropy (expLaw_simplex a) hp
(fun i hi => False.elim ((div_pos (Real.exp_pos _) (expSum_pos a)).ne' hi))
rw [expLaw_cross a hp] at hh
linarith
lemma expSum_variational_eq [Nonempty I] (a : I β β) :
entropy (expLaw a)+β i,expLaw a i*a i=Real.log (expSum a) := by
rw [entropy_eq,expLaw_cross a (expLaw_simplex a)]
ring
namespace LooplessGraph
variable {V : Type u_1} {E : Type u_2} [Fintype V] [Fintype E] [DecidableEq V] [DecidableEq E]
def score (G : LooplessGraph V E) (Ξ² : E β β) (M : G.Matching) : β :=
β eβM.val,Ξ² e
def weightedZ (G : LooplessGraph V E) (Ξ² : E β β) : β :=
expSum (fun M => Real.log 2*G.score Ξ² M)
omit [Fintype V] [DecidableEq V] in
lemma score_indicator (G : LooplessGraph V E) (Ξ² : E β β) (M : G.Matching) :
G.score Ξ² M=β e, Ξ² e*G.indicator M e := by
simp [score,indicator]
omit [Fintype V] [DecidableEq V] in
lemma mean_score (G : LooplessGraph V E) (Ξ² : E β β) (p : G.Matching β β) :
(β M,p M*G.score Ξ² M)=β e,Ξ² e*G.mean p e := by
simp only [score_indicator,mul_sum]
rw [sum_comm]
apply sum_congr rfl; intro e _
simp only [mean,mul_sum]
apply sum_congr rfl; intro M _; ring
omit [Fintype V] [DecidableEq V] in
lemma complement_entropy_le_mass (G : LooplessGraph V E) {x : E β β}
(hx : xβG.polytope) : entropy (fun e => 1-x e)β€β e,x e := by
apply sum_le_sum; intro e _
have hh := Real.negMulLog_le_one_sub_self (sub_nonneg.mpr (G.coordinate_mem_Icc hx e).2)
simpa only [sub_sub_cancel] using hh
lemma entropy_binary_scale (G : LooplessGraph V E) (hPM : Nonempty G.Matching)
{r : β} (hV : Fintype.card V=2*r) {x : E β β} (hx : xβG.polytope) :
entropy x/Real.log 2-4*(Fintype.card V:β)β€ maxMatchingEntropy G x/Real.log 2 β§
maxMatchingEntropy G x/Real.log 2β€entropy x/Real.log 2+(Fintype.card V:β) := by
have hl := separable_lower G hPM x hx
have hu := maxMatchingEntropy_le_binary G x hx
have hc := G.complement_entropy_le_mass hx
rw [G.marginal_sum hV hx] at hc
have hv : (Fintype.card V:β)=2*(r:β) := by exact_mod_cast hV
have hlog := BinaryMatching.Algorithm.half_le_log_two
have hr : (0:β)β€r := by positivity
have hprod := mul_le_mul_of_nonneg_right hlog hr
dsimp only [separableLower,binaryEntropy] at hl hu
constructor
Β· apply (le_div_iffβ BinaryMatching.Algorithm.log_two_pos).2
rw [sub_mul,div_mul_cancelβ _ BinaryMatching.Algorithm.log_two_pos.ne',hv]
nlinarith
Β· apply (div_le_iffβ BinaryMatching.Algorithm.log_two_pos).2
rw [add_mul,div_mul_cancelβ _ BinaryMatching.Algorithm.log_two_pos.ne',hv]
nlinarith
omit [Fintype V] [DecidableEq V] in
lemma weighted_variational_le (G : LooplessGraph V E) [Nonempty G.Matching]
(Ξ² : E β β) {x : E β β} (hx : xβG.polytope) :
maxMatchingEntropy G x/Real.log 2+β e,Ξ² e*x eβ€Real.log (G.weightedZ Ξ²)/Real.log 2 := by
obtain β¨p,hp,hhβ© := maxMatchingEntropy_attained G hx
have h := expSum_variational_le (fun M => Real.log 2*G.score Ξ² M) hp.1
have he : (β M,p M*(Real.log 2*G.score Ξ² M))=Real.log 2*(β e,Ξ² e*x e) := by
rw [mul_sum]
conv_lhs => arg 2; ext M; rw [mul_left_comm]
rw [βmul_sum,G.mean_score,hp.2,mul_sum]
rw [he,hh] at h
apply (le_div_iffβ BinaryMatching.Algorithm.log_two_pos).2
calc
_ = maxMatchingEntropy G x+Real.log 2*(β e,Ξ² e*x e) := by
rw [add_mul,div_mul_cancelβ _ BinaryMatching.Algorithm.log_two_pos.ne']; ring
_ β€ _ := h
omit [Fintype V] [DecidableEq V] in
lemma weighted_variational_attained (G : LooplessGraph V E) [Nonempty G.Matching]
(Ξ² : E β β) : β xβG.polytope,
Real.log (G.weightedZ Ξ²)/Real.log 2β€ maxMatchingEntropy G x/Real.log 2+β e,Ξ² e*x e := by
let p := expLaw (fun M => Real.log 2*G.score Ξ² M)
have hp := expLaw_simplex (fun M => Real.log 2*G.score Ξ² M)
have hpx : pβG.feasibleLaws (G.mean p) := β¨hp,rflβ©
refine β¨G.mean p,(G.mem_polytope_iff _).mpr β¨p,hpxβ©,?_β©
have he := expSum_variational_eq (fun M => Real.log 2*G.score Ξ² M)
have he' : (β M,p M*(Real.log 2*G.score Ξ² M))=Real.log 2*(β e,Ξ² e*G.mean p e) := by
calc
_ = Real.log 2*(β M,p M*G.score Ξ² M) := by
rw [mul_sum]; apply sum_congr rfl; intro M _; ring
_ = _ := by rw [G.mean_score]
change entropy p+(β M,p M*(Real.log 2*G.score Ξ² M))=Real.log (G.weightedZ Ξ²) at he
rw [he'] at he
apply (div_le_iffβ BinaryMatching.Algorithm.log_two_pos).2
have hH := entropy_le_maxMatchingEntropy G hpx
calc
_ β€ maxMatchingEntropy G (G.mean p)+Real.log 2*(β e,Ξ² e*G.mean p e) := by linarith
_ = _ := by rw [add_mul,div_mul_cancelβ _ BinaryMatching.Algorithm.log_two_pos.ne']; ring
end LooplessGraph
end MatchingEntropy
end
end
end OAI
|