math-skill 2.1.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (234) hide show
  1. package/README.en-US.md +159 -200
  2. package/README.md +159 -200
  3. package/agents/math-critic.en.md +2 -2
  4. package/agents/math-critic.md +8 -8
  5. package/commands/ask.md +3 -10
  6. package/design-patterns/attention/equivariant-attention.en.md +72 -0
  7. package/design-patterns/attention/equivariant-attention.md +72 -0
  8. package/design-patterns/attention/geometry-aware-attention.en.md +73 -0
  9. package/design-patterns/attention/geometry-aware-attention.md +72 -0
  10. package/design-patterns/attention/information-bottleneck-attention.en.md +72 -0
  11. package/design-patterns/attention/information-bottleneck-attention.md +72 -0
  12. package/design-patterns/attention/projection-attention.en.md +68 -0
  13. package/design-patterns/attention/projection-attention.md +68 -0
  14. package/design-patterns/attention/spectral-attention.en.md +71 -0
  15. package/design-patterns/attention/spectral-attention.md +71 -0
  16. package/design-patterns/compression/leverage-score-selection.en.md +71 -0
  17. package/design-patterns/compression/leverage-score-selection.md +71 -0
  18. package/design-patterns/compression/low-rank-kv-cache.en.md +60 -0
  19. package/design-patterns/compression/low-rank-kv-cache.md +60 -0
  20. package/design-patterns/compression/spectral-token-pruning.en.md +61 -0
  21. package/design-patterns/compression/spectral-token-pruning.md +61 -0
  22. package/design-patterns/compression/topology-preserving-compression.en.md +64 -0
  23. package/design-patterns/compression/topology-preserving-compression.md +64 -0
  24. package/design-patterns/loss/constraint-penalty.en.md +67 -0
  25. package/design-patterns/loss/constraint-penalty.md +78 -0
  26. package/design-patterns/loss/contrastive-loss.en.md +59 -0
  27. package/design-patterns/loss/contrastive-loss.md +68 -0
  28. package/design-patterns/loss/information-bottleneck-loss.en.md +69 -0
  29. package/design-patterns/loss/information-bottleneck-loss.md +74 -0
  30. package/design-patterns/loss/orthogonality-loss.en.md +56 -0
  31. package/design-patterns/loss/orthogonality-loss.md +60 -0
  32. package/design-patterns/loss/variational-loss.en.md +61 -0
  33. package/design-patterns/loss/variational-loss.md +71 -0
  34. package/design-patterns/representation/equivariant-split.en.md +87 -0
  35. package/design-patterns/representation/equivariant-split.md +89 -0
  36. package/design-patterns/representation/manifold-representation.en.md +85 -0
  37. package/design-patterns/representation/manifold-representation.md +87 -0
  38. package/design-patterns/representation/shared-private-decomposition.en.md +84 -0
  39. package/design-patterns/representation/shared-private-decomposition.md +86 -0
  40. package/design-patterns/representation/subspace-alignment.en.md +90 -0
  41. package/design-patterns/representation/subspace-alignment.md +92 -0
  42. package/design-patterns/routing/graph-routing.en.md +79 -0
  43. package/design-patterns/routing/graph-routing.md +81 -0
  44. package/design-patterns/routing/moe-routing.en.md +85 -0
  45. package/design-patterns/routing/moe-routing.md +87 -0
  46. package/design-patterns/routing/optimal-transport-routing.en.md +68 -0
  47. package/design-patterns/routing/optimal-transport-routing.md +72 -0
  48. package/design-patterns/routing/spectral-clustering-routing.en.md +88 -0
  49. package/design-patterns/routing/spectral-clustering-routing.md +90 -0
  50. package/knowledge-base/differential-geometry/connection.en.md +51 -0
  51. package/knowledge-base/differential-geometry/connection.md +51 -0
  52. package/knowledge-base/differential-geometry/curvature.en.md +49 -0
  53. package/knowledge-base/differential-geometry/curvature.md +49 -0
  54. package/knowledge-base/differential-geometry/geodesic.en.md +51 -0
  55. package/knowledge-base/differential-geometry/geodesic.md +51 -0
  56. package/knowledge-base/differential-geometry/manifold.en.md +47 -0
  57. package/knowledge-base/differential-geometry/manifold.md +47 -0
  58. package/knowledge-base/differential-geometry/metric-tensor.en.md +50 -0
  59. package/knowledge-base/differential-geometry/metric-tensor.md +50 -0
  60. package/knowledge-base/differential-geometry/tangent-space.en.md +48 -0
  61. package/knowledge-base/differential-geometry/tangent-space.md +48 -0
  62. package/knowledge-base/information-geometry/fisher-metric.en.md +56 -0
  63. package/knowledge-base/information-geometry/fisher-metric.md +56 -0
  64. package/knowledge-base/information-geometry/natural-gradient.en.md +54 -0
  65. package/knowledge-base/information-geometry/natural-gradient.md +54 -0
  66. package/knowledge-base/lie-theory/equivariance.en.md +54 -0
  67. package/knowledge-base/lie-theory/equivariance.md +54 -0
  68. package/knowledge-base/lie-theory/group-action.en.md +51 -0
  69. package/knowledge-base/lie-theory/group-action.md +51 -0
  70. package/knowledge-base/lie-theory/lie-algebra.en.md +51 -0
  71. package/knowledge-base/lie-theory/lie-algebra.md +51 -0
  72. package/knowledge-base/lie-theory/lie-group.en.md +51 -0
  73. package/knowledge-base/lie-theory/lie-group.md +51 -0
  74. package/knowledge-base/lie-theory/representation.en.md +52 -0
  75. package/knowledge-base/lie-theory/representation.md +52 -0
  76. package/knowledge-base/matrix-analysis/low-rank-approximation.en.md +49 -0
  77. package/knowledge-base/matrix-analysis/low-rank-approximation.md +49 -0
  78. package/knowledge-base/matrix-analysis/matrix-perturbation.en.md +49 -0
  79. package/knowledge-base/matrix-analysis/matrix-perturbation.md +49 -0
  80. package/knowledge-base/matrix-analysis/positive-semidefinite.en.md +50 -0
  81. package/knowledge-base/matrix-analysis/positive-semidefinite.md +50 -0
  82. package/knowledge-base/matrix-analysis/projection.en.md +47 -0
  83. package/knowledge-base/matrix-analysis/projection.md +47 -0
  84. package/knowledge-base/matrix-analysis/spectral-decomposition.en.md +48 -0
  85. package/knowledge-base/matrix-analysis/spectral-decomposition.md +48 -0
  86. package/knowledge-base/optimization/constrained-optimization.en.md +53 -0
  87. package/knowledge-base/optimization/constrained-optimization.md +53 -0
  88. package/knowledge-base/optimization/convex-optimization.en.md +50 -0
  89. package/knowledge-base/optimization/convex-optimization.md +50 -0
  90. package/knowledge-base/optimization/lagrangian-duality.en.md +50 -0
  91. package/knowledge-base/optimization/lagrangian-duality.md +50 -0
  92. package/knowledge-base/optimization/proximal-method.en.md +52 -0
  93. package/knowledge-base/optimization/proximal-method.md +52 -0
  94. package/knowledge-base/optimization/riemannian-optimization.en.md +51 -0
  95. package/knowledge-base/optimization/riemannian-optimization.md +51 -0
  96. package/knowledge-base/overview.en.md +29 -218
  97. package/knowledge-base/overview.md +29 -220
  98. package/knowledge-base/probability/concentration-inequality.en.md +45 -0
  99. package/knowledge-base/probability/concentration-inequality.md +45 -0
  100. package/knowledge-base/probability/entropy.en.md +47 -0
  101. package/knowledge-base/probability/entropy.md +47 -0
  102. package/knowledge-base/probability/fisher-information.en.md +48 -0
  103. package/knowledge-base/probability/fisher-information.md +48 -0
  104. package/knowledge-base/probability/information-bottleneck.en.md +49 -0
  105. package/knowledge-base/probability/information-bottleneck.md +49 -0
  106. package/knowledge-base/probability/kl-divergence.en.md +51 -0
  107. package/knowledge-base/probability/kl-divergence.md +51 -0
  108. package/knowledge-base/topology/euler-characteristic.en.md +54 -0
  109. package/knowledge-base/topology/euler-characteristic.md +54 -0
  110. package/knowledge-base/topology/fundamental-group.en.md +52 -0
  111. package/knowledge-base/topology/fundamental-group.md +52 -0
  112. package/knowledge-base/topology/persistent-homology.en.md +54 -0
  113. package/knowledge-base/topology/persistent-homology.md +54 -0
  114. package/lenses/algorithmic.en.md +49 -0
  115. package/lenses/algorithmic.md +49 -0
  116. package/lenses/axiomatization.en.md +48 -0
  117. package/lenses/axiomatization.md +48 -0
  118. package/lenses/categorical.en.md +48 -0
  119. package/lenses/categorical.md +48 -0
  120. package/lenses/causal.en.md +49 -0
  121. package/lenses/causal.md +49 -0
  122. package/lenses/duality.en.md +47 -0
  123. package/lenses/duality.md +47 -0
  124. package/lenses/game.en.md +50 -0
  125. package/lenses/game.md +50 -0
  126. package/lenses/geometric.en.md +53 -0
  127. package/lenses/geometric.md +53 -0
  128. package/lenses/local-to-global.en.md +52 -0
  129. package/lenses/local-to-global.md +52 -0
  130. package/lenses/perturbation.en.md +51 -0
  131. package/lenses/perturbation.md +51 -0
  132. package/lenses/probabilistic.en.md +48 -0
  133. package/lenses/probabilistic.md +48 -0
  134. package/lenses/projection.en.md +50 -0
  135. package/lenses/projection.md +50 -0
  136. package/lenses/spectral.en.md +52 -0
  137. package/lenses/spectral.md +52 -0
  138. package/lenses/symmetry.en.md +49 -0
  139. package/lenses/symmetry.md +49 -0
  140. package/lenses/topological.en.md +48 -0
  141. package/lenses/topological.md +48 -0
  142. package/lenses/variational.en.md +48 -0
  143. package/lenses/variational.md +48 -0
  144. package/package.json +9 -3
  145. package/references/books/abstract-algebra.md +5 -5
  146. package/references/books/algebraic-geometry-rising-sea.md +5 -5
  147. package/references/books/differential-geometry.md +3 -3
  148. package/references/books/matrix-analysis.md +4 -4
  149. package/references/books/micro-lie-theory.md +3 -3
  150. package/references/books/optimization-ml.md +1 -1
  151. package/references/books/smooth-manifolds.md +3 -3
  152. package/references/gpu-friendly-math.en.md +8 -8
  153. package/references/gpu-friendly-math.md +2 -2
  154. package/references/inspiration.en.md +1 -1
  155. package/references/inspiration.md +2 -2
  156. package/skills/math-research-activator/SKILL.en.md +161 -106
  157. package/skills/math-research-activator/SKILL.md +162 -110
  158. package/skills/math-research-activator/original-texts.en.md +9 -9
  159. package/skills/math-research-activator/original-texts.md +11 -11
  160. package/commands/abstraction.md +0 -11
  161. package/commands/algorithmic-thinking.md +0 -11
  162. package/commands/axiomatization.md +0 -11
  163. package/commands/causal-inference.md +0 -11
  164. package/commands/discrete-combinatorial.md +0 -11
  165. package/commands/game-theory.md +0 -11
  166. package/commands/induction-analogy.md +0 -11
  167. package/commands/information-theory.md +0 -11
  168. package/commands/logic-deduction.md +0 -11
  169. package/commands/modeling.md +0 -11
  170. package/commands/optimization.md +0 -11
  171. package/commands/probability-statistics.md +0 -11
  172. package/commands/symmetry-invariance.md +0 -11
  173. package/commands/topological-thinking.md +0 -11
  174. package/commands/transformation.md +0 -11
  175. package/skills/abstraction/SKILL.en.md +0 -117
  176. package/skills/abstraction/SKILL.md +0 -121
  177. package/skills/abstraction/original-texts.en.md +0 -163
  178. package/skills/abstraction/original-texts.md +0 -175
  179. package/skills/algorithmic-thinking/SKILL.en.md +0 -132
  180. package/skills/algorithmic-thinking/SKILL.md +0 -138
  181. package/skills/algorithmic-thinking/original-texts.en.md +0 -253
  182. package/skills/algorithmic-thinking/original-texts.md +0 -256
  183. package/skills/axiomatization/SKILL.en.md +0 -144
  184. package/skills/axiomatization/SKILL.md +0 -151
  185. package/skills/axiomatization/original-texts.en.md +0 -154
  186. package/skills/axiomatization/original-texts.md +0 -160
  187. package/skills/causal-inference/SKILL.en.md +0 -147
  188. package/skills/causal-inference/SKILL.md +0 -151
  189. package/skills/causal-inference/original-texts.en.md +0 -136
  190. package/skills/causal-inference/original-texts.md +0 -167
  191. package/skills/discrete-combinatorial/SKILL.en.md +0 -124
  192. package/skills/discrete-combinatorial/SKILL.md +0 -131
  193. package/skills/discrete-combinatorial/original-texts.en.md +0 -184
  194. package/skills/discrete-combinatorial/original-texts.md +0 -185
  195. package/skills/game-theory/SKILL.en.md +0 -117
  196. package/skills/game-theory/SKILL.md +0 -123
  197. package/skills/game-theory/original-texts.en.md +0 -131
  198. package/skills/game-theory/original-texts.md +0 -131
  199. package/skills/induction-analogy/SKILL.en.md +0 -145
  200. package/skills/induction-analogy/SKILL.md +0 -152
  201. package/skills/induction-analogy/original-texts.en.md +0 -140
  202. package/skills/induction-analogy/original-texts.md +0 -154
  203. package/skills/information-theory/SKILL.en.md +0 -134
  204. package/skills/information-theory/SKILL.md +0 -140
  205. package/skills/information-theory/original-texts.en.md +0 -127
  206. package/skills/information-theory/original-texts.md +0 -127
  207. package/skills/logic-deduction/SKILL.en.md +0 -130
  208. package/skills/logic-deduction/SKILL.md +0 -135
  209. package/skills/logic-deduction/original-texts.en.md +0 -160
  210. package/skills/logic-deduction/original-texts.md +0 -173
  211. package/skills/modeling/SKILL.en.md +0 -135
  212. package/skills/modeling/SKILL.md +0 -139
  213. package/skills/modeling/original-texts.en.md +0 -162
  214. package/skills/modeling/original-texts.md +0 -165
  215. package/skills/optimization/SKILL.en.md +0 -129
  216. package/skills/optimization/SKILL.md +0 -135
  217. package/skills/optimization/original-texts.en.md +0 -167
  218. package/skills/optimization/original-texts.md +0 -168
  219. package/skills/probability-statistics/SKILL.en.md +0 -146
  220. package/skills/probability-statistics/SKILL.md +0 -151
  221. package/skills/probability-statistics/original-texts.en.md +0 -191
  222. package/skills/probability-statistics/original-texts.md +0 -193
  223. package/skills/symmetry-invariance/SKILL.en.md +0 -135
  224. package/skills/symmetry-invariance/SKILL.md +0 -139
  225. package/skills/symmetry-invariance/original-texts.en.md +0 -206
  226. package/skills/symmetry-invariance/original-texts.md +0 -221
  227. package/skills/topological-thinking/SKILL.en.md +0 -124
  228. package/skills/topological-thinking/SKILL.md +0 -128
  229. package/skills/topological-thinking/original-texts.en.md +0 -134
  230. package/skills/topological-thinking/original-texts.md +0 -164
  231. package/skills/transformation/SKILL.en.md +0 -120
  232. package/skills/transformation/SKILL.md +0 -124
  233. package/skills/transformation/original-texts.en.md +0 -204
  234. package/skills/transformation/original-texts.md +0 -216
