math-skill 2.0.1 → 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.
- package/README.en-US.md +167 -175
- package/README.md +167 -175
- package/agents/math-critic.en.md +235 -0
- package/agents/math-critic.md +10 -8
- package/commands/ask.md +3 -12
- package/design-patterns/attention/equivariant-attention.en.md +72 -0
- package/design-patterns/attention/equivariant-attention.md +72 -0
- package/design-patterns/attention/geometry-aware-attention.en.md +73 -0
- package/design-patterns/attention/geometry-aware-attention.md +72 -0
- package/design-patterns/attention/information-bottleneck-attention.en.md +72 -0
- package/design-patterns/attention/information-bottleneck-attention.md +72 -0
- package/design-patterns/attention/projection-attention.en.md +68 -0
- package/design-patterns/attention/projection-attention.md +68 -0
- package/design-patterns/attention/spectral-attention.en.md +71 -0
- package/design-patterns/attention/spectral-attention.md +71 -0
- package/design-patterns/compression/leverage-score-selection.en.md +71 -0
- package/design-patterns/compression/leverage-score-selection.md +71 -0
- package/design-patterns/compression/low-rank-kv-cache.en.md +60 -0
- package/design-patterns/compression/low-rank-kv-cache.md +60 -0
- package/design-patterns/compression/spectral-token-pruning.en.md +61 -0
- package/design-patterns/compression/spectral-token-pruning.md +61 -0
- package/design-patterns/compression/topology-preserving-compression.en.md +64 -0
- package/design-patterns/compression/topology-preserving-compression.md +64 -0
- package/design-patterns/loss/constraint-penalty.en.md +67 -0
- package/design-patterns/loss/constraint-penalty.md +78 -0
- package/design-patterns/loss/contrastive-loss.en.md +59 -0
- package/design-patterns/loss/contrastive-loss.md +68 -0
- package/design-patterns/loss/information-bottleneck-loss.en.md +69 -0
- package/design-patterns/loss/information-bottleneck-loss.md +74 -0
- package/design-patterns/loss/orthogonality-loss.en.md +56 -0
- package/design-patterns/loss/orthogonality-loss.md +60 -0
- package/design-patterns/loss/variational-loss.en.md +61 -0
- package/design-patterns/loss/variational-loss.md +71 -0
- package/design-patterns/representation/equivariant-split.en.md +87 -0
- package/design-patterns/representation/equivariant-split.md +89 -0
- package/design-patterns/representation/manifold-representation.en.md +85 -0
- package/design-patterns/representation/manifold-representation.md +87 -0
- package/design-patterns/representation/shared-private-decomposition.en.md +84 -0
- package/design-patterns/representation/shared-private-decomposition.md +86 -0
- package/design-patterns/representation/subspace-alignment.en.md +90 -0
- package/design-patterns/representation/subspace-alignment.md +92 -0
- package/design-patterns/routing/graph-routing.en.md +79 -0
- package/design-patterns/routing/graph-routing.md +81 -0
- package/design-patterns/routing/moe-routing.en.md +85 -0
- package/design-patterns/routing/moe-routing.md +87 -0
- package/design-patterns/routing/optimal-transport-routing.en.md +68 -0
- package/design-patterns/routing/optimal-transport-routing.md +72 -0
- package/design-patterns/routing/spectral-clustering-routing.en.md +88 -0
- package/design-patterns/routing/spectral-clustering-routing.md +90 -0
- package/knowledge-base/differential-geometry/connection.en.md +51 -0
- package/knowledge-base/differential-geometry/connection.md +51 -0
- package/knowledge-base/differential-geometry/curvature.en.md +49 -0
- package/knowledge-base/differential-geometry/curvature.md +49 -0
- package/knowledge-base/differential-geometry/geodesic.en.md +51 -0
- package/knowledge-base/differential-geometry/geodesic.md +51 -0
- package/knowledge-base/differential-geometry/manifold.en.md +47 -0
- package/knowledge-base/differential-geometry/manifold.md +47 -0
- package/knowledge-base/differential-geometry/metric-tensor.en.md +50 -0
- package/knowledge-base/differential-geometry/metric-tensor.md +50 -0
- package/knowledge-base/differential-geometry/tangent-space.en.md +48 -0
- package/knowledge-base/differential-geometry/tangent-space.md +48 -0
- package/knowledge-base/information-geometry/fisher-metric.en.md +56 -0
- package/knowledge-base/information-geometry/fisher-metric.md +56 -0
- package/knowledge-base/information-geometry/natural-gradient.en.md +54 -0
- package/knowledge-base/information-geometry/natural-gradient.md +54 -0
- package/knowledge-base/lie-theory/equivariance.en.md +54 -0
- package/knowledge-base/lie-theory/equivariance.md +54 -0
- package/knowledge-base/lie-theory/group-action.en.md +51 -0
- package/knowledge-base/lie-theory/group-action.md +51 -0
- package/knowledge-base/lie-theory/lie-algebra.en.md +51 -0
- package/knowledge-base/lie-theory/lie-algebra.md +51 -0
- package/knowledge-base/lie-theory/lie-group.en.md +51 -0
- package/knowledge-base/lie-theory/lie-group.md +51 -0
- package/knowledge-base/lie-theory/representation.en.md +52 -0
- package/knowledge-base/lie-theory/representation.md +52 -0
- package/knowledge-base/matrix-analysis/low-rank-approximation.en.md +49 -0
- package/knowledge-base/matrix-analysis/low-rank-approximation.md +49 -0
- package/knowledge-base/matrix-analysis/matrix-perturbation.en.md +49 -0
- package/knowledge-base/matrix-analysis/matrix-perturbation.md +49 -0
- package/knowledge-base/matrix-analysis/positive-semidefinite.en.md +50 -0
- package/knowledge-base/matrix-analysis/positive-semidefinite.md +50 -0
- package/knowledge-base/matrix-analysis/projection.en.md +47 -0
- package/knowledge-base/matrix-analysis/projection.md +47 -0
- package/knowledge-base/matrix-analysis/spectral-decomposition.en.md +48 -0
- package/knowledge-base/matrix-analysis/spectral-decomposition.md +48 -0
- package/knowledge-base/optimization/constrained-optimization.en.md +53 -0
- package/knowledge-base/optimization/constrained-optimization.md +53 -0
- package/knowledge-base/optimization/convex-optimization.en.md +50 -0
- package/knowledge-base/optimization/convex-optimization.md +50 -0
- package/knowledge-base/optimization/lagrangian-duality.en.md +50 -0
- package/knowledge-base/optimization/lagrangian-duality.md +50 -0
- package/knowledge-base/optimization/proximal-method.en.md +52 -0
- package/knowledge-base/optimization/proximal-method.md +52 -0
- package/knowledge-base/optimization/riemannian-optimization.en.md +51 -0
- package/knowledge-base/optimization/riemannian-optimization.md +51 -0
- package/knowledge-base/overview.en.md +39 -0
- package/knowledge-base/overview.md +29 -218
- package/knowledge-base/probability/concentration-inequality.en.md +45 -0
- package/knowledge-base/probability/concentration-inequality.md +45 -0
- package/knowledge-base/probability/entropy.en.md +47 -0
- package/knowledge-base/probability/entropy.md +47 -0
- package/knowledge-base/probability/fisher-information.en.md +48 -0
- package/knowledge-base/probability/fisher-information.md +48 -0
- package/knowledge-base/probability/information-bottleneck.en.md +49 -0
- package/knowledge-base/probability/information-bottleneck.md +49 -0
- package/knowledge-base/probability/kl-divergence.en.md +51 -0
- package/knowledge-base/probability/kl-divergence.md +51 -0
- package/knowledge-base/topology/euler-characteristic.en.md +54 -0
- package/knowledge-base/topology/euler-characteristic.md +54 -0
- package/knowledge-base/topology/fundamental-group.en.md +52 -0
- package/knowledge-base/topology/fundamental-group.md +52 -0
- package/knowledge-base/topology/persistent-homology.en.md +54 -0
- package/knowledge-base/topology/persistent-homology.md +54 -0
- package/lenses/algorithmic.en.md +49 -0
- package/lenses/algorithmic.md +49 -0
- package/lenses/axiomatization.en.md +48 -0
- package/lenses/axiomatization.md +48 -0
- package/lenses/categorical.en.md +48 -0
- package/lenses/categorical.md +48 -0
- package/lenses/causal.en.md +49 -0
- package/lenses/causal.md +49 -0
- package/lenses/duality.en.md +47 -0
- package/lenses/duality.md +47 -0
- package/lenses/game.en.md +50 -0
- package/lenses/game.md +50 -0
- package/lenses/geometric.en.md +53 -0
- package/lenses/geometric.md +53 -0
- package/lenses/local-to-global.en.md +52 -0
- package/lenses/local-to-global.md +52 -0
- package/lenses/perturbation.en.md +51 -0
- package/lenses/perturbation.md +51 -0
- package/lenses/probabilistic.en.md +48 -0
- package/lenses/probabilistic.md +48 -0
- package/lenses/projection.en.md +50 -0
- package/lenses/projection.md +50 -0
- package/lenses/spectral.en.md +52 -0
- package/lenses/spectral.md +52 -0
- package/lenses/symmetry.en.md +49 -0
- package/lenses/symmetry.md +49 -0
- package/lenses/topological.en.md +48 -0
- package/lenses/topological.md +48 -0
- package/lenses/variational.en.md +48 -0
- package/lenses/variational.md +48 -0
- package/package.json +11 -3
- package/references/agentic-workflow.en.md +53 -0
- package/references/agentic-workflow.md +2 -0
- package/references/books/abstract-algebra.md +9 -5
- package/references/books/algebraic-geometry-rising-sea.md +9 -5
- package/references/books/differential-geometry.md +7 -3
- package/references/books/matrix-analysis.md +8 -4
- package/references/books/micro-lie-theory.md +7 -3
- package/references/books/optimization-ml.md +5 -1
- package/references/books/smooth-manifolds.md +7 -3
- package/references/gpu-friendly-math.en.md +65 -0
- package/references/gpu-friendly-math.md +4 -2
- package/references/inspiration.en.md +113 -0
- package/references/inspiration.md +4 -2
- package/skills/math-research-activator/SKILL.en.md +187 -0
- package/skills/math-research-activator/SKILL.md +162 -108
- package/skills/math-research-activator/original-texts.en.md +105 -0
- package/skills/math-research-activator/original-texts.md +11 -11
- package/commands/abstraction.md +0 -13
- package/commands/algorithmic-thinking.md +0 -13
- package/commands/axiomatization.md +0 -13
- package/commands/causal-inference.md +0 -13
- package/commands/discrete-combinatorial.md +0 -13
- package/commands/game-theory.md +0 -13
- package/commands/induction-analogy.md +0 -13
- package/commands/information-theory.md +0 -13
- package/commands/logic-deduction.md +0 -13
- package/commands/modeling.md +0 -13
- package/commands/optimization.md +0 -13
- package/commands/probability-statistics.md +0 -13
- package/commands/symmetry-invariance.md +0 -13
- package/commands/topological-thinking.md +0 -13
- package/commands/transformation.md +0 -13
- package/skills/abstraction/SKILL.md +0 -119
- package/skills/abstraction/original-texts.md +0 -175
- package/skills/algorithmic-thinking/SKILL.md +0 -136
- package/skills/algorithmic-thinking/original-texts.md +0 -256
- package/skills/axiomatization/SKILL.md +0 -149
- package/skills/axiomatization/original-texts.md +0 -160
- package/skills/causal-inference/SKILL.md +0 -149
- package/skills/causal-inference/original-texts.md +0 -167
- package/skills/discrete-combinatorial/SKILL.md +0 -129
- package/skills/discrete-combinatorial/original-texts.md +0 -185
- package/skills/game-theory/SKILL.md +0 -121
- package/skills/game-theory/original-texts.md +0 -131
- package/skills/induction-analogy/SKILL.md +0 -150
- package/skills/induction-analogy/original-texts.md +0 -154
- package/skills/information-theory/SKILL.md +0 -138
- package/skills/information-theory/original-texts.md +0 -127
- package/skills/logic-deduction/SKILL.md +0 -133
- package/skills/logic-deduction/original-texts.md +0 -173
- package/skills/modeling/SKILL.md +0 -137
- package/skills/modeling/original-texts.md +0 -165
- package/skills/optimization/SKILL.md +0 -133
- package/skills/optimization/original-texts.md +0 -168
- package/skills/probability-statistics/SKILL.md +0 -149
- package/skills/probability-statistics/original-texts.md +0 -193
- package/skills/symmetry-invariance/SKILL.md +0 -137
- package/skills/symmetry-invariance/original-texts.md +0 -221
- package/skills/topological-thinking/SKILL.md +0 -126
- package/skills/topological-thinking/original-texts.md +0 -164
- package/skills/transformation/SKILL.md +0 -122
- package/skills/transformation/original-texts.md +0 -216
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: causal-inference
|
|
3
|
-
description: |
|
|
4
|
-
触发:相关≠因果、干预/反事实推理、do-演算、因果图(DAG)建模、混淆变量识别、政策/处理效应评估;或为模型可解释性、分布外泛化、数据生成过程(DGP)建模而需显式因果假设时调用。
|
|
5
|
-
English: Trigger when a problem concerns correlation≠causation, intervention/counterfactual reasoning, do-calculus, causal DAG modeling, confounder identification, policy/treatment effect estimation; or needs explicit causal assumptions for model interpretability, out-of-distribution generalization, or data-generating process modeling.
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
# 🔗 因果推断思想 / Causal Inference
|
|
9
|
-
|
|
10
|
-
> "相关不等于因果——但因果可以理清。关键区别:'看到X时Y如何'≠'如果做了X会怎样'"
|
|
11
|
-
> "Correlation is not causation — but causation can be sorted out. Key distinction: 'how is Y when we see X' ≠ 'what if we did X'"
|
|
12
|
-
>
|
|
13
|
-
> —— 因果推断、结构因果模型、反事实推理
|
|
14
|
-
> —— Causal Inference, Structural Causal Models, Counterfactual Reasoning
|
|
15
|
-
|
|
16
|
-
## 核心原则 / Core Principle
|
|
17
|
-
|
|
18
|
-
**因果推断回答的问题超出概率论的表达能力:概率论能回答"看到 X 时 Y 如何",但不能回答"如果做了 X 会怎样"。Pearl 因果层级将推理分为三层,每层需要更强的建模假设。**
|
|
19
|
-
|
|
20
|
-
**Causal inference answers questions beyond probability's expressive power: probability answers "how is Y when we see X," not "what if we did X." Pearl's causal hierarchy has three levels, each requiring stronger modeling assumptions.**
|
|
21
|
-
|
|
22
|
-
> **数学形式化 / Mathematical Formalization**
|
|
23
|
-
>
|
|
24
|
-
> Pearl 因果层级 / Causal Hierarchy:
|
|
25
|
-
> - **Level 1 关联 / Association**:P(y|x) —— 看到/观察 / Seeing
|
|
26
|
-
> - **Level 2 干预 / Intervention**:P(y|do(x)) —— 做/干预 / Doing
|
|
27
|
-
> - **Level 3 反事实 / Counterfactual**:P(y_x|x',y') —— 想/回顾 / Imagining
|
|
28
|
-
>
|
|
29
|
-
> **do(x) ≠ 条件化 x**:do(x) 切断所有指向 X 的箭头(图手术),条件化 x 不切断任何箭头。后门调整 / back-door adjustment:P(y|do(x)) = Σ_z P(y|x,z)P(z)
|
|
30
|
-
>
|
|
31
|
-
> **潜在结果 / Potential Outcomes (Neyman-Rubin)**:Y(x) 为"若施干预 X=x 时 Y 的取值";个体效应 τ_i = Y_i(1)-Y_i(0),平均处理效应 ATE = E[Y(1)]-E[Y(0)] = E[Y|do(X=1)] - E[Y|do(X=0)]。
|
|
32
|
-
>
|
|
33
|
-
> **结构因果模型 / SCM**:Y := f(X, Z, U),U 为外生变量;DAG + 结构方程共同确定反事实 Y_x = f(x, Z, U)。
|
|
34
|
-
>
|
|
35
|
-
> **d-分离 / d-Separation**:路径被 Z 阻断 ⟺ 链/叉中点 ∈ Z,或 collider X→C←Y 且 C 及其后代 ∉ Z。d-分离 X⊥_G Y|Z 蕴含条件独立,是图上读出因果假设的工具。
|
|
36
|
-
>
|
|
37
|
-
> **do-演算三规则 / Do-calculus**(在修正图上用 d-分离判断):
|
|
38
|
-
> - 规则 1(插入/删除观察):若 Y ⊥ Z | X 在删去所有指向 X 的箭头后的图中成立,则 P(y|do(x),z) = P(y|do(x))
|
|
39
|
-
> - 规则 2(干预与观察互换):若 Y ⊥ Z | X 在删去所有指向 X 的箭头并删去所有从 Z 出发的箭头后的图中成立,则 P(y|do(x),do(z)) = P(y|do(x),z)
|
|
40
|
-
> - 规则 3(插入/删除干预):若 Y ⊥ Z | X 在删去所有指向 X 的箭头并删去所有从 Z 到 X 的路径上的箭头后的图中成立,则 P(y|do(x),do(z)) = P(y|do(x))
|
|
41
|
-
>
|
|
42
|
-
> **因果推理需显式因果模型,不能仅靠数据推导。DAG 编码因果假设,do-演算将干预表达式转化为可观测量。**
|
|
43
|
-
>
|
|
44
|
-
> 详细数学依据见 `original-texts.md`
|
|
45
|
-
|
|
46
|
-
## GPU 友好性 / GPU-Friendliness(横切检查)
|
|
47
|
-
|
|
48
|
-
当因果推断用于**模型可解释性 / 分布外泛化 / 数据生成过程建模**并需大规模估计时,方法本身要过 `../../references/gpu-friendly-math.md` 八维门:
|
|
49
|
-
|
|
50
|
-
- **效应估计 / 调整回归**:后门调整、IPW、双重机器学习的条件期望/regression 全是批量 GEMM,张量化、可融合、低精度可行——**友好**(见 `../../references/books/optimization-ml.md`)。
|
|
51
|
-
- **条件独立检验**:高维条件独立检验含精度阵(协方差逆)求逆 $O(p^3)$,可改 **低秩/对角近似**或迭代求解器——**可改造**(见 `../../references/books/matrix-analysis.md`)。
|
|
52
|
-
- **精确因果发现(DAG 搜索)**:DAG 空间随节点数超指数增长,精确打分搜索 NP-hard、不可微、串行——典型"美但不可算"反模式。
|
|
53
|
-
- **改造手法**:NOTEARS 式**连续松弛**(无环性 $h(W)=\text{tr}(e^{W\circ W})-p=0$)把离散图搜索变成可微优化;或 MCMC/贪心+打分作启发式近似。
|
|
54
|
-
- **反事实/SCM 仿真**:结构方程前向模拟可批量并行;但个体反事实依赖外生 U 的识别,警惕串行依赖。
|
|
55
|
-
|
|
56
|
-
八维最低判定(正式术语):**张量化**看样本/干预/候选图能否批量处理;**GEMM 可映射**看调整回归与表示学习是否落矩阵乘;**复杂度**看因果发现是否避开超指数 DAG 搜索;**显存与 KV-Cache**看精度阵、候选图和中间反事实是否可压缩;**低精度稳定**看 IPW 权重、协方差逆和 logit 是否稳健;**并行与通信**看多环境/多干预估计能否并行;**稀疏结构**看 DAG/SCM 是否结构化稀疏;**算子融合**看打分、mask、loss 能否融合。
|
|
57
|
-
|
|
58
|
-
> 配合 `../../references/books/optimization-ml.md`(干预估计/regression)与 `../../references/books/matrix-analysis.md`(条件独立/低秩精度阵)。
|
|
59
|
-
|
|
60
|
-
## 不适用场景 / When NOT to Use
|
|
61
|
-
|
|
62
|
-
- **纯预测任务且无因果问题**(只需 P(y|x),不关心"为什么")——关联足够,因果多余。
|
|
63
|
-
- **无可编码的因果假设**(画不出合理 DAG,因果方向不确定)——没有显式假设就没有因果结论。
|
|
64
|
-
- **确定性系统且无变异**(输入严格唯一映射输出)——因果已被机制完全描述,无需概率因果框架。
|
|
65
|
-
|
|
66
|
-
## 何时使用 / When to Use
|
|
67
|
-
|
|
68
|
-
- 需要知道干预的效果("做了 X,Y 会怎样?")——需 P(y|do(x)) 而非 P(y|x)。
|
|
69
|
-
- 需要区分原因与混淆变量(X 导致 Y,还是 Z 同时导致 X 和 Y?)——DAG 识别混淆路径。
|
|
70
|
-
- 需要反事实推理("若当时没做 A 结果会怎样?")——Level 3 需结构方程。
|
|
71
|
-
- 需要政策/处理效应评估(RCT 不可行时的后门调整、IV、双重差分)。
|
|
72
|
-
- 需要中介分析(拆分 X→M→Y 的直接与间接效应)。
|
|
73
|
-
- 需要为**模型可解释性 / 分布外泛化**建模数据生成过程(DGP),把预测器的关联变成可干预的因果机制。
|
|
74
|
-
|
|
75
|
-
## 方法流程 / Method
|
|
76
|
-
|
|
77
|
-
### 第一步:构建因果 DAG / Construct the Causal DAG
|
|
78
|
-
明确所有变量,画因果箭头编码直接原因假设,检查无环性。识别原因变量 X(干预对象)、结果 Y(效应)、混淆 Z(X、Y 共同原因)、中介 M(X→M→Y)。箭头 X→Y 表示"X 是 Y 的直接原因",方向编码因果假设。DAG 必须有向无环——存在环路则因果方向不确定,需重新建模。**关键**:是否有足够领域知识编码因果方向?结论完全依赖 DAG 正确性。
|
|
79
|
-
|
|
80
|
-
### 第二步:识别混淆变量 / Identify Confounders
|
|
81
|
-
混淆变量同时影响 X 和 Y,创造虚假关联——不调整则效应估计有偏。**定义**:Z 是混淆 ⟺ Z 是 X、Y 的共同原因(Z→X 且 Z→Y)。**DAG 识别法**:找 X、Y 的所有共同祖先。**后门路径** X←Z→Y 创造非因果关联需阻断。**关键**:所有混淆是否可观测?存在未观测混淆则后门调整不可用,需前门准则或工具变量。
|
|
82
|
-
|
|
83
|
-
### 第三步:选择识别策略 / Choose Identification Strategy
|
|
84
|
-
据混淆可观测性,选择从观测数据计算 P(y|do(x)) 的策略:
|
|
85
|
-
- **后门准则 / Back-door**:若 ∃ S 阻断 X→Y 所有后门路径且 S 不含 X 的后代,则 P(y|do(x)) = Σ_s P(y|x,S=s)·P(S=s)。
|
|
86
|
-
- **前门准则 / Front-door**:混淆不可观测但中介 M 可观测,且 X→M 无后门、M 阻断 X→Y 所有后门路径,则 P(y|do(x)) = Σ_m P(m|x)·Σ_z P(y|m,z)P(z)。
|
|
87
|
-
- **do-演算**:三规则在可观测量间转换 do-表达式(见核心原则数学形式化块)。
|
|
88
|
-
|
|
89
|
-
### 第四步:计算干预效果 / Compute Intervention Effects
|
|
90
|
-
用调整公式算 P(y|do(x)),与观察性 P(y|x) 对比衡量混淆偏差:
|
|
91
|
-
- 后门调整:P(y|do(x)) = Σ_z P(y|x,z)·P(z)——对 Z 所有取值加权平均。
|
|
92
|
-
- 混淆偏差:|P(y|do(x)) - P(y|x)|——偏差越大混淆越严重。
|
|
93
|
-
- 平均处理效应:ATE = E[Y|do(X=1)] - E[Y|do(X=0)] = E[Y(1)] - E[Y(0)]。
|
|
94
|
-
**关键**:P(y|do(x)) 与 P(y|x) 是否显著不同?不同则观察性分析有混淆偏差。
|
|
95
|
-
|
|
96
|
-
### 第五步:反事实分析 / Counterfactual Analysis
|
|
97
|
-
个体层面回顾性推理:若 X 是 x₁ 而非 x₀,Y 会怎样?
|
|
98
|
-
- **SCM**:Y = f(X, Z, U),U 为外生变量。
|
|
99
|
-
- **反事实计算**:给定观测 (x₀,y₀,z₀),反事实 Y_{x₁} = f(x₁, z₀, u₀)。
|
|
100
|
-
- **个体因果效应**:Y_{x₁} - Y_{x₀}——需结构方程。
|
|
101
|
-
**关键**:反事实依赖结构方程具体形式,对模型假设极敏感。
|
|
102
|
-
|
|
103
|
-
### 第六步:实验设计验证 / Experimental Design
|
|
104
|
-
- **RCT(黄金标准)**:随机化切断所有指向 X 的箭头,处理组与对照组在所有变量上期望相等;ATE = E[Y|do(X=1)] - E[Y|do(X=0)]。
|
|
105
|
-
- **自然实验**:利用自然发生的准随机事件(地震、政策变更)。
|
|
106
|
-
- **工具变量 IV**:V→X 且 V 到 Y 无直接路径、V 与 Y 无共同原因——用 V 创造的 X 变异估计因果效应。
|
|
107
|
-
- **双重差分 DD**:(Y₁^后-Y₁^前) - (Y₀^后-Y₀^前)。
|
|
108
|
-
|
|
109
|
-
### 第七步:敏感性分析 / Sensitivity Analysis
|
|
110
|
-
量化结论对未观测混淆的脆弱性:
|
|
111
|
-
- **Rosenbaum Γ**:对混淆强度 Γ,算结论可能翻转的最大 p-value——Γ 越大越脆弱。
|
|
112
|
-
- **E-value**:使效应估计归零所需的最小混淆强度——越大越稳健。
|
|
113
|
-
**关键**:未观测混淆 U 必须多强才能推翻结论?
|
|
114
|
-
|
|
115
|
-
## 常见错误 / Common Errors
|
|
116
|
-
|
|
117
|
-
| 错误 / Error | 批评 / Critique | 正确做法 / Correct Approach |
|
|
118
|
-
|---|---|---|
|
|
119
|
-
| 从相关直接推断因果 | P(y\|x)≠P(y\|do(x));相关可能由混淆创造 | 画 DAG 识别混淆,用后门调整算 P(y\|do(x)) |
|
|
120
|
-
| 忽略混淆变量 | 不调整时 \|P(y\|do(x))-P(y\|x)\|=混淆偏差 | 找 X、Y 所有共同祖先,调整可观测混淆 |
|
|
121
|
-
| 混淆 do(x) 与条件化 P(y\|x) | do(x) 切断指向 X 的箭头,条件化不切断 | 明确区分干预(强制设定)与观察(看到时) |
|
|
122
|
-
| 忽略中介效应 | X→M→Y 总效应=直接+间接 | 中介分析拆分直接/间接效应,前门准则可用 |
|
|
123
|
-
| 过度依赖单一 DAG | DAG 错则结论全错,不同 DAG 可能给相反结论 | 检验 DAG 合理性,比较多个备选 DAG |
|
|
124
|
-
| 忽略敏感性分析 | 未观测混淆可能推翻结论 | 用 Rosenbaum Γ 或 E-value 量化脆弱性 |
|
|
125
|
-
| 精确因果图搜索不可算 | DAG 空间超指数、NP-hard、不可微 | 连续松弛(NOTEARS)/启发式近似,过 GPU 八维门 |
|
|
126
|
-
|
|
127
|
-
## 操作规程 / Operating Procedure
|
|
128
|
-
|
|
129
|
-
当本 skill 被触发时,输出必须包含:
|
|
130
|
-
|
|
131
|
-
1. **[DAG]**:所有变量的有向无环图,标注每条箭头的假设依据。
|
|
132
|
-
2. **[混淆变量]**:列出 X、Y 的所有共同祖先,标注可观测/不可观测。
|
|
133
|
-
3. **[识别策略]**:后门/前门/do-演算,说明选择理由。
|
|
134
|
-
4. **[干预效果]**:P(y|do(x))=[值],用调整公式计算并与 P(y|x) 对比。
|
|
135
|
-
5. **[反事实]**:对关键个体/子群反事实推理,说明所需结构方程。
|
|
136
|
-
6. **[验证方法]**:RCT/自然实验/IV/DD,如何验证因果结论。
|
|
137
|
-
7. **[敏感性]**:Rosenbaum Γ 或 E-value,量化对未观测混淆的脆弱性。
|
|
138
|
-
8. **[GPU 可行性]**(若用于可解释性/OOD/DGP 建模的大规模估计):因果发现/估计方法过八维门,标注友好/可改造/不友好 + 改造建议。
|
|
139
|
-
|
|
140
|
-
**输出不得只给分析而无结论。**
|
|
141
|
-
|
|
142
|
-
## 与其他 skill 的关系 / Relations to Other Skills
|
|
143
|
-
|
|
144
|
-
- **概率与统计**:统计是因果的基础但不充分——P(y|x) 是关联,P(y|do(x)) 是因果效应;因果需额外假设。
|
|
145
|
-
- **建模思想**:因果 DAG 是结构模型——编码变量间因果机制假设,是建模的因果版本。
|
|
146
|
-
- **逻辑演绎**:从 DAG 假设出发,通过 do-演算三规则演绎因果结论。
|
|
147
|
-
- **信息论思想**:混淆变量制造虚假信号,因果推断从噪声中提取真实因果信号。
|
|
148
|
-
- **博弈思想**:策略互动中参与者的选择构成因果干预,均衡分析需因果推理。
|
|
149
|
-
- **现代数学激活**:`../../references/books/optimization-ml.md`(干预估计/regression、双重 ML)、`../../references/books/matrix-analysis.md`(条件独立检验、精度阵低秩近似)。
|
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
# 数学出处与经典文献 / Mathematical Sources and Classic Texts
|
|
2
|
-
|
|
3
|
-
## Wright 路径分析与 DAG / Wright's Path Analysis and DAGs (1921)
|
|
4
|
-
|
|
5
|
-
> 路径系数 p_{ij}:变量 i 对变量 j 的直接因果效应的标准化度量。
|
|
6
|
-
> 每条从 i 到 j 的路径的总效应 = 路径上各系数的乘积。
|
|
7
|
-
|
|
8
|
-
**含义**:因果结构可以用有向图表示,因果效应可以在图上沿路径计算——这是因果 DAG 的起源。
|
|
9
|
-
|
|
10
|
-
**数学背景**:Sewall Wright (1921) 在研究遗传学时发明路径图(path diagrams),用于分解性状的遗传与环境成分。路径分析的本质是结构方程模型(SEM)的图表示:每个变量的值由其直接原因和外生误差项决定,Y = Σ β_{ij}·X_j + ε_j。Wright 的路径追踪规则允许沿 DAG 路径计算变量间的总关联:r_{XY} = Σ(路径上系数乘积)。这一方法为 Pearl 的 DAG 框架奠定了基础。
|
|
11
|
-
|
|
12
|
-
**Significance**: Causal structure can be represented with directed graphs, and causal effects can be computed along paths on the graph — this is the origin of causal DAGs. Wright invented path diagrams in genetics to decompose hereditary and environmental components of traits. Path analysis is essentially the graphical representation of structural equation models (SEM).
|
|
13
|
-
|
|
14
|
-
**关键公式**:路径追踪规则(Wright's tracing rule):变量 i 与 j 间的总关联 r_{ij} = Σ(沿 i→j 的每条开放路径上路径系数乘积)。开放路径是指不经过同一变量两次(无回路)且不含"对撞"(collider)的路径——对撞是两条箭头同时指向的节点。对撞节点默认阻断路径,但若对撞被条件化,则路径重新开放——这就是"对撞偏差"(collider bias)的来源。
|
|
15
|
-
|
|
16
|
-
**Key formula**: Wright's tracing rule: total association r_{ij} = Σ(product of path coefficients along each open path from i to j). An open path has no loops and no colliders (nodes receiving two arrows). Colliders block paths by default, but conditioning on a collider opens the path — the origin of "collider bias."
|
|
17
|
-
|
|
18
|
-
## Fisher 随机化实验 / Fisher's Randomized Experiments (1935)
|
|
19
|
-
|
|
20
|
-
> 随机化不是忽视因果,而是使因果推断成为可能。
|
|
21
|
-
> 随机分配切断所有指向处理变量的因果箭头。
|
|
22
|
-
|
|
23
|
-
**含义**:科学实验的可信度不来自"精密控制",而来自"随机分配"——随机化是因果推断的黄金标准。
|
|
24
|
-
|
|
25
|
-
**数学背景**:R.A. Fisher 在《The Design of Experiments》(1935) 中提出随机化原则。核心论证:若处理 T 随机分配给个体,则 T 与任何混淆变量 Z 独立(P(Z|do(T)) = P(Z)),因此 P(Y|do(T)) = P(Y|T)。随机化消除了所有后门路径,无需识别具体混淆变量。Fisher 还提出零假设下的精确检验(permutation test):在 T 无效应假设下,所有可能分配的 Y 值分布相同,p-value = "观察到当前或更极端分配的概率"。
|
|
26
|
-
|
|
27
|
-
**Significance**: The credibility of scientific experiments comes not from "precise control" but from "random assignment" — randomization is the gold standard for causal inference. Fisher showed that if treatment T is randomly assigned, T is independent of any confounder Z, so P(Y|do(T)) = P(Y|T). Randomization eliminates all back-door paths without needing to identify specific confounders.
|
|
28
|
-
|
|
29
|
-
**Fisher 精确检验与置换推断**:Fisher 的 lady tasting tea 实验是随机化推断的经典案例。一位女士声称能分辨茶是先加奶还是后加奶。Fisher 设计了 8 杯茶(4 杯先加奶、4 杯后加奶),随机顺序呈现。在"女士无辨别能力"(零假设)下,正确猜中 4 杯先加奶的概率 = 1/C(8,4) = 1/70 ≈ 0.014。这一 p-value 不依赖任何分布假设——它完全基于随机化分配,是置换检验(permutation test)的起源。
|
|
30
|
-
|
|
31
|
-
## Wright 工具变量 / Wright's Instrumental Variables (1928)
|
|
32
|
-
|
|
33
|
-
> 工具变量 V 满足:(1) V → X(影响处理),(2) V 与 Y 无直接路径,(3) V 与 Y 无共同原因。
|
|
34
|
-
> IV 估计量:β_{IV} = Cov(Y,V)/Cov(X,V)。
|
|
35
|
-
|
|
36
|
-
**含义**:当混淆变量不可观测时,工具变量可以利用"外生变异"来估计因果效应——IV 创造的 X 的变异不受混淆影响。
|
|
37
|
-
|
|
38
|
-
**数学背景**:Philip Sewall Wright (1928) 在估计亚麻籽需求弹性时首次提出工具变量方法。他需要估计价格对需求量的因果效应,但价格与需求量之间存在双向因果关系(混淆)。Wright 引入一个只影响供给(从而影响价格)但不直接影响需求量的变量作为工具。IV 估计的逻辑:Cov(Y,V) = β_{因果}·Cov(X,V) + Cov(混淆,U·V),但 V 与混淆独立所以 Cov(混淆,U·V)=0,于是 β_{因果} = Cov(Y,V)/Cov(X,V)。当 IV 弱(Cov(X,V) 小),IV 估计的方差膨胀,需警惕弱工具变量问题。
|
|
39
|
-
|
|
40
|
-
**Significance**: When confounders are unobserved, instrumental variables exploit "exogenous variation" to estimate causal effects — the variation in X created by IV is unaffected by confounding. Wright first proposed IV estimation for flaxseed demand elasticity. The logic: since V is independent of confounders, β_{causal} = Cov(Y,V)/Cov(X,V). Weak IV (small Cov(X,V)) inflates variance — beware of weak instrument problems.
|
|
41
|
-
|
|
42
|
-
**经典 IV 案例**:
|
|
43
|
-
|
|
44
|
-
- **Angrist & Krueger (1991)**:用出生季度作为教育年数的工具变量——出生在年初的人因入学年龄规定而被迫多上一年学。IV 估计的教育回报率约 7%,高于 OLS 的 5%(OLS 受能力混淆向下偏)。
|
|
45
|
-
- **两阶段最小二乘 (2SLS)**:第一阶段 X̂ = π₀ + π₁·V(用 IV 预测 X);第二阶段 Y = β₀ + β₁·X̂(用预测值估计因果效应)。当 IV 强时(F-statistic > 10),2SLS 可靠;当 IV 弱时,2SLS 偏向 OLS 且置信区间膨胀。
|
|
46
|
-
|
|
47
|
-
**Classic IV cases**: Angrist & Krueger (1991) used birth quarter as IV for education years — those born early in the year were forced to attend more school. IV-estimated education return ~7% vs OLS ~5% (OLS biased down by ability confounding). 2SLS: first stage X̂ = π₀ + π₁·V, second stage Y = β₀ + β₁·X̂. Reliable when F > 10 (strong IV); biased toward OLS when IV is weak.
|
|
48
|
-
|
|
49
|
-
## Lewis 反事实语义 / Lewis's Counterfactual Semantics (1973)
|
|
50
|
-
|
|
51
|
-
> "如果 A 发生了(实际上没有),C 会怎样?" ——在 A 成立的可能世界中,C 是否成立?
|
|
52
|
-
> Counterfactual: "If A had occurred (which it didn't), would C have happened?" — In the possible world where A holds, does C hold?
|
|
53
|
-
|
|
54
|
-
**含义**:因果陈述本质上涉及反事实——"A 导致 C"意味着"如果 A 没发生,C 就不会发生"。反事实推理需要比较不同的可能世界。
|
|
55
|
-
|
|
56
|
-
**数学背景**:David Lewis (1973) 在《Counterfactuals》中提出可能世界语义来分析反事实条件句。核心概念:相似性 ordering — 在 A 成立的可能世界中,最接近现实世界的那个决定了反事实的真值。Lewis 的 VC (Variably Strict Conditional) 系统:A □→ C 为真,若在所有最接近的 A-世界中 C 成立。这一哲学框架为 Pearl 的结构因果模型中的反事实计算提供了语义基础——SCM 的反事实 Y_x(u) 就是在"设定 X=x"的可能世界中个体 u 的 Y 值。
|
|
57
|
-
|
|
58
|
-
**Significance**: Causal claims inherently involve counterfactuals — "A caused C" means "if A hadn't occurred, C wouldn't have." Counterfactual reasoning requires comparing different possible worlds. Lewis proposed possible-world semantics: the closest A-world to reality determines the truth of the counterfactual. This philosophical framework provided the semantic basis for Pearl's SCM counterfactuals — Y_x(u) is the value of Y for individual u in the world where X is set to x.
|
|
59
|
-
|
|
60
|
-
## Rubin 潜在结果框架 / Rubin's Potential Outcomes Framework (1974)
|
|
61
|
-
|
|
62
|
-
> 对于个体 i:Y_i(1) 为处理下的潜在结果,Y_i(0) 为对照下的潜在结果。
|
|
63
|
-
> 个体因果效应:τ_i = Y_i(1) - Y_i(0)(永远不可同时观测)。
|
|
64
|
-
> 平均处理效应:ATE = E[Y(1) - Y(0)]。
|
|
65
|
-
|
|
66
|
-
**含义**:因果效应是两个潜在结果之差——但每个个体只能观测到一个潜在结果,这是因果推断的根本难题("因果推断的根本问题" / fundamental problem of causal inference)。
|
|
67
|
-
|
|
68
|
-
**数学背景**:Donald Rubin (1974) 将 Neyman (1923) 在农业实验中的随机化推断框架推广为一般性的潜在结果模型(Neyman-Rubin causal model)。关键假设 SUTVA(Stable Unit Treatment Value Assumption):(1) 个体 i 的潜在结果不受他人处理分配影响,(2) 处理形式唯一(无不同版本)。在随机化下,ATE 的无偏估计为 τ̂ = Ȳ_1 - Ȳ_0。Rubin 的框架与 Pearl 的 DAG 框架是等价的:潜在结果模型是 SCM 中结构方程的隐式表示,DAG 是潜在结果模型中因果假设的显式表示。
|
|
69
|
-
|
|
70
|
-
**Significance**: The causal effect is the difference between two potential outcomes — but only one can be observed per individual, the "fundamental problem of causal inference." Rubin extended Neyman's framework into the general potential outcomes model (Neyman-Rubin causal model). SUTVA ensures no interference between units. Under randomization, ATE is unbiasedly estimated by τ̂ = Ȳ_1 - Ȳ_0. Rubin's framework is equivalent to Pearl's: potential outcomes are implicit structural equations, DAGs are explicit causal assumptions.
|
|
71
|
-
|
|
72
|
-
## Pearl 因果层级与 do-演算 / Pearl's Causal Hierarchy and Do-Calculus (2000)
|
|
73
|
-
|
|
74
|
-
> 因果层级:
|
|
75
|
-
> Level 1:P(y|x) — 关联 / Seeing
|
|
76
|
-
> Level 2:P(y|do(x)) — 干预 / Doing
|
|
77
|
-
> Level 3:P(y_x|x',y') — 反事实 / Imagining
|
|
78
|
-
>
|
|
79
|
-
> do-演算三条规则允许将干预表达式转化为可观测量。
|
|
80
|
-
|
|
81
|
-
**含义**:因果不是关联的强化版——"do(x)" 与 "observe x" 在数学上截然不同。do-演算提供了从观测数据计算因果效应的完整逻辑系统。
|
|
82
|
-
|
|
83
|
-
**数学背景**:Judea Pearl 在《Causality》(2000) 中建立了因果推断的数学框架。核心贡献:(1) 因果层级将推理能力从关联到干预到反事实分为三层,每层需要更强的建模假设;(2) do-演算三条规则给出了将 do-表达式转化为无 do 的可观测量表达式的完整规则集;(3) Pearl 证明了 do-演算的完备性——若一个 do-表达式可以转化为可观测量表达式,do-演算的三条规则必能找到这一转化。后门准则和前门准则是 do-演算的最重要特例。
|
|
84
|
-
|
|
85
|
-
**Significance**: Causation is not a strengthened version of correlation — "do(x)" and "observe x" are mathematically distinct. Do-calculus provides a complete logical system for computing causal effects from observational data. Pearl proved completeness: if a do-expression can be converted to an observational expression, the three rules of do-calculus will find it. The back-door and front-door criteria are the most important special cases.
|
|
86
|
-
|
|
87
|
-
## Card & Krueger 双重差分 / Card & Krueger Difference-in-Differences (1994)
|
|
88
|
-
|
|
89
|
-
> DD = (Y₁^{post} - Y₁^{pre}) - (Y₀^{post} - Y₀^{pre})
|
|
90
|
-
> 处理组的前后变化减去对照组的前后变化 = 纯因果效应。
|
|
91
|
-
|
|
92
|
-
**含义**:当 RCT 不可能时,可以利用干预前后处理组与对照组的差异变化来估计因果效应——前提是平行趋势假设成立。
|
|
93
|
-
|
|
94
|
-
**数学背景**:David Card 与 Alan Krueger (1994) 在研究最低工资对就业的影响时,比较了新泽西(提高最低工资)与宾夕法尼亚(未提高)的快餐业就业变化。DD 的关键假设:若无干预,处理组与对照组的趋势相同(平行趋势假设)。数学上,DD 估计量 τ̂_{DD} = (Ȳ_{NJ,post} - Ȳ_{NJ,pre}) - (Ȳ_{PA,post} - Ȳ_{PA,pre})。当平行趋势成立时,τ̂_{DD} = ATE。平行趋势可部分检验:比较干预前两个组的时间趋势是否一致。
|
|
95
|
-
|
|
96
|
-
**Significance**: When RCT is impossible, difference-in-differences estimates causal effects by comparing pre-post changes between treatment and control groups — provided the parallel trends assumption holds. Card & Krueger studied minimum wage effects on employment by comparing New Jersey (raised minimum wage) with Pennsylvania (did not). The parallel trends assumption can be partially tested by comparing pre-intervention trends.
|
|
97
|
-
|
|
98
|
-
## 中介分析:直接与间接效应 / Mediation Analysis: Direct and Indirect Effects
|
|
99
|
-
|
|
100
|
-
> X → M → Y:间接效应 = X 通过 M 对 Y 的影响
|
|
101
|
-
> X → Y:直接效应 = X 不通过 M 对 Y 的直接影响
|
|
102
|
-
> 总效应 = 直接效应 + 间接效应
|
|
103
|
-
|
|
104
|
-
**含义**:因果效应可以沿不同路径传播——拆分直接与间接效应有助于理解因果机制。
|
|
105
|
-
|
|
106
|
-
**数学背景**:Baron & Kenny (1986) 提出中介分析的经典方法(逐步回归法),但该方法有严重缺陷:依赖线性假设、忽略交互效应、无法处理混淆。Pearl (2001) 提出因果中介分析的定义:自然直接效应 NDE = E[Y_{x,M_{x'}}] - E[Y_{x',M_{x'}}](将 M 设为 x' 下自然值时,X 从 x' 变为 x 的效应);自然间接效应 NIE = E[Y_{x',M_x}] - E[Y_{x',M_{x'}}](X 保持 x' 时,M 从 x' 下自然值变为 x 下自然值的效应)。总效应 = NDE + NIE。这一定义不依赖线性假设。
|
|
107
|
-
|
|
108
|
-
**Significance**: Causal effects propagate along different paths — decomposing direct and indirect effects helps understand causal mechanisms. Baron & Kenny's (1986) classic method has serious flaws. Pearl (2001) defined causal mediation: natural direct effect NDE and natural indirect effect NIE, without requiring linearity. Total effect = NDE + NIE.
|
|
109
|
-
|
|
110
|
-
## Rosenbaum 敏感性分析 / Rosenbaum's Sensitivity Analysis (2002)
|
|
111
|
-
|
|
112
|
-
> 给定混淆强度 Γ:最大 odds ratio P(U=1|T=1)/P(U=1|T=0) ≤ Γ。
|
|
113
|
-
> 计算:在 Γ 下因果结论可能翻转的最大 p-value。
|
|
114
|
-
|
|
115
|
-
**含义**:因果结论必须评估其脆弱性——如果未观测混淆只需强度 Γ 就能推翻结论,则结论不稳健。
|
|
116
|
-
|
|
117
|
-
**数学背景**:Paul Rosenbaum 在《Observational Studies》(2002) 中系统化敏感性分析方法。核心思想:在随机化下 Γ=1(处理与混淆完全独立),Γ>1 表示存在未观测混淆的可能。对每个 Γ,计算:在最强可能混淆下,处理效应的最小 p-value。若 Γ=2 时 p-value 已超过显著性阈值,则结论对较弱混淆就脆弱;若 Γ=5 时 p-value 仍显著,则结论非常稳健。E-value (VanderWeele & Ding, 2017) 是相关概念:使效应估计归零所需的最小混淆强度,E-value = ATE + √(ATE² + ATE)。
|
|
118
|
-
|
|
119
|
-
**Significance**: Causal conclusions must be assessed for robustness — if an unobserved confounder of strength Γ can overturn the conclusion, it's fragile. Rosenbaum's method: for each Γ, compute the maximum p-value under the strongest possible confounding. If the conclusion remains significant at Γ=5, it's robust. The E-value quantifies the minimum confounding strength needed to nullify the effect estimate.
|
|
120
|
-
|
|
121
|
-
## Pearl 结构因果模型 / Pearl's Structural Causal Models (SCM)
|
|
122
|
-
|
|
123
|
-
> SCM = ⟨U, V, F, P(U)⟩
|
|
124
|
-
> U = 外生变量(不可观测的个体特征),V = 内生变量(可观测),F = 结构方程 {f_V}, P(U) = 外生分布
|
|
125
|
-
>
|
|
126
|
-
> 结构方程:V_i = f_i(PA_i, U_i),PA_i = V_i 的直接原因(父母节点)
|
|
127
|
-
|
|
128
|
-
**含义**:结构因果模型是因果推断的完整数学框架——它同时编码因果假设(DAG)、干预(do-演算)和反事实(结构方程)。
|
|
129
|
-
|
|
130
|
-
**数学背景**:Pearl 的 SCM 框架统一了因果推断的三个层级。核心数学对象:(1) DAG 编码因果假设——箭头 PA_i → V_i 表示 PA_i 是 V_i 的直接原因;(2) 结构方程 V_i = f_i(PA_i, U_i) 编码因果机制——f_i 是因果函数而非统计回归;(3) 干预 do(X=x) 的数学操作:将 X 的结构方程替换为 X=x,保持其他方程不变;(4) 反事实 Y_x(u) 的计算:在修改后的模型(X=x)中,给定外生变量 U=u,计算 Y 的值。SCM 的关键性质:从 SCM 可以推导出所有 Level 1-3 的量;反之,仅从 Level 1 数据无法唯一确定 SCM。
|
|
131
|
-
|
|
132
|
-
**Significance**: Structural Causal Models provide the complete mathematical framework for causal inference — they simultaneously encode causal assumptions (DAG), interventions (do-calculus), and counterfactuals (structural equations). The key property: from an SCM, all Level 1-3 quantities can be derived; conversely, Level 1 data alone cannot uniquely determine the SCM.
|
|
133
|
-
|
|
134
|
-
## 因果推断的根本问题 / The Fundamental Problem of Causal Inference
|
|
135
|
-
|
|
136
|
-
> 对于个体 i:τ_i = Y_i(1) - Y_i(0)
|
|
137
|
-
> 我们永远无法同时观测 Y_i(1) 和 Y_i(0)——只能看到其中一个。
|
|
138
|
-
|
|
139
|
-
**含义**:个体因果效应永远不可直接观测——这是因果推断的根本难题。一切因果推断方法本质上都是在试图用部分信息推断完整效应。
|
|
140
|
-
|
|
141
|
-
**数学背景**:Holland (1986) 明确阐述了这一根本问题。每个个体 i 有两个潜在结果 Y_i(treated) 和 Y_i(control),但现实世界只呈现其中一个。一切因果推断策略本质上都是绕过这一限制:(1) 随机化——用群体均值替代个体效应;(2) 前后比较——用个体之前状态近似对照状态(假设无时间趋势);(3) 回归调整——用可观测特征匹配近似个体;(4) 反事实建模——用结构方程预测未观测的潜在结果。每种策略都有其假设,违反假设则结论无效。
|
|
142
|
-
|
|
143
|
-
**Significance**: Individual causal effects can never be directly observed — this is the fundamental problem of causal inference. All causal inference strategies circumvent this limitation: (1) randomization — replace individual effects with group means; (2) before-after comparison — approximate control state; (3) regression adjustment — match on observables; (4) counterfactual modeling — predict unobserved potential outcomes. Each strategy has assumptions; violating them invalidates conclusions.
|
|
144
|
-
|
|
145
|
-
## Simpson 悖论与因果结构 / Simpson's Paradox and Causal Structure
|
|
146
|
-
|
|
147
|
-
> 同一数据在不同分组下给出相反结论:
|
|
148
|
-
> 整体:处理组恢复率更高;分组(按病情严重度):处理组恢复率更低。
|
|
149
|
-
|
|
150
|
-
**含义**:统计关联的方向取决于分析维度——Simpson 悖论揭示纯统计推理无法确定"哪个分组是正确的",必须依赖因果假设。
|
|
151
|
-
|
|
152
|
-
**数学背景**:Simpson 悖论的本质是混淆变量的干扰。经典案例:药物试验中,轻度患者多数被分配到处理组(恢复率高),重度患者多数被分配到对照组(恢复率低)。整体看处理组恢复率更高(因为处理组多为轻度患者),但按病情分组后处理组恢复率更低(药物实际有害)。Pearl 的因果解释:若病情 Z 是混淆变量(Z→T 且 Z→Y),则 P(Y|T=1) > P(Y|T=0) 是虚假关联,正确的因果效应 P(Y|do(T=1)) < P(Y|do(T=0)) 需要后门调整 P(Y|do(T)) = Σ_z P(Y|T,z)·P(z)。因果 DAG 决定了"应该按 Z 分组还是按整体计算"——没有因果模型,统计方法本身无法给出答案。
|
|
153
|
-
|
|
154
|
-
**Significance**: The direction of statistical association depends on the level of analysis — Simpson's paradox reveals that pure statistical reasoning cannot determine "which grouping is correct"; causal assumptions are required. Pearl's explanation: if Z is a confounder (Z→T and Z→Y), P(Y|T=1) > P(Y|T=0) is spurious. The correct causal effect P(Y|do(T=1)) < P(Y|do(T=0)) requires back-door adjustment. The causal DAG determines whether to condition on Z or not — without a causal model, statistics alone cannot answer.
|
|
155
|
-
|
|
156
|
-
## d-分离与条件独立性 / d-Separation and Conditional Independence
|
|
157
|
-
|
|
158
|
-
> 在 DAG G 中,路径 p 被 Z d-阻断,若 p 包含:
|
|
159
|
-
> (1) 一个链 A→B→C 且 B∈Z,或
|
|
160
|
-
> (2) 一个叉 A←B→C 且 B∈Z,或
|
|
161
|
-
> (3) 一个对撞 A→B←C 且 B∉Z(且 B 的后代∉Z)。
|
|
162
|
-
|
|
163
|
-
**含义**:d-分离是 DAG 编码的条件独立性——若 X 与 Y 被 Z d-分离,则 X ⊥ Y | Z 在所有由 G 产生的分布中成立。
|
|
164
|
-
|
|
165
|
-
**数学背景**:d-分离(directed separation)是 Pearl (1988) 提出的概念,连接因果图结构与概率分布的独立性。三条阻断规则对应三种路径类型:链(因果传导路径)、叉(混淆路径)、对撞(选择偏差路径)。d-分离的关键性质:(1) 若 X 与 Y 被 Z d-分离,则数据中应观察到 X ⊥ Y | Z——若观察到 X 与 Y 在给定 Z 时仍相关,则 DAG 可能错误;(2) d-分离是 DAG 的蕴涵——不需要知道具体参数值,仅从图结构即可推断独立性;(3) d-分离是因果推理的基础——后门路径就是不被空集 d-阻断的非因果路径。
|
|
166
|
-
|
|
167
|
-
**Significance**: d-separation is the conditional independence encoded by the DAG — if X and Y are d-separated by Z, then X ⊥ Y | Z holds in all distributions generated by G. The three blocking rules correspond to: chains (causal transmission), forks (confounding), colliders (selection bias). d-separation is foundational for causal reasoning — back-door paths are exactly non-causal paths not d-separated by the empty set.
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: discrete-combinatorial
|
|
3
|
-
description: |
|
|
4
|
-
触发:当需要计数、枚举、发现有限结构中的规律,或处理图论、组合结构、生成函数、递推关系;或为稀疏/路由/拓扑结构设计组合方案时调用。
|
|
5
|
-
English: Trigger when you need to count, enumerate, find patterns in finite structures, or handle graph theory, combinatorial structures, generating functions, recurrences; or design combinatorial schemes for sparse/routing/topological structures.
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
# 🧮 离散与组合思想 / Discrete & Combinatorial
|
|
9
|
-
|
|
10
|
-
> "计数是最古老的数学活动——有限对象蕴含无限规律。"
|
|
11
|
-
> "Counting is the oldest mathematical activity — finite objects harbor infinite patterns."
|
|
12
|
-
>
|
|
13
|
-
> —— 组合数学、图论、生成函数
|
|
14
|
-
> —— Combinatorics, Graph Theory, Generating Functions
|
|
15
|
-
|
|
16
|
-
## 核心原则 / Core Principle
|
|
17
|
-
|
|
18
|
-
**组合思想对有限结构进行系统计数、发现支配枚举的规律,并用生成函数等代数方法将计数问题变换为代数问题——有限的简单掌控无限的复杂。**
|
|
19
|
-
|
|
20
|
-
**Combinatorial thinking systematically counts finite structures, discovers patterns governing enumeration, and uses algebraic methods (generating functions) to recast counting as algebra — finite simplicity governing infinite complexity.**
|
|
21
|
-
|
|
22
|
-
> **数学形式化 / Mathematical Formalization**
|
|
23
|
-
>
|
|
24
|
-
> **鸽巢原理 (Pigeonhole Principle)**:n 个物品放入 m < n 个盒子,则某盒至少含 2 个;推广 kn+1 入 n 盒则某盒至少含 k+1。存在性证明利器——只证必然存在,不构造具体实例。
|
|
25
|
-
>
|
|
26
|
-
> **容斥原理 (Inclusion-Exclusion)**:|A₁∪...∪A_n| = Σ|A_i| − Σ|A_i∩A_j| + ... ± |A₁∩...∩A_n|;补集计数:"不具有 P" = 全部 − "具有 P"。
|
|
27
|
-
>
|
|
28
|
-
> **生成函数 (Generating Functions)**:常生成函数 OGF A(x)=Σa_n x^n(无序/组合,A·C 系数 = Σa_i·c_{n−i});指数生成函数 EGF B(x)=Σb_n x^n/n!(有序/有标号,B·D 系数/n! = Σ(b_i/i!)·(d_{n−i}/(n−i)!))。
|
|
29
|
-
>
|
|
30
|
-
> **Pólya 计数定理 (Pólya Enumeration)**:群 G 作用下的轨道计数 = (1/|G|)Σ_{g∈G}|Fix(g)|(Burnside 引理),用循环指标多项式刻画"旋转/翻转视为相同"的等价类着色计数。
|
|
31
|
-
>
|
|
32
|
-
> Euler 的洞察:将 1+2+3+... 的"发散级数"重新诠释为分拆计数的生成函数。
|
|
33
|
-
|
|
34
|
-
## GPU 友好性 / GPU-Friendliness(横切检查)
|
|
35
|
-
|
|
36
|
-
离散/组合结构常「美但不可算」——精确计数多为 #P 完备(着色计数、匹配计数),精确枚举 NP-hard(Hamilton 路、子集和),直接落 GPU 不可行。落 GPU 须过 `../../references/gpu-friendly-math.md` 八维门,改用可张量化的聚合与采样近似:
|
|
37
|
-
|
|
38
|
-
- **友好**:邻接矩阵幂迭代 A^k 计路径数(GEMM)、动态规划表批量并行、bitset packed 计数(popcount)、结构化稀疏图遍历。
|
|
39
|
-
- **可改造**:容斥/递推 → 半环聚合((min,+) / (max,+) / Boolean / 热带半环)张量化;精确计数 → 蒙特卡洛/重要性采样估计;枚举 → 分支定界剪枝 + 批量并行;离散选择 → Gumbel-softmax 松弛。
|
|
40
|
-
- **反模式**:精确全枚举(n! 爆炸)、串行回溯搜索、强串行 DP(长程依赖不可并行)、非结构化图随机访存——"美但不可算",须近似或松弛。
|
|
41
|
-
|
|
42
|
-
八维最低判定(正式术语):**张量化**看有限对象能否编码成矩阵/bitset/批量表;**GEMM 可映射**看递推能否半环矩阵化;**复杂度**明确 NP-hard/#P-hard 与近似界;**显存与 KV-Cache**检查枚举表、DP 表、邻接结构是否爆炸;**低精度稳定**看松弛采样和半环运算是否数值稳健;**并行与通信**看子问题是否独立或可斜扫描;**稀疏结构**只采用块/带状/规则图稀疏;**算子融合**看计数、mask、采样能否合并为少量 kernel。
|
|
43
|
-
|
|
44
|
-
> 配合 `../../references/books/abstract-algebra.md`(半环/有限域聚合)、`../../references/books/matrix-analysis.md`(邻接矩阵/谱图)。
|
|
45
|
-
|
|
46
|
-
## 不适用场景 / When NOT to Use
|
|
47
|
-
|
|
48
|
-
- **连续/分析性问题,无离散结构**——极限、微分、积分而非有限对象计数,属分析而非组合。
|
|
49
|
-
- **精确闭式公式可直接给出答案**——组合枚举是多余开销(如 n·(n−1) 直接代数运算)。
|
|
50
|
-
- **纯粹概率问题,无组合结构**——连续分布参数估计、贝叶斯更新不涉及有限集合计数,概率密度积分不是组合问题。
|
|
51
|
-
|
|
52
|
-
## 何时使用 / When to Use
|
|
53
|
-
|
|
54
|
-
- 需要计数配置数量(排列/选择/分配),答案是具体有限数而非 1 或无穷。
|
|
55
|
-
- 需通过鸽巢原理证存在性("必存在某对象具某性质")而不构造实例。
|
|
56
|
-
- 需发现枚举数列 {a_n} 的递推或封闭公式(如 Catalan C_n = (2n)!/(n!(n+1)!))。
|
|
57
|
-
- 需枚举满足约束的配置——按结构分类、按规则生成,非随机罗列。
|
|
58
|
-
- 需图/网络分析(连接、路径、匹配、着色、覆盖)——社交网络、调度、规划可化为图问题。
|
|
59
|
-
- 需求解递推关系求封闭公式或渐近行为——递推 → 生成函数 → 代数求解 → 提取系数。
|
|
60
|
-
- **为稀疏/路由/拓扑结构设计组合方案**——稀疏 attention 模式、路由表/拓扑排序、块结构化稀疏布局。
|
|
61
|
-
|
|
62
|
-
## 方法流程 / Method
|
|
63
|
-
|
|
64
|
-
### 第一步:识别离散结构与计数问题
|
|
65
|
-
明确**计数对象**(排列/组合/分拆/安排)、**目标**(总数/带约束子集/概率)、**约束**(互不相交、有序/无序、有标号/无标号)。分类:排列 P(n,k)=n!/(n−k)!;组合 C(n,k)=n!/(k!(n−k)!);分拆 p(n) 整数分拆、B(n) 集合分拆;安排(物品入位置)。
|
|
66
|
-
|
|
67
|
-
### 第二步:应用基本计数原理
|
|
68
|
-
- **乘法原理**:k 个独立选择 → k₁×k₂×...×k_n。
|
|
69
|
-
- **加法原理**:互斥选项 → |A∪B|=|A|+|B|(A∩B=∅)。
|
|
70
|
-
- **鸽巢原理**:n>m 碰撞不可避免,某盒至少 ⌈n/m⌉;推广 kn+1 入 n 盒则某盒至少含 k+1。
|
|
71
|
-
|
|
72
|
-
### 第三步:使用容斥原理
|
|
73
|
-
|A₁∪...∪A_n| = Σ|A_i| − Σ|A_i∩A_j| + Σ|A_i∩A_j∩A_k| − ... ± |A₁∩...∩A_n|。**补集计数**:"不具有 P" = 全部 − "具有 P";经典错排 D(n) = n! − C(n,1)(n−1)! + C(n,2)(n−2)! − ... ± C(n,n)·0!。**符号规则**:第 k 层贡献 = (−1)^{k+1} Σ|A_{i₁}∩...∩A_{i_k}|(奇层正、偶层负)。
|
|
74
|
-
|
|
75
|
-
### 第四步:构造生成函数
|
|
76
|
-
- **OGF**:A(x)=Σa_n x^n,无序/组合;A(x)·C(x) 系数 = Σa_i·c_{n−i}(组合两个独立计数)。
|
|
77
|
-
- **EGF**:B(x)=Σb_n x^n/n!,有序/排列/有标号;B(x)·D(x) 系数/n! = Σ(b_i/i!)·(d_{n−i}/(n−i)!)。
|
|
78
|
-
- 经典:分拆 P(x)=Σp(n)x^n = 1/((1−x)(1−x²)(1−x³)...);Catalan C(x)=ΣC_n x^n = (1−√(1−4x))/(2x),由 C_n=ΣC_i·C_{n−1−i} 得 C(x)=1+x·C(x)²。
|
|
79
|
-
|
|
80
|
-
### 第五步:分析图结构
|
|
81
|
-
图 G=(V,E),|V| 顶点、|E| 边。核心:度数 deg(v)、邻接/关联矩阵;路径/连通分量、最短路(Dijkstra、Floyd-Warshall);树恰 n−1 边、生成树(Kruskal/Prim)、二叉树计数 C_n;平面图 Euler 公式 V−E+F=2、E≤3V−6;色数 χ(G)、四色定理 χ(平面图)≤4;匹配(Hall 婚姻定理、König:二分图最大匹配=最小顶点覆盖);Euler 环(连通且全度数偶)、Hamilton 环(NP-complete)。
|
|
82
|
-
|
|
83
|
-
### 第六步:发现递推与封闭公式
|
|
84
|
-
- **递推**:Catalan C_n=ΣC_i·C_{n−1−i},Fibonacci F_n=F_{n−1}+F_{n−2},错排 D_n=(n−1)(D_{n−1}+D_{n−2})。
|
|
85
|
-
- **生成函数求解**:递推乘 x^n 求和 → 解 A(x) → 提取 a_n;Fibonacci F(x)=x/(1−x−x²),部分分式得 F_n=(φ^n−ψ^n)/√5(φ=(1+√5)/2)。
|
|
86
|
-
- **直接公式**:C(n,k)=n!/(k!(n−k)!)(n 选 k 无序);Catalan C_n=C(2n,n)/(n+1)(合法括号序列组合论证)。
|
|
87
|
-
|
|
88
|
-
### 第七步:验证与推广
|
|
89
|
-
检查小案例 n=0,1,2,3 手动枚举与公式对比;验证公式计数正确、递推自洽、边界条件无误(空结构计数为 1:C₀=1, F₀=0, F₁=1);推广至更一般参数或更深组合解释。
|
|
90
|
-
|
|
91
|
-
> **验证不是可选的——未经验证的计数公式不可信。** n=3 的手动枚举与公式对比是最低验证要求。
|
|
92
|
-
|
|
93
|
-
## 常见错误 / Common Errors
|
|
94
|
-
|
|
95
|
-
| 错误 / Error | 批评 / Critique | 正确做法 / Correct Approach |
|
|
96
|
-
|---|---|---|
|
|
97
|
-
| 漏计与重计 | 漏计:遗漏约束交互少计;重计:同配置多次计算 | 明确约束交互,容斥修正重计,补集修正漏计 |
|
|
98
|
-
| 忽略约束条件交互 | 约束非独立,交集须容斥处理 | 用容斥:并集 = 各集之和 − 交集 |
|
|
99
|
-
| 混淆排列与组合 | 排列计序 P(n,k)=n!/(n−k)!,组合不计序 C(n,k)=n!/(k!(n−k)!) | 先判有序/无序再选公式 |
|
|
100
|
-
| 错误使用容斥符号 | 奇层正、偶层负,符号错则结果偏差 | 严格按 (−1)^{k+1} 定符号 |
|
|
101
|
-
| 忽略生成函数收敛域 | 形式幂级数可忽略收敛,但提封闭公式须在收敛域内 | 区分形式操作与解析操作 |
|
|
102
|
-
| 混淆有标号/无标号 | 有标号用 EGF,无标号用 OGF | 排列/分布→EGF;组合/分拆→OGF |
|
|
103
|
-
| 鸽巢原理使用不当 | 仅证存在性不构造实例,需 n>m | 确认 n>m,结论为"至少一个"非"恰好一个" |
|
|
104
|
-
| 递推边界条件错误 | C₀=1 非 0;F₀=0, F₁=1 | 空结构=1,检查 n=0,1 边界 |
|
|
105
|
-
| GPU 不可算性 | 精确枚举/计数 #P 或 NP-hard 爆炸 | 改半环聚合/采样近似,过 GPU 八维门 |
|
|
106
|
-
|
|
107
|
-
## 操作规程 / Operating Procedure
|
|
108
|
-
|
|
109
|
-
当本 skill 被触发时,输出必须包含:
|
|
110
|
-
|
|
111
|
-
1. **结构识别**:`[结构]: [离散对象]` — 计数对象、约束、分类
|
|
112
|
-
2. **计数类型**:`[计数类型]: [排列/组合/分拆/安排]` — 有序/无序、有标号/无标号
|
|
113
|
-
3. **原理选择**:`[原理]: [乘法/加法/鸽巢/容斥]` — 选择理由
|
|
114
|
-
4. **生成函数**:`[生成函数]: [公式]` — GF 及代数性质(如涉及)
|
|
115
|
-
5. **图结构**:`[图结构]: [属性]` — 顶点/边/连通/着色(如涉及)
|
|
116
|
-
6. **递推/公式**:`[递推/公式]: [内容]` — 递推及封闭公式
|
|
117
|
-
7. **验证**:`[验证]: [小案例]` — 至少 n=0,1,2,3 手动枚举与公式对比
|
|
118
|
-
8. **[GPU 可行性]**(若用于算法/算子设计)— 精确计数/枚举是否 NP-hard/#P,能否半环聚合/张量化/采样近似,过八维门
|
|
119
|
-
|
|
120
|
-
**输出不得只给分析而无结论。**
|
|
121
|
-
|
|
122
|
-
## 与其他 skill 的关系 / Relations to Other Skills
|
|
123
|
-
|
|
124
|
-
- **归纳与类比**:组合规律由归纳发现——从 {a_n} 前几项归纳递推,再类比到更一般结构。
|
|
125
|
-
- **算法思想**:组合计数支撑复杂度分析——n!、C(n,k) 是算法代价估计基础。
|
|
126
|
-
- **概率与统计**:组合是概率的计算基础——古典概率 P(A)=|A|/|Ω|,分子分母皆组合计数。
|
|
127
|
-
- **变换思想**:生成函数将计数变换为代数——序列→幂级数,递推→方程,计数→系数提取。
|
|
128
|
-
- **公理化思想**:组合恒等式需严格证明——C(n,k)=C(n,n−k) 须代数或组合论证,不可仅凭直觉。
|
|
129
|
-
- **现代数学激活**:`../../references/books/abstract-algebra.md`(有限域/半环聚合、Burnside 计数)、`../../references/books/matrix-analysis.md`(邻接矩阵/谱图/传递矩阵)。
|