Fisher Information as a Metric Tensor 用度规张量理解和推导费舍信息矩阵
本文在 codex 辅助下完成.
1 Basic Prerequisites
- Jacobian \(J\) 看作流形局部的线性变换, 如何解读 \(J\) 中的信息.
- Metric tensor \(G\) 的理解:
- \(G\) 作为一个表格, 如何解读其中的信息.
- \(G\) 和 \(J\) 的关系: \[G=J^t J\]
- \(G\) 作为 bilinear form, 定义了内积结构: \[\langle u, v \rangle = u^t G v\]
核心问题: How to Define “Intrinsic” Gradient!
2 Takeaway
如果你忘记了本章的内容, 请看看下面这个例子:
如果你对 Jacobian 和 Metric tensor 有一定认知, 很容易写出:
\[ J = \begin{pmatrix} 2 & 1 \\ 0 & 2 \end{pmatrix}, G = J^t J = \begin{pmatrix} 4 & 2 \\ 2 & 5 \end{pmatrix}. \]
直觉上来看, 蓝色的梯度应该是更 efficient 的下降方向, 因为他直接映射回左图的梯度, 但是绿色的梯度却是直接在右图上算出来的 (很容易得到), 如何从绿色的梯度得到蓝色的梯度呢? 我们可以观察到:
\[ G \text{ blue} = \text{green} \]
这里的 \(G\) 就是所谓 fisher information matrix, 或者说那个 metric tensor. 下文将直接在 parameter space 上算出来的梯度 (没有考虑 metric) 称为 ordinary gradient flow, 而考虑 metric 后的梯度称为 intrinsic gradient flow.
3 An Euclidean Example
同一个 manifold 可以有不同的 parameterizations. 改变 coordinates 不会改变原 metric 诱导的 scalar field 在对应点上的值, 但直接在 parameter plane 中计算 ordinary gradient, 相当于默认使用该平面的 Euclidean metric. 这样计算出来的梯度跟考虑 metric 后的 intrinsic gradient 一般不同, 我们来感受一下这件事情:
考虑半径为 \(R>0\) 的 upper hemisphere
\[ \mathcal H=\{(X,Y,Z):X^2+Y^2+Z^2=R^2,\ Z>0\}, \quad ds^2=dX^2+dY^2+dZ^2. \]
3.1 Six coordinate descriptions of a hemisphere
下面是 6 种不同的对 \(\mathcal{H}\) 参数化的方法, 具体细节见:
3.1.1 a. Equatorial projection
将上半球正交投影到赤道平面,取 \((a,b)=(X,Y)\)。记 \(z=\sqrt{R^2-a^2-b^2}\):
\[ f_a(a,b)=(a,b,z),\qquad a^2+b^2<R^2. \]
Inverse 为 \(a=X,b=Y\),因此这个 open disk 确实覆盖整个 open upper hemisphere,包括 north pole。
\[ J_a=\begin{pmatrix}1&0\\0&1\\-a/z&-b/z\end{pmatrix}, \qquad \boxed{G_a=\frac1{R^2-a^2-b^2} \begin{pmatrix}R^2-b^2&ab\\ab&R^2-a^2\end{pmatrix}.} \]
靠近 equator 时,平面中很小的 radial displacement 会对应较大的球面移动,因此 metric 的 radial 分量发散。
3.1.2 b. Equatorial projection in polar coordinates
在 a 的 equatorial plane 中令 \(a=r\cos\phi\)、\(b=r\sin\phi\)。记 \(z=\sqrt{R^2-r^2}\),则
\[ f_b(r,\phi)=(r\cos\phi,r\sin\phi,\sqrt{R^2-r^2}), \qquad 0<r<R,\quad \phi\in\mathbb R/(2\pi\mathbb Z). \]
代入即得 \(X^2+Y^2+Z^2=r^2+(R^2-r^2)=R^2\)。Inverse 为 \(r=\sqrt{X^2+Y^2}\)、\(\phi=\operatorname{atan2}(Y,X)\);它覆盖除 north pole 外的 upper hemisphere。\(r=0\) 时所有 \(\phi\) 对应同一个 pole,这是 polar coordinates 的 singularity。
\[ J_b= \begin{pmatrix} \cos\phi&-r\sin\phi\\ \sin\phi&r\cos\phi\\ -r/z&0 \end{pmatrix}, \qquad \boxed{G_b=J_b^t J_b= \begin{pmatrix} R^2/(R^2-r^2)&0\\ 0&r^2 \end{pmatrix}.} \]
两条 columns 的 dot product 为零;它们的 squared lengths 分别是 \(1+r^2/z^2=R^2/(R^2-r^2)\) 和 \(r^2\)。因此 radial 与 angular directions orthogonal,但对应的长度尺度不同。这也说明:即使 a 与 b 使用同一个 projection plane,改用 \((r,\phi)\) 后,若直接将 coordinate metric 当成 identity,ordinary gradient flow 仍会改变。
3.1.3 c. Vertical-cylinder coordinates
取 height \(h=Z\) 和绕 \(Z\) axis 的 azimuth \(\phi\),令 \(r=\sqrt{R^2-h^2}\):
\[ f_c(h,\phi)=(r\cos\phi,r\sin\phi,h), \qquad 0<h<R,\quad \phi\in\mathbb R/(2\pi\mathbb Z). \]
Inverse 为 \(h=Z,\phi=\operatorname{atan2}(Y,X)\)。它覆盖除 north pole 外的半球;pole 处所有 \(\phi\) 对应同一点。
\[ J_c=\begin{pmatrix} -h\cos\phi/r&-r\sin\phi\\ -h\sin\phi/r&r\cos\phi\\ 1&0 \end{pmatrix}, \qquad \boxed{G_c=\begin{pmatrix}R^2/(R^2-h^2)&0\\0&R^2-h^2\end{pmatrix}.} \]
\(\det G_c=R^2\),所以 area element 为 \(R\,dh\,d\phi\)。圆柱展开后用 \((h,R\phi)\) 表示实际长度时,这是 equal-area projection;它一般不保留 angle。
3.1.4 d. Spherical coordinates
\[ f_d(\theta,\phi)= R(\sin\theta\cos\phi,\sin\theta\sin\phi,\cos\theta), \qquad 0<\theta<\frac\pi2. \]
Inverse 为 \(\theta=\arccos(Z/R),\phi=\operatorname{atan2}(Y,X)\),同样在 north pole 处退化。
\[ J_d=R\begin{pmatrix} \cos\theta\cos\phi&-\sin\theta\sin\phi\\ \cos\theta\sin\phi&\sin\theta\cos\phi\\ -\sin\theta&0 \end{pmatrix}, \qquad \boxed{G_d=R^2\begin{pmatrix}1&0\\0&\sin^2\theta\end{pmatrix}.} \]
\(G_c,G_d\) 都是 diagonal,只意味着两条 coordinate directions orthogonal。要相对于 coordinate plane 的 Euclidean metric 保角,需要 \(G=\lambda I\);diagonal 本身不够。
3.1.5 e. Stereographic projection from the south pole
连接 south pole \(S=(0,0,-R)\) 与球面点 \((X,Y,Z)\),这条直线与赤道平面 \(Z=0\) 的交点为
\[ (x,y)=\left(\frac{RX}{R+Z},\frac{RY}{R+Z}\right). \]
反解这条直线与 radius-\(R\) sphere 的交点。令 \(D=R^2+x^2+y^2\),得到
\[ \boxed{f_e(x,y)=\left(\frac{2R^2x}{D},\frac{2R^2y}{D},\frac{R(R^2-x^2-y^2)}{D}\right),\qquad x^2+y^2<R^2.} \]
这是覆盖整个 open upper hemisphere 的 global chart。代入可验证球面方程;\((0,0)\) 对应 north pole,radius-\(R\) circle 对应 equator。
\[ J_e=\frac{2R^2}{D^2} \begin{pmatrix}D-2x^2&-2xy\\-2xy&D-2y^2\\-2Rx&-2Ry\end{pmatrix}, \qquad \boxed{G_e=\frac{4R^4}{(R^2+x^2+y^2)^2}I.} \]
因此 stereographic projection 是 conformal。\(G_e^{-1}\nabla H_e\) 与 \(\nabla H_e\) 只差 positive scalar:对于同一个 loss,ordinary 与 intrinsic gradient flow 的路径相同,速度一般不同。这是六张图中一个特别有用的对照。
3.1.6 f. Stereographic projection in polar coordinates
在上一张 projection plane 中令 \(x=\rho\cos\phi,y=\rho\sin\phi\)。记 \(D=R^2+\rho^2\):
\[ \boxed{f_f(\rho,\phi)=\left( \frac{2R^2\rho\cos\phi}{D},\frac{2R^2\rho\sin\phi}{D},\frac{R(R^2-\rho^2)}{D} \right),\qquad 0<\rho<R.} \]
Inverse 为 \(\rho=R\sqrt{X^2+Y^2}/(R+Z)=R\tan(\theta/2)\) 和 \(\phi=\operatorname{atan2}(Y,X)\)。
\[ J_f=\begin{pmatrix} 2R^2(R^2-\rho^2)\cos\phi/D^2&-2R^2\rho\sin\phi/D\\ 2R^2(R^2-\rho^2)\sin\phi/D^2&2R^2\rho\cos\phi/D\\ -4R^3\rho/D^2&0 \end{pmatrix}, \qquad \boxed{G_f=\frac{4R^4}{(R^2+\rho^2)^2} \begin{pmatrix}1&0\\0&\rho^2\end{pmatrix}.} \]
Stereographic projection 仍然是 conformal,但 polar plane 本身的 Euclidean line element 是 \(d\rho^2+\rho^2d\phi^2\)。如果把画成矩形的 \((\rho,\phi)\) coordinates 当成 metric 为 identity 的平面,ordinary gradient 就不再只是 intrinsic gradient 的 scalar multiple。 图中的 Euclidean GD f 比较的正是这种 coordinate update。
下面的 scalar field 是以 \(T\) 为中心的 geodesic distance, 图中为了让投影图比例合适, 取 \(R = 6 \approx 2\pi\).
3.2 Some Questions
- 为什么 ordinary gradient 和 intrinsic gradient 不一样?
- 这个问题在前一章讲过了, 并且他们俩的区别就是 metric tensor
- 为什么 stereographic projection 的 ordinary gradient 和 intrinsic gradient 方向完全一样?
- 因为 stereographic projection 是 conformal 的, 也就是 \(G\) 是一个 scalar
- spherical 参数化的 \(G\) 是 diagonal 的, 为什么 ordinary gradient 和 intrinsic gradient 方向还是不一样?
- 因为 diagonal 只意味着两条 coordinate directions orthogonal, 横竖 stretch 的比例不一样的话, 仍然不能 preserve angles
- 为什么有时候 b 参数化的 ordinary gradient flow 会停在 pole, 而 intrinsic gradient flow 可以继续到达 Target?
- 因为有 coordinate singularity, 这个问题我还没理解其实
- 这些图之间的不变量是什么?
- 在每个 regular chart 内,都有 \[Df_i(-G_i^{-1}\nabla H_i)=-\operatorname{grad}_{\mathbb S_R^2}H_0,\qquad i=a,\ldots,f.\] 同一个 scalar field 的 coordinate derivatives 不同, 但正确考虑 metric 后, 映回球面的是同一个 intrinsic direction.
4 A non-Euclidean Example
4.1 Manifold of 1D Gaussian Distributions
现在考虑
\[ \mathcal M=\{\mathcal N(\mu,\sigma^2):\mu\in\mathbb R,\ \sigma>0\}. \]
random variable 是一维的,但 distribution 由 mean 和 standard deviation 两个 parameters 决定,因此 \(\mathcal M\) 是 two-dimensional。为这个 manifold 选择 Fisher metric:
\[ \boxed{ F(\mu,\sigma)= \begin{pmatrix}1/\sigma^2&0\\0&2/\sigma^2\end{pmatrix}, \qquad ds_F^2=\frac{d\mu^2+2d\sigma^2}{\sigma^2}. } \]
它的来源会在下一节推导。先看含义:相同的 \(d\mu\),在较小的 \(\sigma\) 处对应更大的 Fisher length。例如,固定 standard deviation,把 mean 增加 \(0.1\),精确的 KL 是
\[ D_{\mathrm{KL}}\bigl(\mathcal N(\mu,\sigma^2)\|\mathcal N(\mu+0.1,\sigma^2)\bigr) =\frac{0.1^2}{2\sigma^2}. \]
当 \(\sigma=1\) 时,KL 为 \(0.005\);当 \(\sigma=0.1\) 时,KL 为 \(0.5\)。parameter 移动相同数值,不代表 distribution 改变相同程度。
4.2 A hyperbolic geometry
令 \(u=\mu/\sqrt2\)、\(v=\sigma\),则
\[ ds_F^2=2\frac{du^2+dv^2}{v^2}, \]
这是缩放后的 hyperbolic upper-half-plane metric,curvature 为 \(-1/2\)。它不能作为一个完整的 smooth surface,isometrically embedded 在普通 Euclidean \(\mathbb R^3\) 中;但可以嵌入三维 Minkowski space:
\[ X=\sqrt2\frac uv,\qquad Y=\sqrt2\frac{u^2+v^2-1}{2v},\qquad Z=\sqrt2\frac{u^2+v^2+1}{2v}. \]
这些点满足 \(Z^2-X^2-Y^2=2\)、\(Z>0\),构成 hyperboloid 的 upper sheet。这里的 ambient metric 是
\[ dX^2+dY^2-dZ^2, \]
而不是三个正号。代入上面的 embedding,正好得到 \(ds_F^2\)。因此,若记这个 embedding 的 Jacobian 为 \(J\),应当写
\[ F=J^t\operatorname{diag}(1,1,-1)J, \]
而不是 \(J^tJ\)。Ambient Minkowski metric 不定号,但限制到曲面的 tangent directions 后是 positive definite;Gaussian manifold 上的 Fisher metric 仍是 Riemannian metric。
下面依然以到 Target 的 geodesic distance 作为 heatmap。两个 Gaussian 的 Fisher–Rao distance 为
\[ d_F\bigl((\mu,\sigma),(\mu_T,\sigma_T)\bigr) =\sqrt2\operatorname{arcosh}\left( 1+\frac{(\mu-\mu_T)^2/2+(\sigma-\sigma_T)^2}{2\sigma\sigma_T} \right). \]
左图显示 hyperboloid 的三维形状,右图显示 \((\mu,\sigma)\) coordinates;对应点的 heatmap 值相同。左图中屏幕上的 Euclidean 长度并不是 Fisher length,曲面的「碗状」外观也不代表 intrinsic curvature 为正。
在右图,ordinary descent 使用 \(-\nabla h\),而 intrinsic descent 使用
\[ -F^{-1}\nabla h =-\begin{pmatrix} \sigma^2\partial_\mu h\\ \frac{\sigma^2}{2}\partial_\sigma h \end{pmatrix}. \]
两种更新的区别仍然是:有没有按真实 metric 比较移动的大小。这里只是不能再通过普通三维 Euclidean length 来读取这个 metric。
5 Fisher Information as a Metric Tensor
5.1 Fisher information
暂时不谈 geometry。统计学中,Fisher information 描述 observations 对未知 parameter 的局部辨别能力。对于 model \(p_\theta(x)\),定义 score vector:
\[ s_\theta(x)=\nabla_\theta\log p_\theta(x). \]
它衡量给定 observation \(x\) 时,log likelihood 对 parameter 的敏感程度。单个 observation 的 Fisher information matrix 定义为
\[ \boxed{F(\theta)=\mathbb E_{x\sim p_\theta}[s_\theta(x)s_\theta(x)^t].} \]
对于 scalar parameter,它就是 squared score 的 expectation。在常用的 regularity conditions 下,\(\mathbb E[s_\theta]=0\),因此 \(F\) 也是 score 的 covariance matrix。独立同分布的 \(n\) 个 observations 的 information 为 \(nF\);例如 scalar unbiased estimator 的 Cramér–Rao bound 为 \(\operatorname{Var}(\hat\theta)\geq1/(nF)\)。这说明 Fisher information 最初与 estimation 的精度有关,并不依赖 manifold 的表述。
以 Gaussian 为例,令 \(z=(x-\mu)/\sigma\sim\mathcal N(0,1)\),则
\[ \partial_\mu\log p=\frac z\sigma, \qquad \partial_\sigma\log p=\frac{z^2-1}{\sigma}. \]
利用 \(\mathbb E[z^2]=1\)、\(\mathbb E[z^3]=0\)、\(\mathbb E[z^4]=3\),得到
\[ F_{\mu\mu}=\frac1{\sigma^2},\qquad F_{\mu\sigma}=0,\qquad F_{\sigma\sigma}=\frac{\mathbb E[(z^2-1)^2]}{\sigma^2}=\frac2{\sigma^2}. \]
这就是前一节使用的 metric matrix:
\[ F(\mu,\sigma)=\begin{pmatrix}1/\sigma^2&0\\0&2/\sigma^2\end{pmatrix}. \]
5.2 Derive fisher information from KL divergence
任意 metric tensor 并不都等于 FIM。两者的联系来自一个具体选择:用相邻 distributions 之间 KL 的二阶变化来定义局部长度。
固定 \(p_\theta\),只对第二个 distribution 的 parameter 展开:
\[ \begin{aligned} D_{\mathrm{KL}}(p_\theta\|p_{\theta+\mathrm{d}\theta}) &=\mathbb E_{p_\theta}[\log p_\theta-\log p_{\theta+\mathrm{d}\theta}]\\ &=-\mathbb E[\nabla\log p_\theta]^t \mathrm{d}\theta -\frac12\mathrm{d}\theta^t\mathbb E[\nabla^2\log p_\theta]\mathrm{d}\theta +O(\|\mathrm{d}\theta\|^3). \end{aligned} \]
假设 support 不随 parameter 改变、density 足够 smooth,且 differentiation 可以与 integration 交换。由于 \(\int p_\theta(x)\,dx=1\),
\[ \mathbb E[\partial_i\log p_\theta] =\int\partial_i p_\theta(x)\,dx=0. \]
再利用
\[ \partial_i\partial_j\log p_\theta =\frac{\partial_i\partial_jp_\theta}{p_\theta} -\frac{\partial_i p_\theta\,\partial_j p_\theta}{p_\theta^2}, \]
乘以 \(p_\theta\) 后积分,第一项变成 \(\partial_i\partial_j1=0\),于是
\[ -\mathbb E[\partial_i\partial_j\log p_\theta] =\mathbb E[(\partial_i\log p_\theta)(\partial_j\log p_\theta)] =F_{ij}. \]
最终得到
\[ \boxed{ D_{\mathrm{KL}}(p_\theta\|p_{\theta+\mathrm{d}\theta}) =\frac12\mathrm{d}\theta^tF(\theta)\mathrm{d}\theta+O(\|\mathrm{d}\theta\|^3). } \]
因此,定义 \(ds_F^2=\mathrm{d}\theta^tF\mathrm{d}\theta\) 时,FIM 就是 metric tensor。更直观地,
\[ ds_F^2 =\mathbb E_{p_\theta}\left[ \bigl(\nabla\log p_\theta(x)^t\mathrm{d}\theta\bigr)^2 \right]. \]
括号内是这次 parameter 更新造成的 log density 的一阶变化。如果一个移动让 log density 改变得更多,它的 Fisher length 就更大。 这个表达式保证 \(F\) positive semidefinite;要得到非退化的 Riemannian metric,还需要 model 在局部没有一阶上完全不可辨别的 parameter directions。
这里有两个不能混淆的尺度:
- 长度公式是 \(ds_F^2=\mathrm{d}\theta^tF\mathrm{d}\theta\),没有 \(1/2\);KL 公式中的 \(1/2\) 来自 Taylor expansion。
- categorical 例子使用 unit sphere \(x_i=\sqrt{p_i}\),所以 \(ds_F^2=\sum_i dp_i^2/p_i=4\sum_i dx_i^2\),即 \(F=4G_{\mathrm{sphere}}\)。换成 \(x_i=2\sqrt{p_i}\),才与标准 Fisher metric 完全一致。
KL 本身不是 distance metric。它的局部二阶项定义 Fisher metric;沿路径积分 Fisher length,再寻找最短路径,才得到 Fisher–Rao distance。对于相距较远的 distributions,不能把 KL 当成 Fisher–Rao distance 的平方的一半。
6 Conclusion
Natural gradient descent 的更新写成
\[ \boxed{\theta_{t+1}=\theta_t-\eta F(\theta_t)^{-1}\nabla_\theta L(\theta_t).} \]
理解这个公式,可以抓住四件事:
- 同一个 loss,不同的 coordinates。 Heatmap 在对应点上的值不变,但直接使用 coordinate plane 的 Euclidean gradient,会隐含地把 metric 换成 identity。
- Metric 规定什么叫同样大的移动。 \(G\) 记录 coordinate edges 的长度和夹角;用 \(G^{-1}\) 修正 gradient,才是在真实步长约束下选择最快下降方向。
- Fisher 是一个特定的 metric。 它来自 KL 的局部二阶项,不是任意 metric 的别名,也不是一般 training loss 的 Hessian。
- Intrinsic 不等于总沿 geodesic。 只有适当的 objective,例如本文的到 Target 的 distance,才产生这样的路径;coordinate invariance 也主要指 infinitesimal direction,而不是任意有限步长的精确重合。
在大型 neural networks 中,完整 FIM 往往既难以存储,也可能 singular。实现时通常求解 \((F+\lambda I)v=\nabla L\),再更新 \(\theta\leftarrow\theta-\eta v\),或使用结构化近似,而不是显式求 inverse。Damping 和近似会改变理想的 geometry。还应区分 model expectation 定义的 Fisher 与直接使用训练 labels 的 empirical Fisher,二者一般不相等。