最大熵模型
最大熵模型(maximum entropy model)由最大熵原理推导实现
最大熵原理
最大熵原理是概率模型学习的一个准则。最大熵原理认为,学习概率模型时,在所有可能的概率模型(分布)中,熵最大的模型时最好的模型。通常用约束条件来确定概率模型的集合,所以,最大熵原理也可以表述为在满足约束条件的模型集合中选取熵最大的模型。
假设离散随机变量 X X X的概率分布时 P ( X ) P\left(X\right) P(X),则其熵是
H ( P ) = − ∑ x P ( x ) log P ( x ) H\left(P\right) = -\sum_{x}P\left(x\right)\log P\left(x\right) H(P)=−x∑P(x)logP(x)
熵满足下列不等式:
0 ≤ H ( P ) ≤ log ∣ X ∣ 0\le H\left(P\right) \le \log \left|X\right| 0≤H(P)≤log∣X∣
其中 ∣ X ∣ \left|X\right| ∣X∣是 X X X的取值个数,当且仅当 X X X的分布是均匀分布时,右边的等号成立。
这就是说,当 X X X服从均匀分布时,熵最大
证明:
max p i − ∑ i = 1 n p i log p i s.t. ∑ i = 1 n p i = 1 \begin{aligned} &\max _{p_{i}}-\sum_{i=1}^{n} p_{i} \log p_{i} \\ &\text { s.t. } \sum_{i=1}^{n} p_{i}=1 \end{aligned} pimax−i=1∑npilogpi s.t. i=1∑npi=1
显然 − ∑ i = 1 n p i log p i ≥ 0 -\sum_{i=1}^{n} p_{i} \log p_{i} \ge 0 −∑i=1npilogpi≥0
当 p i p_i pi中其中一个为 1 1 1,其他为 0 0 0时, − ∑ i = 1 n p i log p i = 0 -\sum_{i=1}^{n} p_{i} \log p_{i} = 0 −∑i=1npilogpi=0
拉格朗日函数
L ( P , λ ) = − ∑ i = 1 n p i log p i − λ ( ∑ i = 1 n p i − 1 ) L\left(P, \lambda\right) = -\sum_{i=1}^{n} p_{i} \log p_{i} - \lambda\left(\sum_{i=1}^{n} p_{i} - 1\right) L(P,λ)=−i=1∑npilogpi−λ(i=1∑npi−1)
求导
∂ L ∂ p i = − log p i − 1 − λ = 0 \frac{\partial L}{\partial p_i} = -\log p_i - 1-\lambda =0 ∂pi∂L=−logpi−1−λ=0
于是
log p 1 = log p 2 = ⋯ = log p n = − λ − 1 \log p_1=\log p_2 = \cdots = \log p_n = -\lambda - 1 logp1=logp2=⋯=logpn=−λ−1
进而
p 1 = p 2 = ⋯ = p n p_1 = p_2=\cdots = p_n p1=p2=⋯=pn
最大熵模型的定义
最大熵原理时统计学习的一般原理,将它应用到分类得到最大熵模型
假设分类模型时一个条件概率分布 P ( Y ∣ X ) P\left(Y|X\right) P(Y∣X), X ∈ X ⊆ R n X\in\mathcal{X}\subseteq \mathbb{R}^n X∈X⊆Rn表示输入, Y ∈ Y Y\in\mathcal{Y} Y∈Y表示输出, X \mathcal{X} X和 Y \mathcal{Y} Y分别是输入和输出的集合。
这个模型表示的是对于给定的输入 X X X,以条件概率 P ( Y ∣ X ) P\left(Y|X\right) P(Y∣X)输出 Y Y Y
给定一个训练数据集
T = { ( x 1 , y 1 ) , ⋯ , ( x N , y N ) } T = \left\{\left(\mathbf{x}_1,y_1\right),\cdots,\left(\mathbf{x}_N,y_N\right)\right\} T={(x1,y1),⋯,(xN,yN)}
学习的目标是用最大熵原理选择最好的分类模型
首先考虑模型应该满足的条件。给定训练数据集,可以确定联合分布 P ( X , Y ) P\left(X,Y\right) P(X,Y)的经验分布和边缘分布 P ( X ) P\left(X\right) P(X)的经验分布,分别以 P ~ ( X , Y ) \tilde{P}\left(X,Y\right) P~(X,Y)和 P ~ ( X ) \tilde{P}\left(X\right) P~(X)表示。这里
P ~ ( X = x , Y = y ) = v ( X = x , Y = y ) N P ~ ( X = x ) = v ( X = x ) N \tilde{P}\left(X=\mathbf{x},Y=y\right)=\frac{v\left(X=\mathbf{x},Y=y\right)}{N}\\ \tilde{P}\left(X=\mathbf{x}\right) = \frac{v\left(X = \mathbf{x}\right)}{N} P~(X=x,Y=y)=Nv(X=x,Y=y)P~(X=x)=Nv(X=x)
其中, v ( X = x , Y = y ) v\left(X=\mathbf{x},Y= y\right) v(X=x,Y=y)表示训练数据中样本 ( x , y ) \left(\mathbf{x},y\right) (x,y)出现的频率, v ( X = x ) v\left(X=\mathbf{x}\right) v(X=x)表示训练数据中输入 x \mathbf{x} x出现的频率, N N N表示训练样本容量
用特征函数(feature function) f ( x , y ) f\left(\mathbf{x}, y\right) f(x,y)描述输入 x \mathbf{x} x和输出 y y y之间的某一个事实,其定义是
f ( x , y ) = { 1 , x 与 y 满足某一事实 0 , 否则 f\left(\mathbf{x},y\right) = \begin{cases} 1, & \mathbf{x}与y满足某一事实\\ 0, &否则 \end{cases} f(x,y)={1,0,x与y满足某一事实否则
特征函数 f ( x , y ) f\left(x,y\right) f(x,y)关于经验分布 P ~ ( X , Y ) \tilde{P}\left(X,Y\right) P~(X,Y)的期望值,用 E P ~ ( f ) E_{\tilde{P}}\left(f\right) EP~(f)表示
E P ~ ( f ) = ∑ x , y P ~ ( x , y ) f ( x , y ) E_{\tilde{P}}\left(f\right)=\sum_{\mathbf{x},y}\tilde{P}\left(\mathbf{x},y\right)f\left(\mathbf{x},y\right) EP~(f)=x,y∑P~(x,y)f(x,y)
特征函数 f ( x , y ) f\left(\mathbf{x},y\right) f(x,y)关于模型 P ( Y ∣ X ) P\left(Y|X\right) P(Y∣X)与经验分布 P ~ ( X ) \tilde{P}\left(X\right) P~(X)的期望值,用 E P ( f ) E_P\left(f\right) EP(f)表示
E P ( f ) = ∑ x , y P ~ ( x ) P ( y ∣ x ) f ( x , y ) E_P\left(f\right) = \sum_{\mathbf{x},y}\tilde{P}\left(\mathbf{x}\right)P\left(y|\mathbf{x}\right)f\left(\mathbf{x},y\right) EP(f)=x,y∑P~(x)P(y∣x)f(x,y)
如果模型能够获取训练数据中的信息,那么就可以假设这两个期望值相等,即
E P ( f ) = E P ~ ( f ) E_P\left(f\right)=E_{\tilde{P}}\left(f\right) EP(f)=EP~(f)
或者
∑ x , y P ~ ( x ) P ( y ∣ x ) f ( x , y ) = ∑ x , y P ~ ( x , y ) f ( x , y ) \sum_{\mathbf{x},y}\tilde{P}\left(\mathbf{x}\right)P\left(y|\mathbf{x}\right)f\left(\mathbf{x},y\right)=\sum_{\mathbf{x},y}\tilde{P}\left(\mathbf{x},y\right)f\left(\mathbf{x},y\right) x,y∑P~(x)P(y∣x)f(x,y)=x,y∑P~(x,y)f(x,y)
上式作为模型学习的约束条件
假设有 n n n个特征函数 f i ( x , y ) f_i\left(\mathbf{x},y\right) fi(x,y),那么就有 n n n个约束条件
最大熵模型:假设满足所有约束条件的模型集合为
C ≡ { P ∈ P ∣ E p ( f i ) = E P ~ ( f i ) , i = 1 , 2 , ⋯ , n } \mathcal{C}\equiv\left\{P\in\mathcal{P}|E_p\left(f_i\right) = E_{\tilde{P}}\left(f_i\right),\quad i = 1,2,\cdots, n\right\} C≡{P∈P∣Ep(fi)=EP~(fi),i=1,2,⋯,n}
定义在条件概率分布 P ( Y ∣ X ) P\left(Y|X\right) P(Y∣X)上的条件熵为
H ( P ) = − ∑ x , y P ~ ( x ) P ( y ∣ x ) log P ( y ∣ x ) H\left(P\right) = -\sum_{\mathbf{x},y}\tilde{P}\left(\mathbf{x}\right)P\left(y|\mathbf{x}\right)\log P\left(y|\mathbf{x}\right) H(P)=−x,y∑P~(x)P(y∣x)logP(y∣x)
则模型集合 C \mathcal{C} C中条件熵 H ( P ) H\left(P\right) H(P)最大的模型称为最大熵模型。
(其中 log = ln = log e \log = \ln = \log_e log=ln=loge)
最大熵模型的学习
最大熵模型的学习过程就是求解最大熵模型的过程。最大熵模型的学习可以形式化为约束最大化问题
对于给定的训练数据集 T = { ( x 1 , y 1 ) , ⋯ , ( x N , y N ) } T=\left\{\left(\mathbf{x}_1,y_1\right), \cdots, \left(\mathbf{x}_N, y_N\right)\right\} T={(x1,y1),⋯,(xN,yN)}以及特征函数 f i ( x , y ) f_i\left(\mathbf{x},y\right) fi(x,y),最大熵的学习等价于约束最优化问题:
max P ∈ C H ( P ) = − ∑ x , y P ~ ( x ) P ( y ∣ x ) log P ( y ∣ x ) s . t . E P ( f i ) = E P ~ ( f i ) , i = 1 , 2 , ⋯ , n ∑ y P ( y ∣ x ) = 1 \begin{aligned} \max_{P\in \mathcal{C}} & H\left(P\right) = -\sum_{\mathbf{x},y}\tilde{P}\left(\mathbf{x}\right)P\left(y|\mathbf{x}\right)\log P\left(y|\mathbf{x}\right)\\ s.t.& E_P\left(f_i\right) = E_{\tilde{P}}\left(f_i\right),\quad i = 1,2,\cdots, n\\ &\sum_{y}P\left(y|\mathbf{x}\right) =1 \end{aligned} P∈Cmaxs.t.H(P)=−x,y∑P~(x)P(y∣x)logP(y∣x)EP(fi)=EP~(fi),i=1,2,⋯,ny∑P(y∣x)=1
改成最小化
min P ∈ C − H ( P ) = ∑ x , y P ~ ( x ) P ( y ∣ x ) log P ( y ∣ x ) s . t . E P ( f i ) = E P ~ ( f i ) , i = 1 , 2 , ⋯ , n ∑ y P ( y ∣ x ) = 1 \begin{aligned} \min_{P\in \mathcal{C}} & -H\left(P\right) = \sum_{\mathbf{x},y}\tilde{P}\left(\mathbf{x}\right)P\left(y|\mathbf{x}\right)\log P\left(y|\mathbf{x}\right)\\ s.t.& E_P\left(f_i\right) = E_{\tilde{P}}\left(f_i\right),\quad i = 1,2,\cdots, n\\ &\sum_{y}P\left(y|\mathbf{x}\right) =1 \end{aligned} P∈Cmins.t.−H(P)=x,y∑P~(x)P(y∣x)logP(y∣x)EP(fi)=EP~(fi),i=1,2,⋯,ny∑P(y∣x)=1
拉格朗日函数
L ( P , w ) = − H ( P ) + w 0 ( 1 − ∑ y P ( y ∣ x ) ) + ∑ i = 1 n w i ( E P ~ ( f i ) − E P ( f i ) ) = ∑ x , y P ~ ( x ) P ( y ∣ x ) log P ( y ∣ x ) + w 0 ( 1 − ∑ y P ( y ∣ x ) ) + ∑ i = 1 n w i ( ∑ x , y P ~ ( x , y ) f ( x , y ) − ∑ x , y P ~ ( x ) P ( y ∣ x ) f ( x , y ) ) \begin{aligned} L\left(P,\mathbf{w}\right) &=-H\left(P\right) + w_0\left(1 - \sum_{y}P\left(y|\mathbf{x}\right)\right)+\sum_{i=1}^{n}w_i\left(E_{\tilde{P}}\left(f_i\right) - E_P\left(f_i\right)\right)\\ &=\sum_{\mathbf{x},y}\tilde{P}\left(\mathbf{x}\right)P\left(y|\mathbf{x}\right)\log P\left(y|\mathbf{x}\right)+w_0\left(1 - \sum_{y}P\left(y|\mathbf{x}\right)\right)\\ &\quad +\sum_{i=1}^{n}w_i\left(\sum_{\mathbf{x},y}\tilde{P}\left(\mathbf{x},y\right)f\left(\mathbf{x},y\right) - \sum_{\mathbf{x},y}\tilde{P}\left(\mathbf{x}\right)P\left(y|\mathbf{x}\right)f\left(\mathbf{x},y\right)\right) \end{aligned} L(P,w)=−H(P)+w0(1−y∑P(y∣x))+i=1∑nwi(EP~(fi)−EP(fi))=x,y∑P~(x)P(y∣x)logP(y∣x)+w0(1−y∑P(y∣x))+i=1∑nwi(x,y∑P~(x,y)f(x,y)−x,y∑P~(x)P(y∣x)f(x,y))
原始问题
min P ∈ C max w L ( P , w ) \min_{P\in \mathcal{C}}\max_{\mathbf{w}} L\left(P,\mathbf{w}\right) P∈CminwmaxL(P,w)
对偶问题
max w min P ∈ C L ( P , w ) \max_{\mathbf{w}}\min_{P\in \mathcal{C}} L\left(P,\mathbf{w}\right) wmaxP∈CminL(P,w)
目标函数是凸的,约束条件是等式约束,于是满足广义Slater条件, 所以原始问题与对偶问题等价
设
ψ ( w ) = min P ∈ C L ( P , w ) = L ( P w , w ) \psi\left(\mathbf{w}\right) = \min_{P\in \mathcal{C}} L\left(P,\mathbf{w}\right)=L\left(P_\mathbf{w},\mathbf{w}\right) ψ(w)=P∈CminL(P,w)=L(Pw,w)
其中
P w = arg min P ∈ C L ( P , w ) = P w ( y ∣ x ) P_{\mathbf{w}}=\arg\min_{P\in\mathcal{C}} L\left(P,\mathbf{w}\right) = P_{\mathbf{w}}\left(y|\mathbf{x}\right) Pw=argP∈CminL(P,w)=Pw(y∣x)
∂ L ∂ P ( y ∣ x ) = ∑ x , y P ~ ( x ) ( log P ( y ∣ x ) + 1 ) − ∑ y w 0 − ∑ x , y ( P ~ ( x ) ∑ i = 1 n w i f i ( x , y ) ) = ∑ x , y P ~ ( x ) ( log P ( y ∣ x ) + 1 − w 0 − ∑ i = 1 n w i f i ( x , y ) ) = 0 \begin{aligned} \frac{\partial L}{\partial P\left(y|\mathbf{x}\right)} &= \sum_{\mathbf{x},y} \tilde{P}\left(\mathbf{x}\right)\left(\log P\left(y|\mathbf{x}\right) + 1\right)-\sum_{y}w_0-\sum_{\mathbf{x},y}\left(\tilde{P}\left(\mathbf{x}\right)\sum_{i=1}^{n}w_if_i\left(\mathbf{x},y\right)\right)\\ &= \sum_{\mathbf{x},y}\tilde{P}\left(\mathbf{x}\right)\left(\log P\left(y|\mathbf{x}\right) + 1-w_0-\sum_{i=1}^{n}w_if_i\left(\mathbf{x},y\right)\right)\\ &=0 \end{aligned} ∂P(y∣x)∂L=x,y∑P~(x)(logP(y∣x)+1)−y∑w0−x,y∑(P~(x)i=1∑nwifi(x,y))=x,y∑P~(x)(logP(y∣x)+1−w0−i=1∑nwifi(x,y))=0
在 P ~ ( x ) > 0 \tilde{P}\left(\mathbf{x}\right)>0 P~(x)>0的情况下
P ( y ∣ x ) = e x p ( ∑ i = 1 n w i f i ( x , y ) + w 0 − 1 ) = e x p ( ∑ i = 1 n w i f i ( x , y ) ) e x p ( 1 − w 0 ) P\left(y|\mathbf{x}\right) = exp\left(\sum_{i=1}^{n}w_if_i\left(\mathbf{x},y\right) + w_0 - 1\right)=\frac{exp\left(\sum_{i=1}^{n}w_if_i\left(\mathbf{x},y\right)\right)}{exp\left(1-w_0\right)} P(y∣x)=exp(i=1∑nwifi(x,y)+w0−1)=exp(1−w0)exp(∑i=1nwifi(x,y))
利用 ∑ y P ( y ∣ x ) = 1 \sum_{y} P\left(y|\mathbf{x}\right) = 1 ∑yP(y∣x)=1,得
P w ( y ∣ x ) = 1 Z w ( x ) e x p ( ∑ i = 1 n w i f i ( x , y ) ) P_{\mathbf{w}}\left(y|\mathbf{x}\right) = \frac{1}{Z_{\mathbf{w}}\left(\mathbf{x}\right)}exp\left(\sum_{i=1}^{n}w_if_i\left(\mathbf{x},y\right)\right) Pw(y∣x)=Zw(x)1exp(i=1∑nwifi(x,y))
其中
Z w ( x ) = ∑ y e x p ( ∑ i = 1 n w i f i ( x , y ) ) Z_{\mathbf{w}}\left(\mathbf{x}\right) = \sum_{y}exp\left(\sum_{i=1}^{n}w_if_i\left(\mathbf{x},y\right)\right) Zw(x)=y∑exp(i=1∑nwifi(x,y))
其中 Z w ( x ) Z_{\mathbf{w}}\left(\mathbf{x}\right) Zw(x)称为规范化因子;
P w = P w ( y ∣ x ) P_{\mathbf{w}}=P_{\mathbf{w}}\left(y|\mathbf{x}\right) Pw=Pw(y∣x)就是最大熵模型。这里 w \mathbf{w} w是最大熵模型中的参数向量
之后,求解
max ψ ( w ) \max\psi\left(\mathbf{w}\right) maxψ(w)
令
w ∗ = arg max w ψ ( w ) \mathbf{w}^{*} = \arg\max_{\mathbf{w}}\psi\left(\mathbf{w}\right) w∗=argwmaxψ(w)
极大似然估计
下面证明对偶函数的极大化等价于最大熵模型的极大似然估计
训练数据的经验概率分布 P ~ ( X , Y ) \tilde{P}\left(X,Y\right) P~(X,Y),条件概率分布 P ( Y ∣ X ) P\left(Y|X\right) P(Y∣X)的对数似然函数表示为
L P ~ ( P w ) = log π x , y P ( y ∣ x ) P ~ ( x , y ) = ∑ x , y P ~ ( x , y ) log P ( y ∣ x ) L_{\tilde{P}} \left(P_{\mathbf{w}}\right) = \log \pi_{\mathbf{x},y}P\left(y|\mathbf{x}\right)^{\tilde{P}\left(\mathbf{x},y\right)} =\sum_{\mathbf{x},y}\tilde{P}\left(\mathbf{x},y\right) \log P\left(y|\mathbf{x}\right) LP~(Pw)=logπx,yP(y∣x)P~(x,y)=x,y∑P~(x,y)logP(y∣x)
L P ~ ( P w ) = ∑ x , y P ~ ( x , y ) log P ( y ∣ x ) = ∑ x , y P ~ ( x , y ) ∑ i = 1 n w i f i ( x , y ) − ∑ x , y P ~ ( x , y ) log Z w ( x ) = ∑ x , y P ~ ( x , y ) ∑ i = 1 n w i f i ( x , y ) − ∑ x P ~ ( x ) log Z w ( x ) \begin{aligned} L_{\tilde{P}}\left(P_{\mathbf{w}}\right) &= \sum_{\mathbf{x},y} \tilde{P}\left(\mathbf{x},y\right) \log P\left(y|\mathbf{x}\right)\\ &=\sum_{\mathbf{x},y}\tilde{P}\left(\mathbf{x},y\right)\sum_{i=1}^{n}w_i f_i\left(\mathbf{x},y\right) - \sum_{\mathbf{x},y}\tilde{P}\left(\mathbf{x},y\right)\log Z_{\mathbf{w}}\left(\mathbf{x}\right)\\ &=\sum_{\mathbf{x},y}\tilde{P}\left(\mathbf{x},y\right)\sum_{i=1}^{n}w_i f_i\left(\mathbf{x},y\right) - \sum_{\mathbf{x}}\tilde{P}\left(\mathbf{x}\right)\log Z_{\mathbf{w}}\left(\mathbf{x}\right) \end{aligned} LP~(Pw)=x,y∑P~(x,y)logP(y∣x)=x,y∑P~(x,y)i=1∑nwifi(x,y)−x,y∑P~(x,y)logZw(x)=x,y∑P~(x,y)i=1∑nwifi(x,y)−x∑P~(x)logZw(x)
接着
ψ ( w ) = ∑ x , y P ~ ( x ) P w ( y , x ) log P w ( y ∣ x ) + ∑ i = 1 n w i ( ∑ x , y P ~ ( x , y ) f i ( x , y ) − ∑ x , y P ~ ( x ) P w ( y ∣ x ) f i ( x , y ) ) = ∑ x , y P ~ ( x , y ) ∑ i = 1 n w i f i ( x , y ) + ∑ x , y P ~ ( x ) P w ( y ∣ x ) ( log P w ( y ∣ x ) − ∑ i = 1 n w i f i ( x , y ) ) = ∑ x , y P ~ ( x , y ) ∑ i = 1 n w i f i ( x , y ) − ∑ x , y P ~ ( x ) P w ( y ∣ x ) log Z w ( x ) = ∑ x , y P ~ ( x , y ) ∑ i = 1 n w i f i ( x , y ) − ∑ x , y P ~ ( x ) log Z w ( x ) \begin{aligned} \psi\left(\mathbf{w}\right) &= \sum_{\mathbf{x},y}\tilde{P}\left(\mathbf{x}\right)P_{\mathbf{w}}\left(y,\mathbf{x}\right)\log P_{\mathbf{w}}\left(y|\mathbf{x}\right) \\ &\quad + \sum_{i=1}^n w_i\left(\sum_{\mathbf{x},y}\tilde{P}\left(\mathbf{x},y\right)f_i\left(\mathbf{x},y\right) - \sum_{\mathbf{x},y}\tilde{P}\left(\mathbf{x}\right)P_{\mathbf{w}}\left(y|\mathbf{x}\right)f_i\left(\mathbf{x},y\right)\right)\\ &=\sum_{\mathbf{x},y}\tilde{P}\left(\mathbf{x},y\right)\sum_{i=1}^{n}w_i f_i\left(\mathbf{x},y\right) + \sum_{\mathbf{x},y}\tilde{P}\left(\mathbf{x}\right) P_{\mathbf{w}}\left(y|\mathbf{x}\right)\left(\log P_{\mathbf{w}}\left(y|\mathbf{x}\right) - \sum_{i=1}^{n}w_if_i\left(\mathbf{x},y\right)\right)\\ &=\sum_{\mathbf{x},y}\tilde{P}\left(\mathbf{x},y\right)\sum_{i=1}^{n}w_i f_i\left(\mathbf{x},y\right)-\sum_{\mathbf{x},y}\tilde{P}\left(\mathbf{x}\right)P_{\mathbf{w}}\left(y|\mathbf{x}\right)\log Z_{\mathbf{w}}\left(\mathbf{x}\right)\\ &=\sum_{\mathbf{x},y}\tilde{P}\left(\mathbf{x},y\right)\sum_{i=1}^{n}w_i f_i\left(\mathbf{x},y\right)-\sum_{\mathbf{x},y}\tilde{P}\left(\mathbf{x}\right)\log Z_{\mathbf{w}}\left(\mathbf{x}\right)\\ \end{aligned} ψ(w)=x,y∑P~(x)Pw(y,x)logPw(y∣x)+i=1∑nwi(x,y∑P~(x,y)fi(x,y)−x,y∑P~(x)Pw(y∣x)fi(x,y))=x,y∑P~(x,y)i=1∑nwifi(x,y)+x,y∑P~(x)Pw(y∣x)(logPw(y∣x)−i=1∑nwifi(x,y))=x,y∑P~(x,y)i=1∑nwifi(x,y)−x,y∑P~(x)Pw(y∣x)logZw(x)=x,y∑P~(x,y)i=1∑nwifi(x,y)−x,y∑P~(x)logZw(x)
这样,最大熵模型的学习问题就转化为具体求解对数似然函数极大化或对偶函数极大化的问题
可以将最大熵模型写成更一般的形式
1 Z w ( x ) e x p ( ∑ i = 1 n w i f i ( x , y ) ) \frac{1}{Z_{\mathbf{w}}\left(\mathbf{x}\right)}exp\left(\sum_{i=1}^{n}w_i f_i\left(\mathbf{x},y\right)\right) Zw(x)1exp(i=1∑nwifi(x,y))
其中
Z w ( x ) = ∑ y e x p ( ∑ i = 1 n w i f i ( x , y ) ) Z_{\mathbf{w}}\left(\mathbf{x}\right)=\sum_{y}exp\left(\sum_{i=1}^{n}w_i f_i\left(\mathbf{x},y\right)\right) Zw(x)=y∑exp(i=1∑nwifi(x,y))
这里 x ∈ R n \mathbf{x}\in\mathbb{R}^n x∈Rn为输入, y ∈ { 1 , 2 , ⋯ , K } y\in\left\{1,2,\cdots, K\right\} y∈{1,2,⋯,K}为输出, w ∈ R n \mathbf{w}\in\mathbb{R}^n w∈Rn为权值向量, f i ( x , y ) f_i\left(\mathbf{x},y\right) fi(x,y)为任意实值特征函数
参考:
统计学习方法(李航)