@@ -0,0 +1,51 @@
1
+ # 测地线 (Geodesic)
2
+
3
+ ## 最小定义
4
+
5
+ 测地线是流形上局部最短(或极值长度)的路径 $\gamma: [0,1] \to M$,满足自平行条件 $\nabla_{\dot\gamma} \dot\gamma = 0$——即切向量沿自身平行移动不变。指数映射 $\exp_p(v)$ 将切向量 $v \in T_pM$ 映为从 $p$ 出发、初速为 $v$ 的测地线在 $t=1$ 处的终点。
6
+
7
+ ## 核心公式
8
+
9
+ - 测地方程:$\ddot\gamma^k + \sum_{ij} \Gamma^k_{ij} \dot\gamma^i \dot\gamma^j = 0$
10
+ - 指数映射:$\exp_p(v) = \gamma_v(1)$,其中 $\gamma_v$ 是 $\gamma(0)=p, \dot\gamma(0)=v$ 的测地线
11
+ - 对数映射:$\log_p(q) = v \in T_pM$ 使得 $\exp_p(v) = q$(指数映射的逆)
12
+ - Retraction(工程近似):$R_p(v) \approx \exp_p(v)$,只需一阶近似即可用于优化
13
+ - 球面闭式:$\exp_p(v) = \cos(\|v\|) p + \sin(\|v\|) \frac{v}{\|v\|}$
14
+
15
+ ## 适用问题
16
+
17
+ - 约束优化:在 SPD/Stiefel/Grassmann/双曲流形上做 SGD,更新步需要沿测地线移动
18
+ - 隐空间插值:latent space 中两点间的测地线比欧氏直线更尊重数据流形结构
19
+ - 流形上的距离计算:$d(p,q) = \|\log_p(q)\|_g$
20
+ - 数据增广:沿测地线采样生成新训练样本
21
+
22
+ ## AI 设计翻译
23
+
24
+ - **Retraction-based 优化器**:每步做 $x_{k+1} = R_{x_k}(-\eta \cdot \text{grad})$,用闭式 retraction 替代 ODE 积分;球面用旋转、Stiefel 用 QR/Cayley、SO(3) 用 Rodrigues
25
+ - **测地线插值层**:在球面/双曲 latent space 中用闭式测地线做 mixup 和插值,$\gamma(t) = \exp_p(t \cdot \log_p(q))$
26
+ - **流形上的 momentum**:将动量向量通过 vector transport(平行移动的离散版)从 $T_{x_k}M$ 搬到 $T_{x_{k+1}}M$,再与新梯度合成
27
+ - **指数映射输出头**:网络在切空间 $\mathbb{R}^n$ 中自由预测,经 $\exp_p$ 投回合法流形,天然满足约束
28
+
29
+ ## 工程可行性
30
+
31
+ GPU 友好度取决于是否有闭式 retraction:
32
+ - **有闭式的流形**(球面、双曲、SO(3)、Stiefel-QR):$\exp_p(v)$ 是有限项代数表达式,$O(1)$/样本,可 batched 张量化,GPU 友好
33
+ - **无闭式的流形**:需要数值积分测地方程(二阶 ODE),串行递推,GPU 不友好
34
+ - 闭式 retraction 替代精确 exp:QR 分解、Cayley 变换等一阶近似,牺牲少量精度换取大幅加速
35
+ - 3x3/4x4 小矩阵 exp(SO(3)/SE(3))可融进单 kernel,但吃不满 Tensor Core
36
+ - **低精度致命点**:$\sin\theta/\theta$、$(1-\cos\theta)/\theta^2$ 在 $\theta \to 0$ 时除零,$\theta \to \pi$ 时 log 奇异,fp16 直接 NaN
37
+
38
+ ## 风险与失效条件
39
+
40
+ - **逐步 ODE 积分做测地线**:串行递推杀死 GPU 并行度,必须用闭式 retraction 替代
41
+ - **小角/大角奇异点**:$\theta \to 0$ 和 $\theta \to \pi$ 处的数值不稳定在低精度下被灾难性放大,必须做 Taylor 展开兜底
42
+ - **Retraction 误差累积**:一阶近似在多步迭代中误差可能累积,需偶尔做一次精确投影校正
43
+ - **Cut locus 问题**:指数映射在 cut locus 以外不再是最短路径,$\log_p(q)$ 可能不存在或不唯一
44
+ - **为几何美强行流形化**:欧氏近似已足够的任务硬上测地线,增加复杂度和奇异点风险
45
+
46
+ ## 深入参考
47
+
48
+ - 蒸馏稿:references/books/differential-geometry.md(Ch 13 §13.4 Geodesics, §13.11 Rauch Comparison)
49
+ - 蒸馏稿:references/books/smooth-manifolds.md(Ch 20 The Exponential Map)
50
+ - 原书:Jeffrey M. Lee, *Manifolds and Differential Geometry*, §13.4 Geodesics
51
+ - 原书:John M. Lee, *Introduction to Smooth Manifolds*, Ch 20(指数映射、retraction 原型)
@@ -0,0 +1,47 @@
1
+ # Manifold
2
+
3
+ ## Minimal Definition
4
+
5
+ A manifold is a topological space that is locally homeomorphic to Euclidean space $\mathbb{R}^n$. A smooth manifold further requires that the transition maps $\phi_\beta \circ \phi_\alpha^{-1}$ between coordinate charts are $C^\infty$-smooth, enabling calculus to be performed on curved spaces.
6
+
7
+ ## Core Formulas
8
+
9
+ - Coordinate chart: $(U_\alpha, \phi_\alpha)$, where $\phi_\alpha: U_\alpha \to \mathbb{R}^n$ is a homeomorphism
10
+ - Smooth transition map: $\phi_\beta \circ \phi_\alpha^{-1}: \phi_\alpha(U_\alpha \cap U_\beta) \to \phi_\beta(U_\alpha \cap U_\beta) \in C^\infty$
11
+ - Whitney Embedding Theorem: An $n$-dimensional manifold can be embedded in $\mathbb{R}^{2n}$
12
+
13
+ ## Applicable Problems
14
+
15
+ - Data naturally resides in non-Euclidean spaces: rotations SO(3), covariance matrices SPD(n), directional data $S^2$, graphs and meshes
16
+ - Parameters have geometric constraints (orthogonality, unit norm, low rank) that require identifying the constraint set as a submanifold
17
+ - Latent space geometric modeling: interpolation, clustering, and nearest-neighbor search must respect the intrinsic curved structure of the data
18
+ - Dimensionality reduction and embedding: the manifold hypothesis assumes high-dimensional data lies on a low-dimensional manifold
19
+
20
+ ## AI Design Translation
21
+
22
+ - **Manifold optimizer (Riemannian SGD/Adam)**: Project gradients onto the tangent space and retract back to the manifold, replacing the ad-hoc patchwork of projected gradient descent
23
+ - **Latent space geometry module**: Use manifold structure in the VAE/GAN latent space for geodesic interpolation, replacing Euclidean linear interpolation
24
+ - **Constraint reparameterization layer**: Encode orthogonality/SPD/unit-norm constraints as manifold parameterizations (e.g., Cayley transform, matrix exponential), so outputs naturally satisfy constraints
25
+ - **Manifold-hypothesis-driven architecture design**: Use manifold dimension estimation to guide latent space dimension selection, avoiding the curse of dimensionality
26
+
27
+ ## Engineering Feasibility
28
+
29
+ Moderate GPU friendliness. Coordinate chart transformations are element-wise maps (parallelizable), but the core bottleneck lies in:
30
+ - Transition maps with closed-form expressions (sphere, hyperbolic space): can be directly tensorized as batched per-sample computations, GPU-friendly
31
+ - Transition maps requiring iterative solvers (general manifolds): serial dependencies, not tensorizable, GPU-unfriendly
32
+ - Partition of unity involves locally weighted sums, expressible as sparse matmul
33
+ - Key operation complexity depends on the specific manifold: simple manifolds $O(1)$/sample, complex manifolds may be $O(n^3)$
34
+
35
+ ## Risks and Failure Conditions
36
+
37
+ - **Global chart illusion**: Attempting to cover the entire manifold with a single parameterization inevitably introduces singularities (e.g., gimbal lock with Euler angles); an atlas or redundant parameterization is required
38
+ - **Manifold hypothesis abuse**: Applying manifold structure to data that actually lives in flat Euclidean space is pure over-engineering
39
+ - **Low-precision instability**: Matrix exp/log/eig in coordinate transformations becomes catastrophically unstable under fp16/bf16, often silently diverging
40
+ - **Dimension estimation errors**: The Whitney Embedding Theorem provides an upper bound of $2n$; practical embedding dimension selection lacks theoretical guidance
41
+
42
+ ## Further References
43
+
44
+ - Distillation notes: references/books/smooth-manifolds.md (Ch 1-2 Smooth Manifolds / Smooth Maps)
45
+ - Distillation notes: references/books/differential-geometry.md (Ch 1-2 Differentiable Manifolds / The Tangent Structure)
46
+ - Original text: John M. Lee, *Introduction to Smooth Manifolds*, 2nd Edition, Ch 1-2 (topological manifolds, smooth structures, partition of unity)
47
+ - Original text: Jeffrey M. Lee, *Manifolds and Differential Geometry*, Ch 1-2
@@ -0,0 +1,47 @@
1
+ # 流形 (Manifold)
2
+
3
+ ## 最小定义
4
+
5
+ 流形是局部同胚于欧氏空间 $\mathbb{R}^n$ 的拓扑空间。光滑流形进一步要求坐标卡之间的转移映射 $\phi_\beta \circ \phi_\alpha^{-1}$ 是 $C^\infty$ 光滑的,使得微积分可以在弯曲空间上进行。
6
+
7
+ ## 核心公式
8
+
9
+ - 坐标卡:$(U_\alpha, \phi_\alpha)$,其中 $\phi_\alpha: U_\alpha \to \mathbb{R}^n$ 是同胚
10
+ - 光滑转移映射:$\phi_\beta \circ \phi_\alpha^{-1}: \phi_\alpha(U_\alpha \cap U_\beta) \to \phi_\beta(U_\alpha \cap U_\beta) \in C^\infty$
11
+ - Whitney 嵌入定理:$n$ 维流形可嵌入 $\mathbb{R}^{2n}$
12
+
13
+ ## 适用问题
14
+
15
+ - 数据本身住在非欧空间:旋转 SO(3)、协方差矩阵 SPD(n)、方向数据 $S^2$、图与网格
16
+ - 参数有几何约束(正交、单位范数、低秩),需要把约束集识别为子流形
17
+ - 隐空间几何建模:插值、聚类、最近邻需要尊重数据的内在弯曲结构
18
+ - 降维与嵌入:高维数据的低维流形假设(manifold hypothesis)
19
+
20
+ ## AI 设计翻译
21
+
22
+ - **流形优化器(Riemannian SGD/Adam)**:梯度投影到切空间 + retraction 回流形,替代投影梯度下降的 ad-hoc 修补
23
+ - **隐空间几何模块**:在 VAE/GAN 的 latent space 中用流形结构做测地插值,替代欧氏线性插值
24
+ - **约束重参数化层**:将正交/SPD/单位范数约束编码为流形参数化(如 Cayley 变换、矩阵指数),输出天然满足约束
25
+ - **流形假设驱动的架构设计**:用流形维数估计指导隐空间维度选择,避免维度诅咒
26
+
27
+ ## 工程可行性
28
+
29
+ GPU 友好度中等。坐标卡变换本身是逐元素的映射(可并行),但核心瓶颈在于:
30
+ - 转移映射若为闭式(球面、双曲空间):可直接张量化,batched 逐样本计算,GPU 友好
31
+ - 转移映射若需迭代求解(一般流形):串行依赖、不可张量化,GPU 不友好
32
+ - 单位分解(partition of unity)涉及局部加权求和,可表达为稀疏 matmul
33
+ - 关键操作复杂度取决于具体流形:简单流形 $O(1)$/样本,复杂流形可能 $O(n^3)$
34
+
35
+ ## 风险与失效条件
36
+
37
+ - **全局坐标卡幻觉**:试图用单一参数化覆盖整个流形必有奇点(如欧拉角的 gimbal lock),需要 atlas / 冗余参数化
38
+ - **流形假设滥用**:数据实际分布在平坦欧氏空间时硬套流形结构,纯属过度工程
39
+ - **低精度不稳定**:坐标变换中的矩阵 exp/log/eig 在 fp16/bf16 下灾难性不稳定,常静默发散
40
+ - **维数估计错误**:Whitney 嵌入定理给出上界 $2n$,实际嵌入维数选择缺乏理论指导
41
+
42
+ ## 深入参考
43
+
44
+ - 蒸馏稿:references/books/smooth-manifolds.md(Ch 1-2 Smooth Manifolds / Smooth Maps)
45
+ - 蒸馏稿:references/books/differential-geometry.md(Ch 1-2 Differentiable Manifolds / The Tangent Structure)
46
+ - 原书:John M. Lee, *Introduction to Smooth Manifolds*, 2nd Edition, Ch 1-2(拓扑流形、光滑结构、单位分解)
47
+ - 原书:Jeffrey M. Lee, *Manifolds and Differential Geometry*, Ch 1-2
@@ -0,0 +1,50 @@
1
+ # Metric Tensor
2
+
3
+ ## Minimal Definition
4
+
5
+ The metric tensor $g$ is a positive-definite symmetric bilinear form $g_p: T_pM \times T_pM \to \mathbb{R}$ on the tangent space $T_pM$ at each point $p$ of a manifold, defining inner products, lengths, angles, and distances on the manifold. It is the precise quantification of "what is close to what" and "which direction is steepest."
6
+
7
+ ## Core Formulas
8
+
9
+ - Inner product: $\langle u, v \rangle_g = u^T g_p v = \sum_{ij} g_{ij} u^i v^j$
10
+ - Arc length element: $ds^2 = \sum_{ij} g_{ij} dx^i dx^j$
11
+ - Geodesic distance: $d(p,q) = \inf_\gamma \int_0^1 \sqrt{g_{\gamma(t)}(\dot\gamma, \dot\gamma)} \, dt$
12
+ - Musical isomorphism (index raising/lowering): $v^\flat = gv$ (tangent to cotangent), $\omega^\sharp = g^{-1}\omega$ (cotangent to tangent)
13
+ - Fisher-Rao metric: $g_{ij}(\theta) = \mathbb{E}_{p_\theta}\left[\frac{\partial \log p_\theta}{\partial \theta^i} \frac{\partial \log p_\theta}{\partial \theta^j}\right]$
14
+
15
+ ## Applicable Problems
16
+
17
+ - Parameter space is non-flat and non-Euclidean: the natural metric on families of probability distributions is the Fisher information matrix
18
+ - Slow optimization convergence: poor conditioning arises from metric mismatch, remedied by preconditioning with the natural gradient $g^{-1}\nabla L$
19
+ - Distance/similarity must adapt to data geometry: metric learning is essentially learning a $g$
20
+ - Volume computation and density estimation: $\sqrt{\det g}$ gives the volume form on the manifold
21
+
22
+ ## AI Design Translation
23
+
24
+ - **Natural gradient / K-FAC optimizer**: $F^{-1}\nabla L$ where $F$ is the Fisher metric; K-FAC uses the Kronecker factorization $F \approx A \otimes B$ to reduce inversion to two small matrix inversions, and the preconditioning reduces to a GEMM chain
25
+ - **Learnable metric layer**: Parameterize $g = L^T L$ (Cholesky) to learn a task-specific Riemannian metric for metric learning and contrastive learning
26
+ - **Information-geometric regularization**: Replace Euclidean $\|d\theta\|^2$ with the Fisher-Rao distance $\|d\theta\|_F^2 = d\theta^T F d\theta$, making regularization invariant to reparameterization
27
+ - **Fisher-aware learning rate scheduling**: Use $\|g^{-1}\nabla L\|_g$ as the "geometrically correct" gradient norm to guide learning rate selection
28
+
29
+ ## Engineering Feasibility
30
+
31
+ GPU friendliness depends on the structure of the metric:
32
+ - **Diagonal metric** $g = \text{diag}(g_1, \ldots, g_n)$: element-wise multiply/divide, $O(n)$, perfectly GPU-friendly
33
+ - **Kronecker-factored** $g = A \otimes B$: $(A\otimes B)^{-1} = A^{-1}\otimes B^{-1}$, small matrix inversions + GEMM chain, the core trick of K-FAC, GPU-feasible
34
+ - **Block-diagonal metric**: per-block independent inversion, batched small matrix operations, GPU-friendly
35
+ - **Full dense metric**: $n \times n$ matrix inversion $O(n^3)$ + memory $O(n^2)$; with parameter count $N \sim 10^9$, this is immediately ruled out
36
+ - Low-precision risk: the Fisher matrix is often ill-conditioned; inversion under fp16 catastrophically amplifies errors -- **must add damping $F + \lambda I$ and invert in fp32**
37
+
38
+ ## Risks and Failure Conditions
39
+
40
+ - **Ill-conditioned metric matrix**: The condition number of the Fisher matrix can exceed $10^6$; low-precision inversion results are entirely noise
41
+ - **Materializing the full metric matrix**: An $N \times N$ matrix ($N \sim 10^9$) requires $\sim 4$ PB of memory, making materialization impossible
42
+ - **Metric-task mismatch**: The Fisher metric assumes the probabilistic model is correct; under model misspecification, the natural gradient can perform worse than SGD
43
+ - **Dynamic metric update overhead**: The Fisher matrix changes with the parameters; statistical noise from re-estimation at each step may offset preconditioning benefits
44
+
45
+ ## Further References
46
+
47
+ - Distillation notes: references/books/differential-geometry.md (Ch 7 Section 7.6 Metric Tensors, Ch 13 Section 13.1 Levi-Civita)
48
+ - Distillation notes: references/books/smooth-manifolds.md (Ch 13 Riemannian Metrics)
49
+ - Original text: Jeffrey M. Lee, *Manifolds and Differential Geometry*, Section 7.6 Metric Tensors
50
+ - Original text: John M. Lee, *Introduction to Smooth Manifolds*, Ch 13 (Riemannian metrics, musical isomorphisms sharp/flat)
@@ -0,0 +1,50 @@
1
+ # 度量张量 (Metric Tensor)
2
+
3
+ ## 最小定义
4
+
5
+ 度量张量 $g$ 是流形上每点 $p$ 处切空间 $T_pM$ 上的一个正定对称双线性形式 $g_p: T_pM \times T_pM \to \mathbb{R}$,定义了流形上的内积、长度、角度和距离。它是"谁离谁近、什么方向最陡"的精确量化。
6
+
7
+ ## 核心公式
8
+
9
+ - 内积:$\langle u, v \rangle_g = u^T g_p v = \sum_{ij} g_{ij} u^i v^j$
10
+ - 弧长:$ds^2 = \sum_{ij} g_{ij} dx^i dx^j$
11
+ - 测地距离:$d(p,q) = \inf_\gamma \int_0^1 \sqrt{g_{\gamma(t)}(\dot\gamma, \dot\gamma)} \, dt$
12
+ - 升降指标(musical isomorphism):$v^\flat = gv$(切→余切),$\omega^\sharp = g^{-1}\omega$(余切→切)
13
+ - Fisher-Rao 度量:$g_{ij}(\theta) = \mathbb{E}_{p_\theta}\left[\frac{\partial \log p_\theta}{\partial \theta^i} \frac{\partial \log p_\theta}{\partial \theta^j}\right]$
14
+
15
+ ## 适用问题
16
+
17
+ - 参数空间非平坦欧氏:概率分布族上的自然度量是 Fisher 信息矩阵
18
+ - 优化收敛缓慢:条件数差源于度量不匹配,用自然梯度 $g^{-1}\nabla L$ 预条件
19
+ - 距离/相似度需要适应数据几何:度量学习本质是学习一个 $g$
20
+ - 体积计算与密度估计:$\sqrt{\det g}$ 给出流形上的体积形式
21
+
22
+ ## AI 设计翻译
23
+
24
+ - **自然梯度/K-FAC 优化器**:$F^{-1}\nabla L$ 其中 $F$ 是 Fisher 度量;K-FAC 用 Kronecker 因子化 $F \approx A \otimes B$ 使求逆变为两个小矩阵求逆,预条件作用退化为 GEMM 链
25
+ - **可学习度量层**:参数化 $g = L^T L$(Cholesky),学习任务相关的黎曼度量,用于度量学习和对比学习
26
+ - **信息几何正则化**:用 Fisher-Rao 距离 $\|d\theta\|_F^2 = d\theta^T F d\theta$ 替代欧氏 $\|d\theta\|^2$,使正则化对重参数化不变
27
+ - **Fisher 感知的学习率调度**:$\|g^{-1}\nabla L\|_g$ 作为"几何正确"的梯度范数,指导学习率选择
28
+
29
+ ## 工程可行性
30
+
31
+ GPU 友好度取决于度量的结构化程度:
32
+ - **对角度量** $g = \text{diag}(g_1, \ldots, g_n)$:逐元素乘除,$O(n)$,完美 GPU 友好
33
+ - **Kronecker 因子化** $g = A \otimes B$:$(A\otimes B)^{-1} = A^{-1}\otimes B^{-1}$,小矩阵求逆 + GEMM 链,K-FAC 的核心 trick,GPU 可行
34
+ - **块对角度量**:逐块独立求逆,batched 小矩阵运算,GPU 友好
35
+ - **全稠密度量**:$n \times n$ 矩阵求逆 $O(n^3)$ + 显存 $O(n^2)$,参数量 $N \sim 10^9$ 时直接出局
36
+ - 低精度风险:Fisher 矩阵常病态,fp16 下求逆灾难性放大误差,**必须加阻尼 $F + \lambda I$ 并在 fp32 下求逆**
37
+
38
+ ## 风险与失效条件
39
+
40
+ - **度量矩阵病态**:Fisher 矩阵的条件数可达 $10^6$ 以上,低精度求逆结果全是噪声
41
+ - **物化全度量矩阵**:$N \times N$ 矩阵($N \sim 10^9$)需 $\sim 4$ PB 显存,不可能物化
42
+ - **度量与任务不匹配**:Fisher 度量假设概率模型正确,模型误设定时自然梯度可能比 SGD 更差
43
+ - **动态度量更新开销**:Fisher 矩阵随参数变化,每步重新估计的统计噪声可能抵消预条件收益
44
+
45
+ ## 深入参考
46
+
47
+ - 蒸馏稿:references/books/differential-geometry.md(Ch 7 §7.6 Metric Tensors, Ch 13 §13.1 Levi-Civita)
48
+ - 蒸馏稿:references/books/smooth-manifolds.md(Ch 13 Riemannian Metrics)
49
+ - 原书:Jeffrey M. Lee, *Manifolds and Differential Geometry*, §7.6 Metric Tensors
50
+ - 原书:John M. Lee, *Introduction to Smooth Manifolds*, Ch 13(黎曼度量、升降指标 ♯/♭)
@@ -0,0 +1,48 @@
1
+ # Tangent Space
2
+
3
+ ## Minimal Definition
4
+
5
+ The tangent space $T_pM$ is the $n$-dimensional vector space of all tangent vectors to a manifold $M$ at a point $p$, serving as the local linearization of the manifold. The differential (pushforward) of a smooth map $f: M \to N$ at $p$, denoted $df_p: T_pM \to T_{f(p)}N$, is a linear map between tangent spaces.
6
+
7
+ ## Core Formulas
8
+
9
+ - Tangent vector as a derivation: $v(f) = \sum_i v^i \frac{\partial f}{\partial x^i}\bigg|_p$
10
+ - Pushforward (differential): $df_p: T_pM \to T_{f(p)}N$, with coordinate representation given by the Jacobian matrix $J_f(p)$
11
+ - Tangent bundle: $TM = \bigsqcup_{p \in M} T_pM$
12
+ - Cotangent space (the true gradient): $df \in T_p^*M$, which requires the metric to raise the index via $\sharp$ to obtain a tangent vector
13
+
14
+ ## Applicable Problems
15
+
16
+ - Geometric interpretation of backpropagation: the chain rule equals pushforward along composed maps
17
+ - Correct gradient direction computation: autodiff outputs are covectors (1-forms), requiring a metric to convert them into descent directions
18
+ - Gradient projection in constrained optimization: projecting the Euclidean gradient onto the tangent space of the constraint submanifold
19
+ - Linearized approximations on manifolds: using linear methods within the tangent space to handle local problems
20
+
21
+ ## AI Design Translation
22
+
23
+ - **Natural gradient layer**: $\tilde{\nabla} L = g^{-1} \nabla L$, using the Fisher metric to raise the covector (autodiff output) to a tangent vector, invariant under reparameterization
24
+ - **Tangent space projection module**: Under orthogonality/Stiefel constraints, project the gradient onto the tangent space $W\Omega$ (where $\Omega$ is skew-symmetric) to maintain constraints
25
+ - **Jacobian-vector product (JVP) acceleration**: The pushforward $df_p(v)$ naturally corresponds to the JVP, serving as the geometric prototype for forward-mode AD
26
+ - **Tangent space feature representation**: In manifold optimization, store momentum/historical gradients in the tangent space and transport them across points via vector transport
27
+
28
+ ## Engineering Feasibility
29
+
30
+ High GPU friendliness. The core operations of the tangent space are linear algebra:
31
+ - Pushforward $df_p(v) = Jv$: matrix-vector multiplication, $O(n^2)$, naturally batched GEMM
32
+ - Pullback $df_p^*(\omega) = J^T \omega$: transposed matrix-vector multiplication, which is backpropagation itself
33
+ - Tangent space projection $P = I - WW^T$ (Stiefel): a chain of matrix multiplications, GPU-friendly
34
+ - Metric index raising $g^{-1}\nabla L$: depends on the structure of $g$ -- diagonal/Kronecker-factored yields $O(n)$ to $O(n^2)$, full matrix $O(n^3)$ is infeasible
35
+
36
+ ## Risks and Failure Conditions
37
+
38
+ - **Confusing gradient with descent direction**: Forgetting the metric index-raising and directly using the raw autodiff output (covector) as a descent direction (tangent vector) leads to incorrect directions in curved spaces
39
+ - **Large matrix inversion**: Natural gradients require $g^{-1}$; the full Fisher matrix $O(N^3)$ is infeasible and necessitates Kronecker/block-diagonal/low-rank factorization
40
+ - **Confusing tangent space with the ambient space**: Performing tangent-space vector addition directly on a curved manifold ignores nonlinear deviations caused by curvature
41
+ - **Missing vector transport**: Tangent spaces at different points cannot be directly summed; momentum/Adam states require parallel transport to be carried across steps
42
+
43
+ ## Further References
44
+
45
+ - Distillation notes: references/books/smooth-manifolds.md (Ch 3 Tangent Vectors, Ch 11 The Cotangent Bundle)
46
+ - Distillation notes: references/books/differential-geometry.md (Ch 1-2, Ch 7 Tensors)
47
+ - Original text: John M. Lee, *Introduction to Smooth Manifolds*, 2nd Edition, Ch 3 (tangent spaces, pushforward, tangent bundle)
48
+ - Original text: John M. Lee, *Introduction to Smooth Manifolds*, Ch 11 (cotangent bundle, 1-forms, pullback)
@@ -0,0 +1,48 @@
1
+ # 切空间 (Tangent Space)
2
+
3
+ ## 最小定义
4
+
5
+ 切空间 $T_pM$ 是流形 $M$ 在点 $p$ 处的所有切向量构成的 $n$ 维向量空间,是流形的局部线性化。光滑映射 $f: M \to N$ 在 $p$ 处的微分(pushforward)$df_p: T_pM \to T_{f(p)}N$ 是切空间之间的线性映射。
6
+
7
+ ## 核心公式
8
+
9
+ - 切向量作为导子:$v(f) = \sum_i v^i \frac{\partial f}{\partial x^i}\bigg|_p$
10
+ - Pushforward(微分):$df_p: T_pM \to T_{f(p)}N$,坐标表示为 Jacobian 矩阵 $J_f(p)$
11
+ - 切丛:$TM = \bigsqcup_{p \in M} T_pM$
12
+ - 余切空间(梯度真身):$df \in T_p^*M$,需用度量升指标 $\sharp$ 变为切向量
13
+
14
+ ## 适用问题
15
+
16
+ - 反向传播的几何理解:链式法则 = 沿复合映射做 pushforward
17
+ - 梯度方向的正确计算:autodiff 输出是余向量(1-form),需要度量才能变成下降方向
18
+ - 约束优化中梯度投影:将欧氏梯度投影到约束子流形的切空间
19
+ - 流形上的线性化近似:在切空间中用线性方法处理局部问题
20
+
21
+ ## AI 设计翻译
22
+
23
+ - **自然梯度层**:$\tilde{\nabla} L = g^{-1} \nabla L$,用 Fisher 度量将余向量(autodiff 输出)升为切向量,对重参数化不变
24
+ - **切空间投影模块**:在正交/Stiefel 约束下,将梯度投影到切空间 $W\Omega$($\Omega$ 反对称),维持约束
25
+ - **Jacobian-vector product (JVP) 加速**:pushforward $df_p(v)$ 天然对应 JVP,是 forward-mode AD 的几何原型
26
+ - **切空间特征表示**:在流形优化中,将动量/历史梯度存放在切空间中,通过 vector transport 跨点搬运
27
+
28
+ ## 工程可行性
29
+
30
+ GPU 友好度高。切空间的核心操作是线性代数:
31
+ - Pushforward $df_p(v) = Jv$:矩阵-向量乘法,$O(n^2)$,天然 batched GEMM
32
+ - Pullback $df_p^*(\omega) = J^T \omega$:转置矩阵-向量乘法,即反向传播本身
33
+ - 切空间投影 $P = I - WW^T$(Stiefel):矩阵乘法链,GPU 友好
34
+ - 度量升指标 $g^{-1}\nabla L$:取决于 $g$ 的结构——对角/Kronecker 因子化时 $O(n)$~$O(n^2)$,全矩阵 $O(n^3)$ 不可行
35
+
36
+ ## 风险与失效条件
37
+
38
+ - **混淆梯度与下降方向**:忘记度量升指标,把 raw autodiff 输出(余向量)直接当下降方向(切向量),在弯曲空间中方向错误
39
+ - **大矩阵求逆**:自然梯度需要 $g^{-1}$,全 Fisher 矩阵 $O(N^3)$ 不可行,必须做 Kronecker/块对角/低秩因子化
40
+ - **切空间与原空间混淆**:在弯曲流形上直接做切空间的向量加法,忽略曲率导致的非线性偏差
41
+ - **Vector transport 缺失**:不同点的切空间无法直接相加,动量/Adam 状态需要 parallel transport 才能跨步搬运
42
+
43
+ ## 深入参考
44
+
45
+ - 蒸馏稿:references/books/smooth-manifolds.md(Ch 3 Tangent Vectors, Ch 11 The Cotangent Bundle)
46
+ - 蒸馏稿:references/books/differential-geometry.md(Ch 1-2, Ch 7 Tensors)
47
+ - 原书:John M. Lee, *Introduction to Smooth Manifolds*, 2nd Edition, Ch 3(切空间、pushforward、切丛)
48
+ - 原书:John M. Lee, *Introduction to Smooth Manifolds*, Ch 11(余切丛、1-form、pullback)
@@ -0,0 +1,56 @@
1
+ # Fisher-Rao Metric
2
+
3
+ ## Minimal Definition
4
+ The Fisher-Rao metric is a **Riemannian metric** on the parameter space of a family of probability distributions (statistical model), whose metric tensor is precisely the Fisher information matrix. It endows the parameter space with an intrinsic geometric structure, enabling the "distance" between probability distributions to be described using geometric language (geodesics, curvature, connections). It is the core structure of information geometry.
5
+
6
+ ## Core Formulas
7
+
8
+ **Metric Tensor (i.e., Fisher Information Matrix)**:
9
+ $$g_{ij}(\theta) = \mathcal{I}_{ij}(\theta) = \mathbb{E}_\theta\left[\frac{\partial \log p}{\partial \theta_i} \frac{\partial \log p}{\partial \theta_j}\right]$$
10
+
11
+ **Line Element (infinitesimal distance between distributions)**:
12
+ $$ds^2 = \sum_{i,j} g_{ij}(\theta) \, d\theta_i \, d\theta_j = 2 \, D_{KL}(p_\theta \| p_{\theta+d\theta})$$
13
+
14
+ **Geodesic Distance (finite distance between distributions)**:
15
+ $$d(p_{\theta_1}, p_{\theta_2}) = \inf_{\gamma} \int_0^1 \sqrt{\dot{\gamma}^T \mathcal{I}(\gamma(t)) \dot{\gamma}} \, dt$$
16
+
17
+ **$\alpha$-Connection Family** (different notions of "straight lines"):
18
+ $$\Gamma_{ijk}^{(\alpha)} = \mathbb{E}\left[\left(\partial_i \partial_j \ell + \frac{1-\alpha}{2} \partial_i \ell \, \partial_j \ell\right) \partial_k \ell\right]$$
19
+ - $\alpha = 0$: Levi-Civita connection (metric-compatible), corresponding to "midpoint" symmetry
20
+ - $\alpha = 1$: $e$-connection (exponential connection), corresponding to straight lines in the natural parameters of the exponential family
21
+ - $\alpha = -1$: $m$-connection (mixture connection), corresponding to straight lines in the expectation parameters of the mixture family
22
+
23
+ **Dually Flat Structure**: $(\mathcal{M}, g, \nabla^{(e)}, \nabla^{(m)})$ forms a dually flat manifold — the $e$-connection and $m$-connection are dual to each other with respect to $g$, and the generalized Pythagorean theorem holds.
24
+
25
+ ## Applicable Problems
26
+ - **Geometric distance between distributions**: Comparing the "intrinsic difference" between two probabilistic models (e.g., output distributions of two language models)
27
+ - **Statistical model complexity measurement**: The volume element $\sqrt{\det \mathcal{I}(\theta)} \, d\theta$ induced by the Fisher metric is used for model complexity penalties in MDL/BIC
28
+ - **Parameterization-invariant optimization**: Ensuring that the behavior of optimization algorithms does not depend on the specific choice of parameterization (reparameterization invariance)
29
+
30
+ ## AI Design Translation
31
+ - **Wasserstein vs. Fisher-Rao in generative models**: GANs use the Wasserstein distance to measure distributional differences; the Fisher-Rao metric provides an alternative — performing geometry-aware optimization in the parameter space of the distribution family
32
+ - **Geometry of pretrained model space**: Treating different checkpoints as points on the statistical manifold, Fisher geodesic distances can be used for model selection, model merging, and interpolation path planning
33
+ - **Geometric analysis of MoE expert distributions**: The degree of separation between the output distributions of different experts under the Fisher metric can quantify expert diversity
34
+
35
+ ## Engineering Feasibility
36
+ - **Dimension 1 Tensorization ❌**: The full metric tensor $g_{ij}$ is $d \times d$; infeasible to materialize when $d \sim 10^{10}$
37
+ - **Dimension 2 GEMM-mappability ⚠️**: Kronecker/diagonal approximations can be mapped; the exact metric cannot
38
+ - **Dimension 3 Complexity ❌**: Geodesic computation requires solving a second-order ODE; exact computation is intractable
39
+ - **Dimension 4 Memory ❌**: Full metric tensor storage is $O(d^2)$; completely impossible at LLM scale
40
+ - **Dimension 5 Low Precision ⚠️**: The condition number of the metric tensor may be very large, leading to instability under low precision
41
+ - **Dimension 6 Parallelism ⚠️**: Approximate versions (K-FAC, diagonal) can be parallelized; exact versions cannot
42
+ - **Dimension 7 Sparsity ⚠️**: The Fisher information matrix is typically dense; block-diagonal approximations (inter-layer independence) introduce structured sparsity
43
+ - **Dimension 8 Operator Fusion ✅**: Approximate versions can be fused into optimizer updates
44
+
45
+ **Conclusion**: The exact Fisher metric is infeasible at LLM scale, but **approximate versions** (K-FAC, diagonal Fisher, low-rank) are engineering-viable. The theoretical value of information geometry lies primarily in **guiding design** rather than direct computation.
46
+
47
+ ## Risks and Failure Conditions
48
+ - **Computational complexity is prohibitive**: The metric tensor in a $d$-dimensional parameter space has $O(d^2)$ independent components, which is unaffordable at LLM scale. All practical approaches must use approximations (diagonal, Kronecker, low-rank), and the quality of the approximation determines the practical effectiveness.
49
+ - **Singularities of the statistical manifold**: In certain regions of the parameter space (e.g., degenerate points of mixture distributions), the Fisher metric may degenerate ($\det \mathcal{I} = 0$), causing geodesic distances to be undefined. This type of degeneracy arises in MoE when an expert's weight is zero.
50
+
51
+ ## Further References
52
+ - Distillation draft: `references/books/` — no dedicated information geometry distillation draft at present
53
+ - Amari & Nagaoka. *Methods of Information Geometry*. AMS/Oxford, 2000
54
+ - Amari. *Information Geometry and Its Applications*. Springer, 2016
55
+ - Ay, Jost, Le, Schwachhofer. *Information Geometry*. Springer, 2017
56
+ - Related knowledge cards: `probability/fisher-information.md`, `information-geometry/natural-gradient.md`
@@ -0,0 +1,56 @@
1
+ # Fisher 度量 / Fisher-Rao Metric
2
+
3
+ ## 最小定义
4
+ Fisher-Rao 度量是概率分布族(统计模型)参数空间上的**黎曼度量**,其度量张量恰好是 Fisher 信息矩阵。它赋予参数空间一个内蕴几何结构,使得概率分布之间的"距离"可以用几何语言(测地线、曲率、联络)来描述,是信息几何的核心结构。
5
+
6
+ ## 核心公式
7
+
8
+ **度量张量(即 Fisher 信息矩阵)**:
9
+ $$g_{ij}(\theta) = \mathcal{I}_{ij}(\theta) = \mathbb{E}_\theta\left[\frac{\partial \log p}{\partial \theta_i} \frac{\partial \log p}{\partial \theta_j}\right]$$
10
+
11
+ **线元(分布间的无穷小距离)**:
12
+ $$ds^2 = \sum_{i,j} g_{ij}(\theta) \, d\theta_i \, d\theta_j = 2 \, D_{KL}(p_\theta \| p_{\theta+d\theta})$$
13
+
14
+ **测地线距离(有限分布间距离)**:
15
+ $$d(p_{\theta_1}, p_{\theta_2}) = \inf_{\gamma} \int_0^1 \sqrt{\dot{\gamma}^T \mathcal{I}(\gamma(t)) \dot{\gamma}} \, dt$$
16
+
17
+ **$\alpha$-联络族**(定义"直线"的不同方式):
18
+ $$\Gamma_{ijk}^{(\alpha)} = \mathbb{E}\left[\left(\partial_i \partial_j \ell + \frac{1-\alpha}{2} \partial_i \ell \, \partial_j \ell\right) \partial_k \ell\right]$$
19
+ - $\alpha = 0$:Levi-Civita 联络(度量兼容),对应"中点"对称
20
+ - $\alpha = 1$:$e$-联络(指数联络),对应指数族的自然参数直线
21
+ - $\alpha = -1$:$m$-联络(混合联络),对应混合族的期望参数直线
22
+
23
+ **对偶平坦性**:$(\mathcal{M}, g, \nabla^{(e)}, \nabla^{(m)})$ 构成对偶平坦流形——$e$-联络和 $m$-联络关于 $g$ 互为对偶,广义勾股定理成立。
24
+
25
+ ## 适用问题
26
+ - **分布间的几何距离**:比较两个概率模型(如两个语言模型的输出分布)的"本质差异"
27
+ - **统计模型复杂度度量**:Fisher 度量诱导的体积元 $\sqrt{\det \mathcal{I}(\theta)} \, d\theta$ 用于 MDL/BIC 中的模型复杂度惩罚
28
+ - **参数化无关优化**:确保优化算法的行为不依赖于参数的具体选取方式(reparameterization invariance)
29
+
30
+ ## AI 设计翻译
31
+ - **Wasserstein vs. Fisher-Rao 在生成模型中**:GAN 用 Wasserstein 距离度量分布差异;Fisher-Rao 度量提供替代方案——在分布族的参数空间上做几何感知优化
32
+ - **预训练模型空间的几何**:将不同 checkpoint 视为统计流形上的点,Fisher 测地线距离可用于模型选择、合并(model merging)和插值路径规划
33
+ - **MoE 专家分布的几何分析**:不同专家的输出分布在 Fisher 度量下的分离度可量化专家多样性
34
+
35
+ ## 工程可行性
36
+ - **维度 1 张量化 ❌**:完整度量张量 $g_{ij}$ 是 $d \times d$,$d \sim 10^{10}$ 时不可物化
37
+ - **维度 2 GEMM 可映射 ⚠️**:Kronecker/对角近似可,精确度量不可
38
+ - **维度 3 复杂度 ❌**:测地线计算需解二阶 ODE,精确计算不可行
39
+ - **维度 4 显存 ❌**:完整度量张量存储 $O(d^2)$,LLM 级完全不可能
40
+ - **维度 5 低精度 ⚠️**:度量张量的条件数可能很大,低精度下不稳定
41
+ - **维度 6 并行 ⚠️**:近似版本(K-FAC、对角)可并行,精确版本不可
42
+ - **维度 7 稀疏 ⚠️**:Fisher 信息矩阵通常稠密;块对角近似(层间独立)引入结构化稀疏
43
+ - **维度 8 算子融合 ✅**:近似版本可融入优化器更新
44
+
45
+ **结论**:精确 Fisher 度量在 LLM 规模下不可行,但**近似版本**(K-FAC、对角 Fisher、低秩)在工程上可落地。信息几何的理论价值主要在**指导设计**而非直接计算。
46
+
47
+ ## 风险与失效条件
48
+ - **计算复杂度致命**:$d$ 维参数空间的度量张量有 $O(d^2)$ 个独立分量,LLM 级无法承受。所有实用方案必须做近似(对角、Kronecker、低秩),近似质量决定实际效果。
49
+ - **统计流形的奇点**:在参数空间的某些区域(如混合分布的退化点),Fisher 度量可能退化($\det \mathcal{I} = 0$),导致测地线距离不定义。在 MoE 中某专家权重为零时即出现此类退化。
50
+
51
+ ## 深入参考
52
+ - 蒸馏稿:`references/books/` 暂无专用信息几何蒸馏稿
53
+ - Amari & Nagaoka. *Methods of Information Geometry*. AMS/Oxford, 2000
54
+ - Amari. *Information Geometry and Its Applications*. Springer, 2016
55
+ - Ay, Jost, Le, Schwachhofer. *Information Geometry*. Springer, 2017
56
+ - 关联知识卡:`probability/fisher-information.md`、`information-geometry/natural-gradient.md`
@@ -0,0 +1,54 @@
1
+ # Natural Gradient
2
+
3
+ ## Minimal Definition
4
+ The natural gradient is the steepest descent direction with respect to the **Fisher information metric** on the parameter space. Unlike the naive gradient defined under the Euclidean metric, the natural gradient is defined under the Riemannian metric of the statistical manifold, making it invariant to the choice of parameterization (reparameterization invariant) and automatically adaptive to the curvature structure of the loss surface.
5
+
6
+ ## Core Formulas
7
+
8
+ **Naive Gradient Descent** (Euclidean metric):
9
+ $$\theta_{t+1} = \theta_t - \eta \nabla_\theta \mathcal{L}(\theta)$$
10
+
11
+ **Natural Gradient Descent** (Fisher metric):
12
+ $$\tilde{\nabla} \mathcal{L}(\theta) = \mathcal{I}(\theta)^{-1} \nabla_\theta \mathcal{L}(\theta)$$
13
+ $$\theta_{t+1} = \theta_t - \eta \, \mathcal{I}(\theta)^{-1} \nabla_\theta \mathcal{L}(\theta)$$
14
+
15
+ where $\mathcal{I}(\theta)$ is the Fisher information matrix (see `probability/fisher-information.md`).
16
+
17
+ **Equivalent Derivation (Constrained Optimization Perspective)**: The natural gradient is the solution to the following constrained optimization problem —
18
+ $$\min_{\Delta\theta} \mathcal{L}(\theta + \Delta\theta) \quad \text{s.t.} \quad D_{KL}(p_\theta \| p_{\theta+\Delta\theta}) \leq \epsilon$$
19
+
20
+ Using the second-order expansion $D_{KL} \approx \frac{1}{2} \Delta\theta^T \mathcal{I} \Delta\theta$, solving via Lagrangian yields the natural gradient.
21
+
22
+ **K-FAC Approximation** (Kronecker-Factored Approximate Curvature):
23
+ $$\mathcal{I}_l \approx A_l \otimes B_l$$
24
+ where $A_l = \mathbb{E}[a_l a_l^T]$ (activation covariance) and $B_l = \mathbb{E}[g_l g_l^T]$ (gradient covariance), computed and inverted independently per layer.
25
+
26
+ ## Applicable Problems
27
+ - **Ill-conditioned loss surface optimization**: When the Hessian condition number is large (narrow canyon), the natural gradient updates along the canyon floor, avoiding oscillation
28
+ - **Distributional parameter learning**: Updates to posterior parameters in variational inference; the natural gradient automatically handles the curvature of the Fisher-Rao manifold
29
+ - **Policy gradient (RL)**: The trust-region constraint in TRPO/PPO is equivalent to a step-size-limited version of the natural gradient
30
+
31
+ ## AI Design Translation
32
+ - **K-FAC Optimizer**: Uses Kronecker decomposition to approximate the FIM, enabling approximate second-order optimization. Each layer maintains $(A_l, B_l)$, with inverse $A_l^{-1} \otimes B_l^{-1}$, reducing matrix inversion complexity from $O(d^3)$ to $O(d_A^3 + d_B^3)$
33
+ - **TRPO Trust-Region Policy Gradient**: Policy updates under the constraint $D_{KL}(\pi_{\theta_{\text{old}}} \| \pi_\theta) \leq \delta$, essentially natural gradient + line search
34
+ - **Natural Gradient in Variational Inference**: For exponential family parameters, the natural gradient equals the difference in expected sufficient statistics, avoiding Fisher matrix inversion
35
+
36
+ ## Engineering Feasibility
37
+ - **Dimension 1 Tensorization ⚠️**: The Kronecker factors of the FIM are dense matrices and can be tensorized; the full FIM cannot
38
+ - **Dimension 2 GEMM-mappability ✅**: K-FAC's $A_l^{-1} (\nabla W_l) B_l^{-1}$ is two matrix multiplications, naturally GEMM
39
+ - **Dimension 3 Complexity ⚠️**: K-FAC adds $O(d_A^2 + d_B^2)$ per-layer covariance estimation + $O(d_A^3 + d_B^3)$ matrix inversion; diagonal approximation is $O(d)$
40
+ - **Dimension 4 Memory ⚠️**: Requires additional storage of $A_l$ and $B_l$ per layer ($O(d_A^2 + d_B^2)$); acceptable for LLMs but non-trivial
41
+ - **Dimension 5 Low Precision ⚠️**: Matrix inversion may be unstable in fp16; fp32 or Tikhonov regularization $(A + \epsilon I)^{-1}$ is needed
42
+ - **Dimension 6 Parallelism ✅**: Kronecker factors for each layer are computed independently; fully parallel across layers
43
+ - **Dimension 8 Operator Fusion ✅**: Natural gradient updates can be fused into the parameter update kernel
44
+
45
+ ## Risks and Failure Conditions
46
+ - **K-FAC's inter-layer independence assumption is overly strong**: It assumes the Fisher information is block-diagonal across layers, ignoring inter-layer correlations. In deep networks, this may underestimate the effective curvature, leading to excessively large steps. Line search or trust-region safeguards are needed.
47
+ - **Burn-in problem for covariance estimation**: In early training, $A_l, B_l$ estimates are inaccurate and the natural gradient direction may be wrong. The standard practice is to warm up with Adam/SGD for the first few hundred steps, then switch to K-FAC.
48
+
49
+ ## Further References
50
+ - Distillation draft: `references/books/` — no dedicated information geometry distillation draft at present
51
+ - Amari. *Natural Gradient Works Efficiently in Learning.* Neural Computation, 1998
52
+ - Martens & Grosse. "Optimizing Neural Networks with Kronecker-Factored Approximate Curvature." *ICML*, 2015
53
+ - Schulman et al. "Trust Region Policy Optimization." *ICML*, 2015
54
+ - Related knowledge cards: `probability/fisher-information.md`, `information-geometry/fisher-metric.md`
@@ -0,0 +1,54 @@
1
+ # 自然梯度 / Natural Gradient
2
+
3
+ ## 最小定义
4
+ 自然梯度是参数空间上关于**Fisher 信息度量**的最速下降方向。与朴素梯度在欧氏度量下定义不同,自然梯度在统计流形的黎曼度量下定义,因此对参数化方式的选择不敏感(reparameterization invariant),且能自动适应损失面的曲率结构。
5
+
6
+ ## 核心公式
7
+
8
+ **朴素梯度下降**(欧氏度量):
9
+ $$\theta_{t+1} = \theta_t - \eta \nabla_\theta \mathcal{L}(\theta)$$
10
+
11
+ **自然梯度下降**(Fisher 度量):
12
+ $$\tilde{\nabla} \mathcal{L}(\theta) = \mathcal{I}(\theta)^{-1} \nabla_\theta \mathcal{L}(\theta)$$
13
+ $$\theta_{t+1} = \theta_t - \eta \, \mathcal{I}(\theta)^{-1} \nabla_\theta \mathcal{L}(\theta)$$
14
+
15
+ 其中 $\mathcal{I}(\theta)$ 为 Fisher 信息矩阵(详见 `probability/fisher-information.md`)。
16
+
17
+ **等价推导(约束优化视角)**:自然梯度是以下约束优化问题的解——
18
+ $$\min_{\Delta\theta} \mathcal{L}(\theta + \Delta\theta) \quad \text{s.t.} \quad D_{KL}(p_\theta \| p_{\theta+\Delta\theta}) \leq \epsilon$$
19
+
20
+ 用二阶展开 $D_{KL} \approx \frac{1}{2} \Delta\theta^T \mathcal{I} \Delta\theta$,拉格朗日求解即得自然梯度。
21
+
22
+ **K-FAC 近似**(Kronecker-Factored Approximate Curvature):
23
+ $$\mathcal{I}_l \approx A_l \otimes B_l$$
24
+ 其中 $A_l = \mathbb{E}[a_l a_l^T]$(激活协方差),$B_l = \mathbb{E}[g_l g_l^T]$(梯度协方差),逐层独立计算和求逆。
25
+
26
+ ## 适用问题
27
+ - **病态损失面优化**:当 Hessian 条件数很大(狭长峡谷)时,自然梯度沿峡谷底部方向更新,避免震荡
28
+ - **分布参数学习**:变分推断中后验参数的更新,自然梯度自动处理 Fisher-Rao 流形的曲率
29
+ - **策略梯度(RL)**:TRPO/PPO 的信任域约束等价于自然梯度的步长限制版本
30
+
31
+ ## AI 设计翻译
32
+ - **K-FAC 优化器**:用 Kronecker 分解近似 FIM,实现近似二阶优化。每层维护 $(A_l, B_l)$,逆为 $A_l^{-1} \otimes B_l^{-1}$,矩阵逆复杂度从 $O(d^3)$ 降至 $O(d_A^3 + d_B^3)$
33
+ - **TRPO 信任域策略梯度**:$D_{KL}(\pi_{\theta_{\text{old}}} \| \pi_\theta) \leq \delta$ 约束下的策略更新,本质是自然梯度 + 线搜索
34
+ - **变分推断中的自然梯度**:指数族参数的自然梯度 = 充分统计量的期望差,避免 Fisher 矩阵求逆
35
+
36
+ ## 工程可行性
37
+ - **维度 1 张量化 ⚠️**:FIM 的 Kronecker 因子为稠密矩阵,可张量化;完整 FIM 不可
38
+ - **维度 2 GEMM 可映射 ✅**:K-FAC 的 $A_l^{-1} (\nabla W_l) B_l^{-1}$ 是两次矩阵乘,天然 GEMM
39
+ - **维度 3 复杂度 ⚠️**:K-FAC 每层额外 $O(d_A^2 + d_B^2)$ 协方差估计 + $O(d_A^3 + d_B^3)$ 矩阵逆;对角近似 $O(d)$
40
+ - **维度 4 显存 ⚠️**:需额外存储每层的 $A_l$ 和 $B_l$($O(d_A^2 + d_B^2)$),对 LLM 可接受但非零
41
+ - **维度 5 低精度 ⚠️**:矩阵求逆在 fp16 下可能不稳定,需 fp32 或 Tikhonov 正则化 $(A + \epsilon I)^{-1}$
42
+ - **维度 6 并行 ✅**:各层 Kronecker 因子独立计算,层间完全并行
43
+ - **维度 8 算子融合 ✅**:自然梯度更新可融入参数更新 kernel
44
+
45
+ ## 风险与失效条件
46
+ - **K-FAC 的层间独立性假设过强**:假设各层 Fisher 信息块对角,忽略层间相关性。在深网络中可能低估有效曲率,导致步长过大。需搭配线搜索或 trust-region 安全机制。
47
+ - **协方差估计的 burn-in 问题**:训练初期 $A_l, B_l$ 估计不准确,自然梯度方向可能错误。标准做法是前几百步用 Adam/SGD warmup,再切换到 K-FAC。
48
+
49
+ ## 深入参考
50
+ - 蒸馏稿:`references/books/` 暂无专用信息几何蒸馏稿
51
+ - Amari. *Natural Gradient Works Efficiently in Learning.* Neural Computation, 1998
52
+ - Martens & Grosse. "Optimizing Neural Networks with Kronecker-Factored Approximate Curvature." *ICML*, 2015
53
+ - Schulman et al. "Trust Region Policy Optimization." *ICML*, 2015
54
+ - 关联知识卡:`probability/fisher-information.md`、`information-geometry/fisher-metric.md`