深度学习建立在概率论的基础上,本质是估计数据集(具有随机误差)的分布,即定义模型后进行参数估计。
极大似然估计
极大似然估计是点估计的一种,我们定义一个似然函数来作为对真实分布的估计,取似然程度最大的一组参数作为估计值。
给定分布
p
(
x
;
θ
)
p(x; \boldsymbol{\theta})
p(x;θ),从中取一组样本
X
1
,
X
2
,
X
3
,
.
.
.
,
X
n
X_1, X_2, X_3, ..., X_n
X1,X2,X3,...,Xn,则样本的
p
d
f
pdf
pdf为
L
(
θ
;
X
1
,
X
2
,
X
3
,
.
.
.
,
X
n
)
=
∏
i
n
p
(
x
i
;
θ
)
L(\boldsymbol{\theta};X_1, X_2, X_3, ..., X_n) = \prod_{i}^{n} p(x_i;\boldsymbol{\theta})
L(θ;X1,X2,X3,...,Xn)=i∏np(xi;θ)
其中,参数
θ
\boldsymbol{\theta}
θ未知,
L
L
L即为似然函数。
该问题也就转化为,在观测到一组样本
X
1
,
X
2
,
X
3
,
.
.
.
,
X
n
X_1, X_2, X_3, ..., X_n
X1,X2,X3,...,Xn时,
θ
\boldsymbol{\theta}
θ取什么值会使样本出现的可能性最大,也就是求
L
L
L最大时的参数
θ
\boldsymbol{\theta}
θ值。
arg
max
θ
∏
i
n
p
(
x
i
;
θ
)
\arg\max_{\theta}\prod_{i}^{n} p(x_i;\boldsymbol{\theta})
argθmaxi∏np(xi;θ)
将上述求积转为求和的对数,以便于计算
arg
max
θ
∑
i
n
log
p
(
x
i
;
θ
)
=
arg
min
θ
−
∑
i
n
log
p
(
x
i
;
θ
)
\arg\max_{\theta}\sum_{i}^{n}\log{p(x_i;\boldsymbol{\theta})} = \arg\min_{\theta} - \sum_{i}^{n}\log{p(x_i;\boldsymbol{\theta})}
argθmaxi∑nlogp(xi;θ)=argθmin−i∑nlogp(xi;θ)
KL散度 & 交叉熵
从另一个角度来讲,如何衡量
p
θ
p_{\theta}
pθ和
p
θ
^
p_{\hat\theta}
pθ^的差异呢?则可以使用f-divergence
中的KL散度来进行衡量。
KL散度定义为
D
K
L
(
p
θ
∣
∣
p
θ
^
)
=
∑
i
n
p
θ
(
x
i
)
log
p
θ
(
x
i
)
p
θ
^
(
x
i
)
=
∑
i
n
p
θ
(
x
i
)
log
p
θ
(
x
i
)
−
∑
i
n
p
θ
(
x
i
)
log
p
θ
^
(
x
i
)
D_{KL}(p_{\theta}||p_{\hat\theta}) = \sum_i^n p_{\theta}(x_i) \log \frac{p_{\theta}(x_i)}{p_{\hat\theta}(x_i)} = \sum_i^n p_{\theta}(x_i) \log {p_{\theta}(x_i)} - \sum_i^np_{\theta}(x_i) \log {p_{\hat\theta}(x_i)}
DKL(pθ∣∣pθ^)=i∑npθ(xi)logpθ^(xi)pθ(xi)=i∑npθ(xi)logpθ(xi)−i∑npθ(xi)logpθ^(xi)
其中,
∑
i
n
p
θ
(
x
i
)
log
p
θ
(
x
i
)
\sum_i^n p_{\theta}(x_i) \log {p_{\theta}}(x_i)
i∑npθ(xi)logpθ(xi)为常量。
因此,问题就转化为
arg
min
−
∑
i
n
p
θ
(
x
i
)
log
p
θ
^
(
x
i
)
=
arg
min
θ
−
E
x
log
p
θ
^
(
x
)
\arg \min - \sum_i^np_{\theta}(x_i) \log {p_{\hat\theta}}(x_i) = \arg \min_{\boldsymbol\theta} -E_x\log{p_{\hat\theta}}(\boldsymbol{x})
argmin−i∑npθ(xi)logpθ^(xi)=argθmin−Exlogpθ^(x)
该式子也是交叉熵。
结论
根据大数定理
∑
i
n
log
p
(
x
i
;
θ
)
=
E
x
log
p
θ
^
(
x
)
\sum_{i}^{n}\log{p(x_i;\boldsymbol{\theta})} = E_x\log{p_{\hat\theta}}(\boldsymbol{x})
i∑nlogp(xi;θ)=Exlogpθ^(x)
也就是在本问题中,求极大似然估计、最小化KL散度和最小化交叉熵等价。
注
大数定理
若
X
1
,
X
2
,
X
3
.
.
.
X_1, X_2, X_3...
X1,X2,X3...为独立同分布(iid)的随机变量,且
E
(
X
)
=
μ
,
V
a
r
X
=
σ
2
<
∞
E(X)=\mu, Var X = \sigma^2 < \infty
E(X)=μ,VarX=σ2<∞,定义
X
n
ˉ
=
∑
i
n
X
i
\bar{X_n} = \sum_i^n X_i
Xnˉ=∑inXi,则有
lim
n
→
∞
P
(
∣
X
n
ˉ
−
μ
∣
>
ϵ
)
=
0
\lim_{n\to\infty}P(|\bar{X_n}-\mu| > \epsilon) = 0
n→∞limP(∣Xnˉ−μ∣>ϵ)=0
f-divergence(f-散度)
在概率论中,f散度是用来测量两个分布P和Q之间差异的函数,定义为
D
f
(
P
∣
∣
Q
)
=
∫
f
(
d
P
d
Q
)
d
Q
D_f(P||Q) = \int f(\frac{dP}{dQ})dQ
Df(P∣∣Q)=∫f(dQdP)dQ
若P和Q可导
D
f
(
P
∣
∣
Q
)
=
∫
f
(
(
p
(
x
)
q
(
x
)
)
q
(
x
)
d
x
D_f(P||Q) = \int f(\frac{(p(x)}{q(x)}) q(x)dx
Df(P∣∣Q)=∫f(q(x)(p(x))q(x)dx
当
f
(
t
)
f(t)
f(t)取不同的函数时,即为不同的散度,KL散度取
f
(
t
)
=
t
log
(
t
)
f(t) = t\log(t)
f(t)=tlog(t)
D
K
L
(
P
∣
∣
Q
)
=
∫
p
(
x
)
(
p
(
x
)
q
(
x
)
d
x
D_{KL}(P||Q) = \int p(x)\frac{(p(x)}{q(x)}dx
DKL(P∣∣Q)=∫p(x)q(x)(p(x)dx
熵、KL散度和交叉熵
- 熵: H ( X ) = − ∑ i n p ( x i ) log p ( x i ) H(X)=-\sum_i^n p(x_i)\log p(x_i) H(X)=−∑inp(xi)logp(xi),表示不确定程度,越不确定值越大
- KL散度(相对熵): D K L ( p θ ∣ ∣ p θ ^ ) = ∑ i n p θ ( x i ) log p θ ( x i ) − ∑ i n p θ ( x i ) log p θ ^ ( x i ) D_{KL}(p_{\theta}||p_{\hat\theta}) = \sum_i^n p_{\theta}(x_i) \log {p_{\theta}(x_i)} - \sum_i^np_{\theta}(x_i) \log {p_{\hat\theta}(x_i)} DKL(pθ∣∣pθ^)=∑inpθ(xi)logpθ(xi)−∑inpθ(xi)logpθ^(xi)
- 交叉熵:
C
E
(
X
)
=
−
∑
i
n
p
θ
(
x
i
)
log
p
θ
^
(
x
i
)
CE(X) = - \sum_i^np_{\theta}(x_i) \log {p_{\hat\theta}(x_i)}
CE(X)=−∑inpθ(xi)logpθ^(xi)
从定义里可以看出,当熵为常量时,KL散度和交叉熵等价。