math-skill 1.0.0 → 2.1.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 +313 -0
- package/README.md +313 -278
- package/agents/math-critic.en.md +235 -0
- package/agents/math-critic.md +237 -203
- package/commands/abstraction.md +11 -34
- package/commands/algorithmic-thinking.md +11 -34
- package/commands/ask.md +18 -21
- package/commands/axiomatization.md +11 -34
- package/commands/causal-inference.md +11 -34
- package/commands/discrete-combinatorial.md +11 -34
- package/commands/game-theory.md +11 -34
- package/commands/induction-analogy.md +11 -34
- package/commands/information-theory.md +11 -34
- package/commands/logic-deduction.md +11 -34
- package/commands/modeling.md +11 -37
- package/commands/optimization.md +11 -33
- package/commands/probability-statistics.md +11 -36
- package/commands/symmetry-invariance.md +11 -34
- package/commands/topological-thinking.md +11 -33
- package/commands/transformation.md +11 -33
- package/knowledge-base/overview.en.md +228 -0
- package/knowledge-base/overview.md +230 -230
- package/package.json +73 -59
- package/references/agentic-workflow.en.md +53 -0
- package/references/agentic-workflow.md +55 -0
- package/references/books/abstract-algebra.md +124 -0
- package/references/books/algebraic-geometry-rising-sea.md +171 -0
- package/references/books/differential-geometry.md +140 -0
- package/references/books/matrix-analysis.md +146 -0
- package/references/books/micro-lie-theory.md +116 -0
- package/references/books/optimization-ml.md +164 -0
- package/references/books/smooth-manifolds.md +105 -0
- package/references/gpu-friendly-math.en.md +65 -0
- package/references/gpu-friendly-math.md +67 -0
- package/references/inspiration.en.md +113 -0
- package/{docs → references}/inspiration.md +2 -0
- package/skills/abstraction/SKILL.en.md +117 -0
- package/skills/abstraction/SKILL.md +121 -264
- package/skills/abstraction/original-texts.en.md +163 -0
- package/skills/algorithmic-thinking/SKILL.en.md +132 -0
- package/skills/algorithmic-thinking/SKILL.md +138 -371
- package/skills/algorithmic-thinking/original-texts.en.md +253 -0
- package/skills/axiomatization/SKILL.en.md +144 -0
- package/skills/axiomatization/SKILL.md +151 -213
- package/skills/axiomatization/original-texts.en.md +154 -0
- package/skills/causal-inference/SKILL.en.md +147 -0
- package/skills/causal-inference/SKILL.md +151 -374
- package/skills/causal-inference/original-texts.en.md +136 -0
- package/skills/discrete-combinatorial/SKILL.en.md +124 -0
- package/skills/discrete-combinatorial/SKILL.md +131 -286
- package/skills/discrete-combinatorial/original-texts.en.md +184 -0
- package/skills/game-theory/SKILL.en.md +117 -0
- package/skills/game-theory/SKILL.md +123 -318
- package/skills/game-theory/original-texts.en.md +131 -0
- package/skills/induction-analogy/SKILL.en.md +145 -0
- package/skills/induction-analogy/SKILL.md +152 -310
- package/skills/induction-analogy/original-texts.en.md +140 -0
- package/skills/information-theory/SKILL.en.md +134 -0
- package/skills/information-theory/SKILL.md +140 -242
- package/skills/information-theory/original-texts.en.md +127 -0
- package/skills/logic-deduction/SKILL.en.md +130 -0
- package/skills/logic-deduction/SKILL.md +135 -280
- package/skills/logic-deduction/original-texts.en.md +160 -0
- package/skills/math-research-activator/SKILL.en.md +132 -0
- package/skills/math-research-activator/SKILL.md +136 -0
- package/skills/math-research-activator/original-texts.en.md +105 -0
- package/skills/{meta-selector → math-research-activator}/original-texts.md +104 -104
- package/skills/modeling/SKILL.en.md +135 -0
- package/skills/modeling/SKILL.md +139 -318
- package/skills/modeling/original-texts.en.md +162 -0
- package/skills/optimization/SKILL.en.md +129 -0
- package/skills/optimization/SKILL.md +135 -292
- package/skills/optimization/original-texts.en.md +167 -0
- package/skills/probability-statistics/SKILL.en.md +146 -0
- package/skills/probability-statistics/SKILL.md +151 -312
- package/skills/probability-statistics/original-texts.en.md +191 -0
- package/skills/symmetry-invariance/SKILL.en.md +135 -0
- package/skills/symmetry-invariance/SKILL.md +139 -358
- package/skills/symmetry-invariance/original-texts.en.md +206 -0
- package/skills/topological-thinking/SKILL.en.md +124 -0
- package/skills/topological-thinking/SKILL.md +128 -273
- package/skills/topological-thinking/original-texts.en.md +134 -0
- package/skills/transformation/SKILL.en.md +120 -0
- package/skills/transformation/SKILL.md +124 -264
- package/skills/transformation/original-texts.en.md +204 -0
- package/docs/CLAUDE.md +0 -187
- package/skills/meta-selector/SKILL.md +0 -188
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: causal-inference
|
|
3
|
+
description: |
|
|
4
|
+
Trigger when a problem concerns correlation vs. 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.
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# 🔗 Causal Inference
|
|
8
|
+
|
|
9
|
+
> "Correlation is not causation — but causation can be sorted out. Key distinction: 'how is Y when we see X' is not the same as 'what if we did X.'"
|
|
10
|
+
>
|
|
11
|
+
> — Causal Inference, Structural Causal Models, Counterfactual Reasoning
|
|
12
|
+
|
|
13
|
+
## Core Principle
|
|
14
|
+
|
|
15
|
+
**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.**
|
|
16
|
+
|
|
17
|
+
> **Mathematical Formalization**
|
|
18
|
+
>
|
|
19
|
+
> Pearl's Causal Hierarchy:
|
|
20
|
+
> - **Level 1 — Association**: $P(y|x)$ — Seeing
|
|
21
|
+
> - **Level 2 — Intervention**: $P(y|do(x))$ — Doing
|
|
22
|
+
> - **Level 3 — Counterfactual**: $P(y_x|x',y')$ — Imagining
|
|
23
|
+
>
|
|
24
|
+
> **$do(x) \neq$ conditioning on $x$**: $do(x)$ severs all arrows pointing into $X$ (graph surgery), while conditioning on $x$ severs no arrows. Back-door adjustment: $P(y|do(x)) = \sum_z P(y|x,z)P(z)$
|
|
25
|
+
>
|
|
26
|
+
> **Potential Outcomes (Neyman-Rubin)**: $Y(x)$ denotes "the value $Y$ would take under intervention $X=x$"; individual treatment effect $\tau_i = Y_i(1)-Y_i(0)$; average treatment effect ATE $= E[Y(1)]-E[Y(0)] = E[Y|do(X=1)] - E[Y|do(X=0)]$.
|
|
27
|
+
>
|
|
28
|
+
> **Structural Causal Model (SCM)**: $Y := f(X, Z, U)$, where $U$ is exogenous; the DAG together with structural equations determines the counterfactual $Y_x = f(x, Z, U)$.
|
|
29
|
+
>
|
|
30
|
+
> **d-Separation**: A path is blocked by $Z$ $\iff$ a chain/fork middle node $\in Z$, or a collider $X\to C\leftarrow Y$ has $C$ and its descendants $\notin Z$. d-separation $X\perp_G Y|Z$ implies conditional independence; it is the tool for reading off causal assumptions from the graph.
|
|
31
|
+
>
|
|
32
|
+
> **Do-Calculus — Three Rules** (applied on modified graphs using d-separation):
|
|
33
|
+
> - Rule 1 (Insertion/deletion of observations): If $Y \perp Z \mid X$ in the graph with all arrows into $X$ removed, then $P(y|do(x),z) = P(y|do(x))$
|
|
34
|
+
> - Rule 2 (Exchange of intervention and observation): If $Y \perp Z \mid X$ in the graph with all arrows into $X$ removed and all arrows out of $Z$ removed, then $P(y|do(x),do(z)) = P(y|do(x),z)$
|
|
35
|
+
> - Rule 3 (Insertion/deletion of interventions): If $Y \perp Z \mid X$ in the graph with all arrows into $X$ removed and all arrows from $Z$ to $X$ along paths from $Z$ to $X$ removed, then $P(y|do(x),do(z)) = P(y|do(x))$
|
|
36
|
+
>
|
|
37
|
+
> **Causal reasoning requires an explicit causal model; it cannot be derived from data alone. The DAG encodes causal assumptions, and do-calculus transforms interventional expressions into observable quantities.**
|
|
38
|
+
>
|
|
39
|
+
> See `original-texts.md` for detailed mathematical foundations.
|
|
40
|
+
|
|
41
|
+
## GPU-Friendliness (Cross-Cutting Check)
|
|
42
|
+
|
|
43
|
+
When causal inference is used for **model interpretability / out-of-distribution generalization / data-generating process modeling** at scale, the methods themselves must pass through the eight-dimensional gate in `../../references/gpu-friendly-math.md`:
|
|
44
|
+
|
|
45
|
+
- **Effect estimation / adjustment regression**: Back-door adjustment, IPW, doubly-robust ML — conditional expectations and regression are all batch GEMM, tensorizable, fusible, low-precision viable — **friendly** (see `../../references/books/optimization-ml.md`).
|
|
46
|
+
- **Conditional independence testing**: High-dimensional conditional independence tests involve precision matrix (covariance inverse) inversion $O(p^3)$; can be reformed via **low-rank / diagonal approximation** or iterative solvers — **retrofittable** (see `../../references/books/matrix-analysis.md`).
|
|
47
|
+
- **Exact causal discovery (DAG search)**: DAG space grows super-exponentially with node count; exact score-based search is NP-hard, non-differentiable, serial — a classic "beautiful but intractable" anti-pattern.
|
|
48
|
+
- **Reform approach**: NOTEARS-style **continuous relaxation** (acyclicity constraint $h(W)=\text{tr}(e^{W\circ W})-p=0$) transforms discrete graph search into differentiable optimization; alternatively, MCMC / greedy + scoring as heuristic approximation.
|
|
49
|
+
- **Counterfactual / SCM simulation**: Forward simulation of structural equations is batch-parallelizable; however, individual counterfactuals depend on identifying exogenous $U$ — watch for serial dependencies.
|
|
50
|
+
|
|
51
|
+
Eight-dimensional minimum assessment (formal terms): **Tensorization** — whether samples / interventions / candidate graphs admit batched processing; **GEMM-mappability** — whether adjustment regression and representation learning fall into matrix multiplication; **Complexity** — whether causal discovery avoids super-exponential DAG search; **Memory and KV-Cache** — whether precision matrices, candidate graphs, and intermediate counterfactuals are compressible; **Low-precision stability** — whether IPW weights, covariance inverses, and logits are numerically robust; **Parallelism and communication** — whether multi-environment / multi-intervention estimation is parallelizable; **Sparse structure** — whether the DAG / SCM is structurally sparse; **Operator fusion** — whether scoring, masking, and loss can be fused.
|
|
52
|
+
|
|
53
|
+
> Use in conjunction with `../../references/books/optimization-ml.md` (intervention estimation / regression) and `../../references/books/matrix-analysis.md` (conditional independence / low-rank precision matrices).
|
|
54
|
+
|
|
55
|
+
## When NOT to Use
|
|
56
|
+
|
|
57
|
+
- **Pure prediction tasks with no causal question** (only $P(y|x)$ is needed, no interest in "why") — association is sufficient; causation is superfluous.
|
|
58
|
+
- **No encodable causal assumptions** (cannot draw a reasonable DAG; causal directions are uncertain) — without explicit assumptions, no causal conclusions can be drawn.
|
|
59
|
+
- **Deterministic systems with no variation** (inputs map strictly uniquely to outputs) — causation is fully described by the mechanism; the probabilistic causal framework is unnecessary.
|
|
60
|
+
|
|
61
|
+
## When to Use
|
|
62
|
+
|
|
63
|
+
- Need to know the effect of an intervention ("If we do X, what happens to Y?") — requires $P(y|do(x))$, not $P(y|x)$.
|
|
64
|
+
- Need to distinguish causes from confounders (Does X cause Y, or does Z cause both X and Y?) — DAGs identify confounding paths.
|
|
65
|
+
- Need counterfactual reasoning ("What would have happened if we had not done A?") — Level 3 requires structural equations.
|
|
66
|
+
- Need policy / treatment effect evaluation (back-door adjustment, IV, difference-in-differences when RCTs are infeasible).
|
|
67
|
+
- Need mediation analysis (decomposing direct and indirect effects along $X\to M\to Y$).
|
|
68
|
+
- Need to model the data-generating process (DGP) for **model interpretability / out-of-distribution generalization**, transforming predictor associations into actionable causal mechanisms.
|
|
69
|
+
|
|
70
|
+
## Method
|
|
71
|
+
|
|
72
|
+
### Step 1: Construct the Causal DAG
|
|
73
|
+
Identify all variables explicitly; draw causal arrows encoding direct-cause assumptions; verify acyclicity. Identify the cause variable $X$ (intervention target), outcome $Y$ (effect), confounders $Z$ (common causes of $X$ and $Y$), and mediators $M$ ($X\to M\to Y$). An arrow $X\to Y$ means "$X$ is a direct cause of $Y$"; the direction encodes a causal assumption. The DAG must be directed and acyclic — cycles indicate uncertain causal direction and require re-modeling. **Key question**: Is there sufficient domain knowledge to encode causal directions? Conclusions depend entirely on DAG correctness.
|
|
74
|
+
|
|
75
|
+
### Step 2: Identify Confounders
|
|
76
|
+
Confounders simultaneously affect $X$ and $Y$, creating spurious association — without adjustment, effect estimates are biased. **Definition**: $Z$ is a confounder $\iff$ $Z$ is a common cause of $X$ and $Y$ ($Z\to X$ and $Z\to Y$). **DAG identification**: find all common ancestors of $X$ and $Y$. **Back-door paths** $X\leftarrow Z\to Y$ create non-causal associations that must be blocked. **Key question**: Are all confounders observable? If unobserved confounders exist, back-door adjustment is unavailable and front-door criterion or instrumental variables are needed.
|
|
77
|
+
|
|
78
|
+
### Step 3: Choose Identification Strategy
|
|
79
|
+
Based on confounder observability, select a strategy for computing $P(y|do(x))$ from observational data:
|
|
80
|
+
- **Back-door criterion**: If $\exists S$ blocking all back-door paths from $X$ to $Y$ and $S$ contains no descendants of $X$, then $P(y|do(x)) = \sum_s P(y|x,S=s)\cdot P(S=s)$.
|
|
81
|
+
- **Front-door criterion**: Confounders are unobservable but mediator $M$ is observable, $X\to M$ has no back-door paths, and $M$ blocks all back-door paths from $X$ to $Y$; then $P(y|do(x)) = \sum_m P(m|x)\cdot\sum_z P(y|m,z)P(z)$.
|
|
82
|
+
- **Do-calculus**: Three rules transform do-expressions among observable quantities (see the Mathematical Formalization block in Core Principle).
|
|
83
|
+
|
|
84
|
+
### Step 4: Compute Intervention Effects
|
|
85
|
+
Use the adjustment formula to compute $P(y|do(x))$ and compare with the observational $P(y|x)$ to quantify confounding bias:
|
|
86
|
+
- Back-door adjustment: $P(y|do(x)) = \sum_z P(y|x,z)\cdot P(z)$ — weighted average over all values of $Z$.
|
|
87
|
+
- Confounding bias: $|P(y|do(x)) - P(y|x)|$ — larger bias indicates more severe confounding.
|
|
88
|
+
- Average treatment effect: ATE $= E[Y|do(X=1)] - E[Y|do(X=0)] = E[Y(1)] - E[Y(0)]$.
|
|
89
|
+
|
|
90
|
+
**Key question**: Are $P(y|do(x))$ and $P(y|x)$ significantly different? If so, observational analysis suffers from confounding bias.
|
|
91
|
+
|
|
92
|
+
### Step 5: Counterfactual Analysis
|
|
93
|
+
Individual-level retrospective reasoning: If $X$ had been $x_1$ instead of $x_0$, what would $Y$ have been?
|
|
94
|
+
- **SCM**: $Y = f(X, Z, U)$, where $U$ is exogenous.
|
|
95
|
+
- **Counterfactual computation**: Given observation $(x_0,y_0,z_0)$, the counterfactual $Y_{x_1} = f(x_1, z_0, u_0)$.
|
|
96
|
+
- **Individual causal effect**: $Y_{x_1} - Y_{x_0}$ — requires structural equations.
|
|
97
|
+
|
|
98
|
+
**Key point**: Counterfactuals depend on the specific form of the structural equations and are highly sensitive to model assumptions.
|
|
99
|
+
|
|
100
|
+
### Step 6: Experimental Design
|
|
101
|
+
- **RCT (gold standard)**: Randomization severs all arrows into $X$; treatment and control groups are equal in expectation on all variables; ATE $= E[Y|do(X=1)] - E[Y|do(X=0)]$.
|
|
102
|
+
- **Natural experiments**: Exploit naturally occurring quasi-random events (earthquakes, policy changes).
|
|
103
|
+
- **Instrumental variables (IV)**: $V\to X$ with no direct path from $V$ to $Y$ and no common cause of $V$ and $Y$ — use the variation in $X$ created by $V$ to estimate the causal effect.
|
|
104
|
+
- **Difference-in-differences (DD)**: $(Y_1^{\text{post}}-Y_1^{\text{pre}}) - (Y_0^{\text{post}}-Y_0^{\text{pre}})$.
|
|
105
|
+
|
|
106
|
+
### Step 7: Sensitivity Analysis
|
|
107
|
+
Quantify the vulnerability of conclusions to unobserved confounding:
|
|
108
|
+
- **Rosenbaum $\Gamma$**: For confounding strength $\Gamma$, compute the maximum $p$-value at which the conclusion could be overturned — larger $\Gamma$ means more vulnerable.
|
|
109
|
+
- **E-value**: The minimum confounding strength required to nullify the effect estimate — larger values indicate greater robustness.
|
|
110
|
+
|
|
111
|
+
**Key question**: How strong must an unobserved confounder $U$ be to overturn the conclusion?
|
|
112
|
+
|
|
113
|
+
## Common Errors
|
|
114
|
+
|
|
115
|
+
| Error | Critique | Correct Approach |
|
|
116
|
+
|---|---|---|
|
|
117
|
+
| Inferring causation directly from correlation | $P(y\|x)\neq P(y\|do(x))$; correlation may be created by confounding | Draw a DAG to identify confounders; use back-door adjustment to compute $P(y\|do(x))$ |
|
|
118
|
+
| Ignoring confounders | Without adjustment, $\|P(y\|do(x))-P(y\|x)\|$ equals confounding bias | Find all common ancestors of $X$ and $Y$; adjust for observable confounders |
|
|
119
|
+
| Confusing $do(x)$ with conditioning $P(y\|x)$ | $do(x)$ severs arrows into $X$; conditioning does not | Clearly distinguish intervention (forced setting) from observation (passive seeing) |
|
|
120
|
+
| Ignoring mediation effects | $X\to M\to Y$: total effect = direct + indirect | Perform mediation analysis to decompose direct / indirect effects; front-door criterion may apply |
|
|
121
|
+
| Over-reliance on a single DAG | If the DAG is wrong, all conclusions are wrong; different DAGs can yield opposite conclusions | Validate DAG plausibility; compare multiple candidate DAGs |
|
|
122
|
+
| Skipping sensitivity analysis | Unobserved confounders may overturn conclusions | Quantify vulnerability using Rosenbaum $\Gamma$ or E-value |
|
|
123
|
+
| Intractable exact causal graph search | DAG space is super-exponential, NP-hard, non-differentiable | Use continuous relaxation (NOTEARS) / heuristic approximation; pass through the GPU eight-dimensional gate |
|
|
124
|
+
|
|
125
|
+
## Operating Procedure
|
|
126
|
+
|
|
127
|
+
When this skill is triggered, the output must include:
|
|
128
|
+
|
|
129
|
+
1. **[DAG]**: Directed acyclic graph of all variables, with justification for each arrow's causal assumption.
|
|
130
|
+
2. **[Confounders]**: List all common ancestors of $X$ and $Y$; label each as observable / unobservable.
|
|
131
|
+
3. **[Identification Strategy]**: Back-door / front-door / do-calculus, with justification for the choice.
|
|
132
|
+
4. **[Intervention Effect]**: $P(y|do(x))$ = [value], computed via the adjustment formula and compared with $P(y|x)$.
|
|
133
|
+
5. **[Counterfactuals]**: Counterfactual reasoning for key individuals / subgroups, specifying the required structural equations.
|
|
134
|
+
6. **[Validation Method]**: RCT / natural experiment / IV / DD — how to validate causal conclusions.
|
|
135
|
+
7. **[Sensitivity]**: Rosenbaum $\Gamma$ or E-value, quantifying vulnerability to unobserved confounding.
|
|
136
|
+
8. **[GPU Feasibility]** (if used for large-scale estimation in interpretability / OOD / DGP modeling): Causal discovery / estimation method passes through the eight-dimensional gate; label friendly / retrofittable / unfriendly with reform suggestions.
|
|
137
|
+
|
|
138
|
+
**Output must not consist of analysis alone without conclusions.**
|
|
139
|
+
|
|
140
|
+
## Relations to Other Skills
|
|
141
|
+
|
|
142
|
+
- **Probability and Statistics**: Statistics is the foundation of causation but is insufficient — $P(y|x)$ is association, $P(y|do(x))$ is causal effect; causation requires additional assumptions.
|
|
143
|
+
- **Modeling Thinking**: Causal DAGs are structural models — they encode hypotheses about causal mechanisms among variables; causal modeling is the causal version of modeling.
|
|
144
|
+
- **Logical Deduction**: Starting from DAG assumptions, causal conclusions are deduced through the three rules of do-calculus.
|
|
145
|
+
- **Information Theory Thinking**: Confounders create spurious signals; causal inference extracts true causal signals from noise.
|
|
146
|
+
- **Game Theory Thinking**: Players' choices in strategic interaction constitute causal interventions; equilibrium analysis requires causal reasoning.
|
|
147
|
+
- **Modern Mathematics Activation**: `../../references/books/optimization-ml.md` (intervention estimation / regression, double ML), `../../references/books/matrix-analysis.md` (conditional independence testing, low-rank precision matrix approximation).
|