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.
- package/README.en-US.md +159 -200
- package/README.md +159 -200
- package/agents/math-critic.en.md +2 -2
- package/agents/math-critic.md +8 -8
- package/commands/ask.md +3 -10
- 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 +29 -218
- package/knowledge-base/overview.md +29 -220
- 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 +9 -3
- package/references/books/abstract-algebra.md +5 -5
- package/references/books/algebraic-geometry-rising-sea.md +5 -5
- package/references/books/differential-geometry.md +3 -3
- package/references/books/matrix-analysis.md +4 -4
- package/references/books/micro-lie-theory.md +3 -3
- package/references/books/optimization-ml.md +1 -1
- package/references/books/smooth-manifolds.md +3 -3
- package/references/gpu-friendly-math.en.md +8 -8
- package/references/gpu-friendly-math.md +2 -2
- package/references/inspiration.en.md +1 -1
- package/references/inspiration.md +2 -2
- package/skills/math-research-activator/SKILL.en.md +161 -106
- package/skills/math-research-activator/SKILL.md +162 -110
- package/skills/math-research-activator/original-texts.en.md +9 -9
- package/skills/math-research-activator/original-texts.md +11 -11
- package/commands/abstraction.md +0 -11
- package/commands/algorithmic-thinking.md +0 -11
- package/commands/axiomatization.md +0 -11
- package/commands/causal-inference.md +0 -11
- package/commands/discrete-combinatorial.md +0 -11
- package/commands/game-theory.md +0 -11
- package/commands/induction-analogy.md +0 -11
- package/commands/information-theory.md +0 -11
- package/commands/logic-deduction.md +0 -11
- package/commands/modeling.md +0 -11
- package/commands/optimization.md +0 -11
- package/commands/probability-statistics.md +0 -11
- package/commands/symmetry-invariance.md +0 -11
- package/commands/topological-thinking.md +0 -11
- package/commands/transformation.md +0 -11
- package/skills/abstraction/SKILL.en.md +0 -117
- package/skills/abstraction/SKILL.md +0 -121
- package/skills/abstraction/original-texts.en.md +0 -163
- package/skills/abstraction/original-texts.md +0 -175
- package/skills/algorithmic-thinking/SKILL.en.md +0 -132
- package/skills/algorithmic-thinking/SKILL.md +0 -138
- package/skills/algorithmic-thinking/original-texts.en.md +0 -253
- package/skills/algorithmic-thinking/original-texts.md +0 -256
- package/skills/axiomatization/SKILL.en.md +0 -144
- package/skills/axiomatization/SKILL.md +0 -151
- package/skills/axiomatization/original-texts.en.md +0 -154
- package/skills/axiomatization/original-texts.md +0 -160
- package/skills/causal-inference/SKILL.en.md +0 -147
- package/skills/causal-inference/SKILL.md +0 -151
- package/skills/causal-inference/original-texts.en.md +0 -136
- package/skills/causal-inference/original-texts.md +0 -167
- package/skills/discrete-combinatorial/SKILL.en.md +0 -124
- package/skills/discrete-combinatorial/SKILL.md +0 -131
- package/skills/discrete-combinatorial/original-texts.en.md +0 -184
- package/skills/discrete-combinatorial/original-texts.md +0 -185
- package/skills/game-theory/SKILL.en.md +0 -117
- package/skills/game-theory/SKILL.md +0 -123
- package/skills/game-theory/original-texts.en.md +0 -131
- package/skills/game-theory/original-texts.md +0 -131
- package/skills/induction-analogy/SKILL.en.md +0 -145
- package/skills/induction-analogy/SKILL.md +0 -152
- package/skills/induction-analogy/original-texts.en.md +0 -140
- package/skills/induction-analogy/original-texts.md +0 -154
- package/skills/information-theory/SKILL.en.md +0 -134
- package/skills/information-theory/SKILL.md +0 -140
- package/skills/information-theory/original-texts.en.md +0 -127
- package/skills/information-theory/original-texts.md +0 -127
- package/skills/logic-deduction/SKILL.en.md +0 -130
- package/skills/logic-deduction/SKILL.md +0 -135
- package/skills/logic-deduction/original-texts.en.md +0 -160
- package/skills/logic-deduction/original-texts.md +0 -173
- package/skills/modeling/SKILL.en.md +0 -135
- package/skills/modeling/SKILL.md +0 -139
- package/skills/modeling/original-texts.en.md +0 -162
- package/skills/modeling/original-texts.md +0 -165
- package/skills/optimization/SKILL.en.md +0 -129
- package/skills/optimization/SKILL.md +0 -135
- package/skills/optimization/original-texts.en.md +0 -167
- package/skills/optimization/original-texts.md +0 -168
- package/skills/probability-statistics/SKILL.en.md +0 -146
- package/skills/probability-statistics/SKILL.md +0 -151
- package/skills/probability-statistics/original-texts.en.md +0 -191
- package/skills/probability-statistics/original-texts.md +0 -193
- package/skills/symmetry-invariance/SKILL.en.md +0 -135
- package/skills/symmetry-invariance/SKILL.md +0 -139
- package/skills/symmetry-invariance/original-texts.en.md +0 -206
- package/skills/symmetry-invariance/original-texts.md +0 -221
- package/skills/topological-thinking/SKILL.en.md +0 -124
- package/skills/topological-thinking/SKILL.md +0 -128
- package/skills/topological-thinking/original-texts.en.md +0 -134
- package/skills/topological-thinking/original-texts.md +0 -164
- package/skills/transformation/SKILL.en.md +0 -120
- package/skills/transformation/SKILL.md +0 -124
- package/skills/transformation/original-texts.en.md +0 -204
- package/skills/transformation/original-texts.md +0 -216
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
# Mathematical Sources and Classic Texts
|
|
2
|
-
|
|
3
|
-
## Newton's *Principia Mathematica* (1687)
|
|
4
|
-
|
|
5
|
-
> "The same effects of nature must always be assigned to the same causes."
|
|
6
|
-
|
|
7
|
-
**The most important achievement in the history of mathematical modeling**: Newton unified celestial and terrestrial motion within a single mathematical framework — the law of universal gravitation F = GMm/r² and the three laws of motion. This was humanity's first systematic use of mathematical models to precisely describe the physical world, marking the birth of scientific modeling. The *Principia* established the methodological paradigm of "mathematical model → physical prediction → experimental verification," which remains the foundation of all modeling work to this day.
|
|
8
|
-
|
|
9
|
-
---
|
|
10
|
-
|
|
11
|
-
## Fourier's Heat Equation (1822)
|
|
12
|
-
|
|
13
|
-
> ∂u/∂t = κ ∇²u
|
|
14
|
-
|
|
15
|
-
In *Théorie analytique de la chaleur*, Fourier proposed a mathematical model for heat diffusion and, in doing so, invented Fourier analysis — the method of decomposing arbitrary functions into trigonometric series. This modeling achievement has a twofold significance: it provided a precise mathematical description of heat conduction, and it gave rise to the entire field of harmonic analysis. The Fourier transform remains a core tool in signal processing, quantum mechanics, image compression, and many other domains.
|
|
16
|
-
|
|
17
|
-
**Modeling insight**: The new mathematics invented to solve a modeling problem often has a more profound and lasting impact than the original model itself.
|
|
18
|
-
|
|
19
|
-
---
|
|
20
|
-
|
|
21
|
-
## Maxwell's Equations (1865)
|
|
22
|
-
|
|
23
|
-
> ∇·E = ρ/ε₀, ∇×E = -∂B/∂t
|
|
24
|
-
> ∇·B = 0, ∇×B = μ₀J + μ₀ε₀∂E/∂t
|
|
25
|
-
|
|
26
|
-
Maxwell unified electricity and magnetism into four partial differential equations, and from the mathematical model alone predicted the existence of electromagnetic waves — a prediction later confirmed experimentally by Hertz. This is one of the most brilliant examples in the history of modeling: the discovery of an entirely new physical phenomenon through pure mathematical deduction. The equations also imply the speed of light c = 1/√(μ₀ε₀), subsuming optics into electromagnetic theory — arguably the pinnacle of unification in modeling.
|
|
27
|
-
|
|
28
|
-
---
|
|
29
|
-
|
|
30
|
-
## Lotka-Volterra Predator-Prey Model (1925-1926)
|
|
31
|
-
|
|
32
|
-
The classical population dynamics model:
|
|
33
|
-
|
|
34
|
-
> dx/dt = αx - βxy (prey growth - predation)
|
|
35
|
-
> dy/dt = δxy - γy (predator growth - natural death)
|
|
36
|
-
|
|
37
|
-
**Modeling insight**: Through two simple differential equations, this model successfully explains the periodic oscillations observed in predator and prey populations in nature. It is the epitome of a "good model" — simple yet useful.
|
|
38
|
-
|
|
39
|
-
---
|
|
40
|
-
|
|
41
|
-
## Kermack-McKendrick SIR Epidemic Model (1927)
|
|
42
|
-
|
|
43
|
-
> dS/dt = -βSI (decrease in susceptibles)
|
|
44
|
-
> dI/dt = βSI - γI (change in infected)
|
|
45
|
-
> dR/dt = γI (increase in recovered)
|
|
46
|
-
|
|
47
|
-
**Modeling insight**: The basic reproduction number R₀ = β/γ determines whether an epidemic will take off. Kermack and McKendrick first proposed this model in their 1927 paper "A Contribution to the Mathematical Theory of Epidemics," laying the theoretical foundation for mathematical modeling of infectious diseases. This simple model was widely deployed during the COVID-19 pandemic, demonstrating the enduring value of classical models.
|
|
48
|
-
|
|
49
|
-
---
|
|
50
|
-
|
|
51
|
-
## Buckingham Pi Theorem (1914)
|
|
52
|
-
|
|
53
|
-
> If a physical relationship involves n variables with k independent dimensions, the relationship can be reduced to one among (n-k) dimensionless Π groups.
|
|
54
|
-
|
|
55
|
-
**Modeling insight**: The Buckingham Pi theorem formalizes dimensional analysis, an extremely important simplification tool in modeling. It tells us that any physical model can be cast in dimensionless form, thereby reducing the number of parameters and revealing essential structure. For example, the Reynolds number Re = ρvL/μ in fluid mechanics is a single Π quantity that unifies countless seemingly different flow regimes.
|
|
56
|
-
|
|
57
|
-
---
|
|
58
|
-
|
|
59
|
-
## Turing's Reaction-Diffusion Model (1952)
|
|
60
|
-
|
|
61
|
-
> ∂u/∂t = D_u ∇²u + f(u,v)
|
|
62
|
-
> ∂v/∂t = D_v ∇²v + g(u,v)
|
|
63
|
-
|
|
64
|
-
In his paper "The Chemical Basis of Morphogenesis," Turing proved that two chemical substances diffusing at different rates and interacting can generate stable spatial patterns — spots, stripes, spirals — from an initially uniform state. This is a mathematical model of morphogenesis, explaining a wide range of phenomena from leopard spots to seashell patterns.
|
|
65
|
-
|
|
66
|
-
**Modeling insight**: Mathematical models can explain "how order emerges from disorder" — no pre-existing pattern is required; patterns arise spontaneously from the dynamics of the equations alone. Turing thereby founded the theory of pattern formation.
|
|
67
|
-
|
|
68
|
-
---
|
|
69
|
-
|
|
70
|
-
## Lorenz System (1963)
|
|
71
|
-
|
|
72
|
-
> dx/dt = σ(y - x)
|
|
73
|
-
> dy/dt = x(ρ - y) - xz
|
|
74
|
-
> dz/dt = xy - βz
|
|
75
|
-
|
|
76
|
-
While numerically simulating an atmospheric convection model, Lorenz discovered that tiny differences in initial conditions lead to completely different long-term behavior — the "butterfly effect." Three seemingly simple equations revealed the essential feature of chaos: the long-term unpredictability of deterministic systems.
|
|
77
|
-
|
|
78
|
-
**Modeling insight**: Chaos theory profoundly changed the philosophy of modeling — even if a model is perfectly correct, long-term prediction may be fundamentally impossible. Modelers must distinguish between "predictable timescales" and "unpredictable chaotic regimes."
|
|
79
|
-
|
|
80
|
-
---
|
|
81
|
-
|
|
82
|
-
## Kalman Filtering (1960)
|
|
83
|
-
|
|
84
|
-
> x̂_{k|k} = x̂_{k|k-1} + K_k(z_k - H x̂_{k|k-1})
|
|
85
|
-
|
|
86
|
-
The Kalman filter is a recursive estimation method based on state-space models: it uses the system dynamics model to predict the state and then corrects the prediction with observational data. It unifies "model prediction" and "data updating" within a single mathematical framework and is a cornerstone of modern control theory and signal processing.
|
|
87
|
-
|
|
88
|
-
**Modeling insight**: Good modeling is not only about "building a model" but also about "making optimal estimates based on the model." The Kalman filter demonstrates how models and data work together — the model provides the prior, the data provide the correction, and neither is dispensable.
|
|
89
|
-
|
|
90
|
-
---
|
|
91
|
-
|
|
92
|
-
## Pólya's *How to Solve It* (1945)
|
|
93
|
-
|
|
94
|
-
> "The first step in mathematical modeling is understanding the problem, the second is devising a plan, the third is carrying out the plan, and the fourth is looking back."
|
|
95
|
-
|
|
96
|
-
Pólya's problem-solving framework is a precursor to modeling thinking: transforming an unfamiliar problem into a known mathematical problem.
|
|
97
|
-
|
|
98
|
-
---
|
|
99
|
-
|
|
100
|
-
## Akaike Information Criterion (1974)
|
|
101
|
-
|
|
102
|
-
> AIC = -2 ln(L_max) + 2k
|
|
103
|
-
|
|
104
|
-
In 1974, Akaike proposed AIC, formalizing the model selection problem for the first time: striking an optimal balance between goodness of fit (-2 ln L) and model complexity (2k), where k is the number of parameters and L_max is the maximum likelihood.
|
|
105
|
-
|
|
106
|
-
**Modeling insight**: AIC established a mathematical standard for the "principle of parsimony" — neither the most complex nor the simplest model is best; rather, the optimal trade-off lies in minimizing information loss while keeping parameters parsimonious. This is the quantitative version of Box's dictum that "some are useful."
|
|
107
|
-
|
|
108
|
-
---
|
|
109
|
-
|
|
110
|
-
## Black-Scholes Model (1973)
|
|
111
|
-
|
|
112
|
-
> C = S N(d₁) - K e^{-rT} N(d₂)
|
|
113
|
-
> d₁ = [ln(S/K) + (r + σ²/2)T] / (σ√T)
|
|
114
|
-
> d₂ = d₁ - σ√T
|
|
115
|
-
|
|
116
|
-
Black, Scholes, and Merton developed a mathematical model for option pricing. Based on geometric Brownian motion dS = μS dt + σS dW and the no-arbitrage principle, they derived the partial differential equation ∂C/∂t + ½σ²S²∂²C/∂S² + rS∂C/∂S - rC = 0. This model is the most celebrated result in financial mathematics; Scholes and Merton were awarded the 1997 Nobel Prize in Economics for this work.
|
|
117
|
-
|
|
118
|
-
**Modeling insight**: The Black-Scholes model is the best illustration of Box's dictum — its assumptions (constant volatility, continuous trading, frictionless markets) are all "wrong" in reality, yet it provides the core framework for pricing and risk management, and is therefore "useful."
|
|
119
|
-
|
|
120
|
-
---
|
|
121
|
-
|
|
122
|
-
## George Box's Famous Quote
|
|
123
|
-
|
|
124
|
-
> "All models are wrong, but some are useful."
|
|
125
|
-
|
|
126
|
-
**Modeling philosophy**:
|
|
127
|
-
- A model is not reality — it is necessarily a simplification of reality
|
|
128
|
-
- The value of a model lies not in its "truthfulness" but in its predictive and explanatory power
|
|
129
|
-
- Criteria for a good model: parsimonious, testable, predictive
|
|
130
|
-
|
|
131
|
-
---
|
|
132
|
-
|
|
133
|
-
## General Principles of Modeling
|
|
134
|
-
|
|
135
|
-
1. **Start simple**: Begin with the simplest model, then incrementally add complexity (Lorenz revealed chaos with three equations; Lotka-Volterra explained oscillations with two)
|
|
136
|
-
2. **State assumptions explicitly**: Record and test every assumption (Black-Scholes assumptions, though wrong, are explicit — and so the model remains usable)
|
|
137
|
-
3. **Validate and falsify**: Test models with independent data, not just by fitting (AIC quantifies the risk of overfitting)
|
|
138
|
-
4. **Know the scope**: Every model has a domain of validity; beyond it, the model fails (Newtonian mechanics fails at high velocities and requires Einstein's correction)
|
|
139
|
-
5. **Iterate**: Modeling is a cyclical process, not a one-shot endeavor (Pólya's "looking back" step)
|
|
140
|
-
6. **Unify dimensions**: Use the Buckingham Pi theorem to cast models in dimensionless form, reducing parameters and revealing structure
|
|
141
|
-
7. **Synergize models and data**: The Kalman filter demonstrates how model prediction and data correction work in a feedback loop
|
|
142
|
-
|
|
143
|
-
---
|
|
144
|
-
|
|
145
|
-
## Timeline of Mathematical Modeling
|
|
146
|
-
|
|
147
|
-
| Year | Achievement | Field |
|
|
148
|
-
|------|-------------|-------|
|
|
149
|
-
| 1687 | Newton *Principia* | Mechanics |
|
|
150
|
-
| 1822 | Fourier heat equation | Heat diffusion |
|
|
151
|
-
| 1865 | Maxwell's equations | Electromagnetism |
|
|
152
|
-
| 1914 | Buckingham Pi theorem | Dimensional analysis |
|
|
153
|
-
| 1925-26 | Lotka-Volterra | Population dynamics |
|
|
154
|
-
| 1927 | Kermack-McKendrick SIR | Epidemiology |
|
|
155
|
-
| 1945 | Pólya *How to Solve It* | Methodology |
|
|
156
|
-
| 1952 | Turing reaction-diffusion | Morphogenesis |
|
|
157
|
-
| 1960 | Kalman filter | Estimation & control |
|
|
158
|
-
| 1963 | Lorenz system | Chaos theory |
|
|
159
|
-
| 1973 | Black-Scholes | Finance |
|
|
160
|
-
| 1974 | Akaike AIC | Model selection |
|
|
161
|
-
|
|
162
|
-
This timeline reveals a central pattern: great modeling achievements often transcend disciplinary boundaries. Newton unified the heavens and the earth, Maxwell unified electricity and magnetism, Turing unified chemistry and biology — the power of mathematical models lies precisely in their cross-domain universality.
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
# 数学出处与经典文献 / Mathematical Sources and Classic Texts
|
|
2
|
-
|
|
3
|
-
## Newton《自然哲学的数学原理》/ *Principia Mathematica* (1687)
|
|
4
|
-
|
|
5
|
-
> "自然界中的同一效应必须尽可能归因于同一原因。"
|
|
6
|
-
> "The same effects of nature must always be assigned to the same causes."
|
|
7
|
-
|
|
8
|
-
**数学建模史上最重要的成就**:Newton 将天体运动与地面运动统一在同一数学框架之下——万有引力定律 F = GMm/r² 与三大运动定律。这是人类首次用系统的数学模型精确描述物理世界,标志着科学建模的诞生。《原理》确立了"数学模型→物理预测→实验验证"的方法论范式,至今仍是所有建模工作的根基。
|
|
9
|
-
|
|
10
|
-
---
|
|
11
|
-
|
|
12
|
-
## Fourier 热传导方程 / Fourier's Heat Equation (1822)
|
|
13
|
-
|
|
14
|
-
> ∂u/∂t = κ ∇²u
|
|
15
|
-
|
|
16
|
-
Fourier 在《热的解析理论》中提出了热扩散的数学模型,并为此发明了 Fourier 分析——将任意函数分解为三角级数的方法。这一建模成就具有双重意义:既给出了热传导的精确数学描述,又催生了整个调和分析领域。Fourier 变换至今是信号处理、量子力学、图像压缩等领域的核心工具。
|
|
17
|
-
|
|
18
|
-
**建模启示**:解决一个建模问题所发明的新数学,往往比原模型本身更具深远影响。
|
|
19
|
-
|
|
20
|
-
---
|
|
21
|
-
|
|
22
|
-
## Maxwell 方程组 / Maxwell's Equations (1865)
|
|
23
|
-
|
|
24
|
-
> ∇·E = ρ/ε₀, ∇×E = -∂B/∂t
|
|
25
|
-
> ∇·B = 0, ∇×B = μ₀J + μ₀ε₀∂E/∂t
|
|
26
|
-
|
|
27
|
-
Maxwell 将电学与磁学统一为四个偏微分方程,从数学模型中预言了电磁波的存在——此预言后被 Hertz 实验证实。这是建模史上最辉煌的范例之一:仅凭数学推演便发现了全新的物理现象。方程还隐含光速 c = 1/√(μ₀ε₀),将光学纳入电磁理论,堪称统一建模的巅峰。
|
|
28
|
-
|
|
29
|
-
---
|
|
30
|
-
|
|
31
|
-
## Lotka-Volterra 捕食者-猎物模型 (1925-1926)
|
|
32
|
-
|
|
33
|
-
经典的种群动力学模型:
|
|
34
|
-
|
|
35
|
-
> dx/dt = αx - βxy (猎物增长 - 被捕食)
|
|
36
|
-
> dy/dt = δxy - γy (捕食者增长 - 自然死亡)
|
|
37
|
-
|
|
38
|
-
**建模启示**:通过两个简单的微分方程,成功解释了自然界中捕食者和猎物种群的周期性振荡现象。这是"好模型"的典范——简单但有用。
|
|
39
|
-
|
|
40
|
-
---
|
|
41
|
-
|
|
42
|
-
## Kermack-McKendrick SIR 传染病模型 (1927)
|
|
43
|
-
|
|
44
|
-
> dS/dt = -βSI (易感者减少)
|
|
45
|
-
> dI/dt = βSI - γI (感染者变化)
|
|
46
|
-
> dR/dt = γI (康复者增加)
|
|
47
|
-
|
|
48
|
-
**建模启示**:基本再生数 R₀ = β/γ 决定了疫情是否会爆发。Kermack 与 McKendrick 于 1927 年在论文 "A Contribution to the Mathematical Theory of Epidemics" 中首次提出此模型,奠定了传染病数学建模的理论基础。这个简单的模型在新冠疫情期间被广泛使用,证明了经典模型的持久价值。
|
|
49
|
-
|
|
50
|
-
---
|
|
51
|
-
|
|
52
|
-
## Buckingham Pi 定理 / Buckingham Pi Theorem (1914)
|
|
53
|
-
|
|
54
|
-
> 若物理关系涉及 n 个变量、含 k 个独立量纲,则该关系可简化为 (n-k) 个无量纲 Π 组之间的关系。
|
|
55
|
-
|
|
56
|
-
**建模启示**:Buckingham Pi 定理将量纲分析形式化,是建模中极其重要的简化工具。它告诉我们:任何物理模型都可化为无量纲形式,从而减少参数个数、揭示本质结构。例如,流体力学中雷诺数 Re = ρvL/μ 就是一个 Π 量,它统一了无数看似不同的流动情形。
|
|
57
|
-
|
|
58
|
-
---
|
|
59
|
-
|
|
60
|
-
## Turing 反应-扩散模型 / Turing's Reaction-Diffusion Model (1952)
|
|
61
|
-
|
|
62
|
-
> ∂u/∂t = D_u ∇²u + f(u,v)
|
|
63
|
-
> ∂v/∂t = D_v ∇²v + g(u,v)
|
|
64
|
-
|
|
65
|
-
Turing 在论文 "The Chemical Basis of Morphogenesis" 中证明:两种扩散速率不同的化学物质相互作用,可在均匀状态下产生稳定的空间图案——斑纹、条纹、螺旋等。这是形态发生的数学模型,解释了从豹斑到海贝壳花纹的广泛现象。
|
|
66
|
-
|
|
67
|
-
**建模启示**:数学模型可以解释"有序如何从无序中涌现"——无需预设图案,纯由方程动力学自发产生。Turing 由此开创了模式形成理论。
|
|
68
|
-
|
|
69
|
-
---
|
|
70
|
-
|
|
71
|
-
## Lorenz 系统 / Lorenz System (1963)
|
|
72
|
-
|
|
73
|
-
> dx/dt = σ(y - x)
|
|
74
|
-
> dy/dt = x(ρ - y) - xz
|
|
75
|
-
> dz/dt = xy - βz
|
|
76
|
-
|
|
77
|
-
Lorenz 在数值模拟大气对流模型时发现:初始条件的微小差异会导致完全不同的长期行为——即"蝴蝶效应"。三个看似简单的方程揭示了混沌的本质特征:确定性系统的长期不可预测性。
|
|
78
|
-
|
|
79
|
-
**建模启示**:混沌理论深刻改变了建模哲学——即便模型完全正确,长期预测也可能本质不可能。建模者必须区分"可预测的时间尺度"与"不可预测的混沌区域"。
|
|
80
|
-
|
|
81
|
-
---
|
|
82
|
-
|
|
83
|
-
## Kalman 滤波 / Kalman Filtering (1960)
|
|
84
|
-
|
|
85
|
-
> x̂_{k|k} = x̂_{k|k-1} + K_k(z_k - H x̂_{k|k-1})
|
|
86
|
-
|
|
87
|
-
Kalman 滤波是基于状态空间模型的递推估计方法:利用系统动力学模型预测状态,再用观测数据修正预测。它将"模型预测"与"数据更新"统一在一个数学框架中,是现代控制论与信号处理的基石。
|
|
88
|
-
|
|
89
|
-
**建模启示**:好的建模不仅是"建立模型",还包括"基于模型做最优估计"。Kalman 滤波展示了模型与数据如何协同工作——模型提供先验,数据提供校正,二者缺一不可。
|
|
90
|
-
|
|
91
|
-
---
|
|
92
|
-
|
|
93
|
-
## Pólya《怎样解题》/ *How to Solve It* (1945)
|
|
94
|
-
|
|
95
|
-
> "数学建模的第一步是理解问题,第二步是制定计划,第三步是执行计划,第四步是回顾。"
|
|
96
|
-
> "The first step in mathematical modeling is understanding the problem, the second is devising a plan, the third is carrying out the plan, and the fourth is looking back."
|
|
97
|
-
|
|
98
|
-
Pólya 的解题框架是建模思想的前身:将未知问题转化为已知的数学问题。
|
|
99
|
-
|
|
100
|
-
---
|
|
101
|
-
|
|
102
|
-
## Akaike 信息准则 / Akaike Information Criterion (1974)
|
|
103
|
-
|
|
104
|
-
> AIC = -2 ln(L_max) + 2k
|
|
105
|
-
|
|
106
|
-
Akaike 在 1974 年提出 AIC,首次将模型选择问题形式化:在拟合优度 (-2 ln L) 与模型复杂度 (2k) 之间寻求最优平衡。k 为参数个数,L_max 为最大似然。
|
|
107
|
-
|
|
108
|
-
**建模启示**:AIC 确立了"简约性原则"的数学标准——不是越复杂越好,也不是越简单越好,而是在信息损失最小化与参数简约化之间取最优折中。这是 Box 名言"有些是有用的"的量化版本。
|
|
109
|
-
|
|
110
|
-
---
|
|
111
|
-
|
|
112
|
-
## Black-Scholes 模型 / Black-Scholes Model (1973)
|
|
113
|
-
|
|
114
|
-
> C = S N(d₁) - K e^{-rT} N(d₂)
|
|
115
|
-
> d₁ = [ln(S/K) + (r + σ²/2)T] / (σ√T)
|
|
116
|
-
> d₂ = d₁ - σ√T
|
|
117
|
-
|
|
118
|
-
Black、Scholes 与 Merton 建立了期权定价的数学模型,基于几何布朗运动 dS = μS dt + σS dW 与无套利原理推导出偏微分方程 ∂C/∂t + ½σ²S²∂²C/∂S² + rS∂C/∂S - rC = 0。此模型是金融数学最著名的成果,Scholes 与 Merton 因此获 1997 年诺贝尔经济学奖。
|
|
119
|
-
|
|
120
|
-
**建模启示**:Black-Scholes 是 Box 名言的最佳注脚——模型假设(常数波动率、连续交易、无摩擦市场)在现实中都是"错的",但它提供了定价框架与风险管理的核心工具,因而是"有用的"。
|
|
121
|
-
|
|
122
|
-
---
|
|
123
|
-
|
|
124
|
-
## George Box 的名言 / George Box's Famous Quote
|
|
125
|
-
|
|
126
|
-
> "All models are wrong, but some are useful."
|
|
127
|
-
> "所有模型都是错的,但有些是有用的。"
|
|
128
|
-
|
|
129
|
-
**建模哲学**:
|
|
130
|
-
- 模型不是现实——它必然是对现实的简化
|
|
131
|
-
- 模型的价值不在于"真实性",而在于其预测和解释能力
|
|
132
|
-
- 好模型的标准:简洁(parsimonious)、可检验(testable)、有预测力(predictive)
|
|
133
|
-
|
|
134
|
-
---
|
|
135
|
-
|
|
136
|
-
## 建模的一般原则
|
|
137
|
-
|
|
138
|
-
1. **从简单开始**:先用最简单的模型,然后逐步增加复杂度(Lorenz 用三方程揭示混沌,Lotka-Volterra 用两方程解释振荡)
|
|
139
|
-
2. **明确假设**:每个假设都要记录和检验(Black-Scholes 的假设虽错但明确,因此仍可使用)
|
|
140
|
-
3. **验证与证伪**:用独立数据检验模型,而不仅是拟合数据(AIC 量化了过拟合的风险)
|
|
141
|
-
4. **适用范围**:每个模型都有其适用范围,超出范围即失效(Newton 力学在高速下失效,需 Einstein 修正)
|
|
142
|
-
5. **迭代改进**:建模是一个循环过程,不是一次性的(Pólya 的"回顾"步骤)
|
|
143
|
-
6. **量纲统一**:用 Buckingham Pi 定理将模型化为无量纲形式,减少参数、揭示结构
|
|
144
|
-
7. **模型与数据协同**:Kalman 滤波展示了模型预测与数据校正如何循环工作
|
|
145
|
-
|
|
146
|
-
---
|
|
147
|
-
|
|
148
|
-
## 建模史的时间线 / Timeline of Mathematical Modeling
|
|
149
|
-
|
|
150
|
-
| 年份 | 成就 | 领域 |
|
|
151
|
-
|------|------|------|
|
|
152
|
-
| 1687 | Newton *Principia* | 力学 / Mechanics |
|
|
153
|
-
| 1822 | Fourier 热方程 | 热传导 / Heat diffusion |
|
|
154
|
-
| 1865 | Maxwell 方程组 | 电磁学 / Electromagnetism |
|
|
155
|
-
| 1914 | Buckingham Pi 定理 | 量纲分析 / Dimensional analysis |
|
|
156
|
-
| 1925-26 | Lotka-Volterra | 种群动力学 / Population dynamics |
|
|
157
|
-
| 1927 | Kermack-McKendrick SIR | 传染病 / Epidemiology |
|
|
158
|
-
| 1945 | Pólya *How to Solve It* | 方法论 / Methodology |
|
|
159
|
-
| 1952 | Turing 反应-扩散 | 形态发生 / Morphogenesis |
|
|
160
|
-
| 1960 | Kalman 滤波 | 估计与控制 / Estimation & control |
|
|
161
|
-
| 1963 | Lorenz 系统 | 混沌 / Chaos theory |
|
|
162
|
-
| 1973 | Black-Scholes | 金融 / Finance |
|
|
163
|
-
| 1974 | Akaike AIC | 模型选择 / Model selection |
|
|
164
|
-
|
|
165
|
-
这条时间线揭示了一个核心规律:伟大的建模成就往往跨越学科边界。Newton 统一了天与地,Maxwell 统一了电与磁,Turing 统一了化学与生物学——数学模型的力量恰恰在于它的跨领域普适性。
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: optimization
|
|
3
|
-
description: |
|
|
4
|
-
Trigger when a problem involves resource allocation, trade-offs, maximizing/minimizing objectives, decisions under constraints; or needs convexity analysis, Lagrangian/KKT methods, duality structure; or choosing optimization methods for algorithm/operator/training design.
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
# Optimization
|
|
8
|
-
|
|
9
|
-
> "Under the most general constraints, find extrema of the objective -- convexity determines difficulty, KKT gives necessity, duality reveals structure."
|
|
10
|
-
>
|
|
11
|
-
> -- Optimization Theory & Operations Research
|
|
12
|
-
|
|
13
|
-
## Core Principle
|
|
14
|
-
|
|
15
|
-
**Any decision problem can be formulated as an optimization problem: maximizing (or minimizing) an objective subject to constraints. The essence of optimization is not the pursuit of "the best" in the abstract, but "the best among the feasible."**
|
|
16
|
-
|
|
17
|
-
The three core elements of optimization: **Objective**, **Constraints**, **Feasible set**.
|
|
18
|
-
|
|
19
|
-
> **Mathematical Formalization**
|
|
20
|
-
>
|
|
21
|
-
> General optimization problem: $\min_{x \in \mathbb{R}^n} f(x) \quad \text{s.t.} \quad g_i(x) \leq 0,\; i=1,\dots,m; \quad h_j(x) = 0,\; j=1,\dots,p$
|
|
22
|
-
>
|
|
23
|
-
> Lagrangian: $L(x, \lambda, \mu) = f(x) + \sum_i \lambda_i g_i(x) + \sum_j \mu_j h_j(x)$
|
|
24
|
-
>
|
|
25
|
-
> KKT conditions (essential necessary conditions, under Slater-type constraint qualifications): (1) Stationarity $\nabla_x L = 0$; (2) Primal feasibility $g_i \le 0, h_j = 0$; (3) Dual feasibility $\lambda_i \ge 0$; (4) Complementary slackness $\lambda_i g_i = 0$.
|
|
26
|
-
>
|
|
27
|
-
> Convexity: If $f$ and each $g_i$ are convex and each $h_j$ is linear, the problem is convex; in this case **KKT is sufficient**, and local optimality implies global optimality.
|
|
28
|
-
|
|
29
|
-
## GPU-Friendliness (Cross-Cutting Check)
|
|
30
|
-
|
|
31
|
-
When optimization is used for **algorithm/operator/training design**, the solution method itself must pass the eight-dimensional gate in `../../references/gpu-friendly-math.md`:
|
|
32
|
-
|
|
33
|
-
- **First-order methods (SGD/Adam)**: GEMM-friendly, parallelizable, viable in low precision; pay attention to optimizer state precision and distributed communication overhead.
|
|
34
|
-
- **Second-order / Newton methods**: Hessian inversion $O(n^3)$, memory explosion -- the classic "beautiful but incomputable" case -- adapt to **K-FAC / low-rank / diagonal approximations** (see `../../references/books/optimization-ml.md`, `matrix-analysis.md`).
|
|
35
|
-
- **Constraint projection**: Does the projection admit a closed form and is it tensorizable? Iterative projection requires caution regarding serial dependencies.
|
|
36
|
-
- **Distribution**: Can computation and communication overlap? Is gradient compression needed?
|
|
37
|
-
|
|
38
|
-
Eight-dimensional minimum assessment (formal terms): **Tensorization** -- whether objectives / constraints / gradients can be batched; **GEMM-mappability** -- whether the primary computation is matrix multiplication, HVP, or small K-FAC matrices; **Complexity** -- order of first-order / second-order / combinatorial solvers; **Memory & KV-Cache** -- optimizer states, Hessian storage, activation retention; **Low-precision stability** -- condition numbers, damping, loss scaling; **Parallelism & communication** -- gradient synchronization and communication overlap; **Sparse structure** -- whether preconditioners / constraints are block-structured; **Operator fusion** -- whether updates, clipping, and regularization can be fused.
|
|
39
|
-
|
|
40
|
-
> Cross-reference `../../references/books/optimization-ml.md` (Chong/Lu/Żak) and `../../references/books/matrix-analysis.md`.
|
|
41
|
-
|
|
42
|
-
## When NOT to Use
|
|
43
|
-
|
|
44
|
-
- **No clear evaluation criterion** (one does not know what "good" means) -- define the objective before optimizing.
|
|
45
|
-
- **Purely execution-oriented tasks** (e.g., formatting code) -- there is no optimization space.
|
|
46
|
-
- **The user has already decided on a plan** -- optimization is already complete.
|
|
47
|
-
- **The problem is essentially qualitative judgment rather than quantitative extremum** -- model first, then optimize.
|
|
48
|
-
|
|
49
|
-
## When to Use
|
|
50
|
-
|
|
51
|
-
- When one needs to determine whether a problem is convex in order to assess solution difficulty.
|
|
52
|
-
- Choosing optimization methods for algorithm/operator/training design and evaluating their GPU viability.
|
|
53
|
-
- Making rational decisions with quantifiable objectives under constraints.
|
|
54
|
-
- Systematic optimization of experimental design, resource allocation, and hyperparameter / architecture search.
|
|
55
|
-
- When one is uncertain whether the current strategy is optimal and wishes to perform a systematic analysis (convexity, duality, sensitivity).
|
|
56
|
-
|
|
57
|
-
## Method
|
|
58
|
-
|
|
59
|
-
### Step 1: Define the Objective
|
|
60
|
-
Clarify what is to be maximized / minimized. Key questions: Single-objective or multi-objective? Is it quantifiable (otherwise, find proxy variables)? Static or dynamic? **Is $f$ convex** (convex implies local = global; non-convex requires vigilance against local extrema)? A wrong objective leads further astray the further one proceeds.
|
|
61
|
-
|
|
62
|
-
### Step 2: List the Constraints
|
|
63
|
-
Distinguish **hard constraints** (physical / budget / deadline) from **soft constraints** (preferences / quality floors); mathematically classify: inequality $g_i(x)\le 0$ (defines the boundary of the feasible set), equality $h_j(x)=0$ (reduces dimensionality), linear (feasible set is a convex polyhedron) vs. nonlinear (may be non-convex).
|
|
64
|
-
|
|
65
|
-
### Step 3: Classify the Problem Type
|
|
66
|
-
|
|
67
|
-
| Type | Objective | Constraints | Key Property | Typical Method |
|
|
68
|
-
|------|-----------|-------------|--------------|----------------|
|
|
69
|
-
| LP (Linear Programming) | Linear | Linear inequalities | Optimum at a vertex | Simplex method |
|
|
70
|
-
| QP (Quadratic Programming) | Quadratic | Linear | Positive-definite QP is convex | Interior-point method |
|
|
71
|
-
| Convex optimization | Convex | Convex inequalities + linear equalities | Local = global | Gradient descent, interior-point methods |
|
|
72
|
-
| Non-convex optimization | Non-convex | Arbitrary | Multiple local extrema | Global search, simulated annealing |
|
|
73
|
-
| Combinatorial optimization | Discrete domain | Arbitrary | Frequently NP-hard | Branch-and-bound, heuristics |
|
|
74
|
-
| Stochastic optimization | Contains random terms | May include stochastic constraints | Expected optimum vs. stochastic feasibility | SAA, robust optimization |
|
|
75
|
-
|
|
76
|
-
### Step 4: Find the Optimal Solution
|
|
77
|
-
- **LP/QP/Convex**: Exploit convexity; gradient-based or interior-point methods guarantee convergence to the global optimum.
|
|
78
|
-
- **Non-convex**: Multi-start strategies, global search, or relaxation to convex approximations.
|
|
79
|
-
- **Combinatorial**: Exact solutions are often NP-hard -- branch-and-bound for small scale, heuristics / approximations for large scale.
|
|
80
|
-
- **Stochastic**: Sample Average Approximation (SAA) converts to a deterministic approximation.
|
|
81
|
-
- **Insufficient information**: A satisficing solution suffices.
|
|
82
|
-
|
|
83
|
-
### Step 5: Sensitivity Analysis
|
|
84
|
-
The Lagrange multiplier $\lambda_i^*$ is the **shadow price** of the $i$-th constraint -- relaxing the constraint by one unit improves the objective by approximately $\lambda_i^*$. Complementary slackness: $\lambda_i^*=0$ indicates an inactive constraint (no effect on the optimal solution); $\lambda_i^*>0$ indicates an active constraint (the optimal solution lies precisely at its boundary). Focus on: how the optimal solution changes under small perturbations of constraints / objective, and which constraints are active.
|
|
85
|
-
|
|
86
|
-
### Step 6: Multi-Objective & Pareto
|
|
87
|
-
Multi-objective problems $f_1,\dots,f_k$ generally have no single optimal solution. Pareto optimality: no feasible solution exists that improves all objectives simultaneously. Methods: **Weighted sum** $\min\sum w_i f_i$ (different weights trace different points on the Pareto front); **$\epsilon$-constraint method** $\min f_1$ s.t. $f_i\le\epsilon_i$ (sweep $\epsilon_i$ to cover the front).
|
|
88
|
-
|
|
89
|
-
### Step 7: Monitor Constraint Changes
|
|
90
|
-
The optimal solution depends on the constraints -- when constraints change, re-optimization is required. Changes in active constraints have the greatest impact (high shadow prices); small changes in inactive constraints typically do not affect the optimal solution.
|
|
91
|
-
|
|
92
|
-
## Common Errors
|
|
93
|
-
|
|
94
|
-
| Error | Critique | Correct Approach |
|
|
95
|
-
|-------|----------|------------------|
|
|
96
|
-
| Optimizing without a clear objective | Direction is undefined | Precisely define the objective first |
|
|
97
|
-
| Ignoring implicit constraints | The "optimal solution" is actually infeasible | Exhaustively verify all constraints |
|
|
98
|
-
| Getting trapped in local optima | Greedy methods on non-convex problems do not guarantee global optimality | Verify convexity; use multi-start / global methods for non-convex problems |
|
|
99
|
-
| Treating the optimum as unique | The optimal solution may not be unique | Check for the existence of multiple equivalent optima |
|
|
100
|
-
| Using single-objective methods for multi-objective problems | Different objectives require trade-offs | Employ Pareto analysis |
|
|
101
|
-
| Failing to verify convexity | Applying convex methods to non-convex problems | Determine convexity before selecting a method |
|
|
102
|
-
| Ignoring duality theory | The dual problem may be easier to solve | Construct the dual and exploit strong duality |
|
|
103
|
-
| Confusing feasibility with optimality | Feasible does not imply optimal | Verify feasibility first, then verify optimality |
|
|
104
|
-
| Ignoring computational / GPU complexity | Second-order methods / combinatorial optimization may be incomputable | Assess complexity, pass the GPU eight-dimensional gate, approximate when necessary |
|
|
105
|
-
| Forgetting to re-optimize | Failing to update when constraints change | Periodically check for constraint changes |
|
|
106
|
-
|
|
107
|
-
## Operating Procedure
|
|
108
|
-
|
|
109
|
-
When this skill is triggered, the output must include:
|
|
110
|
-
|
|
111
|
-
1. **Objective function**: `[Objective]: [Description]` + `[Convexity]: [Convex / Non-convex / Unknown]`
|
|
112
|
-
2. **Constraint list**: Each labeled `[Hard / Soft]` and `[Inequality / Equality]` `[Linear / Nonlinear]`
|
|
113
|
-
3. **Problem type classification**: `[Type]: [LP / QP / Convex / Non-convex / Combinatorial / Stochastic]`
|
|
114
|
-
4. **Feasible set analysis**: Which options are feasible? Which constraints are active?
|
|
115
|
-
5. **Optimal / satisficing solution**: `[Strategy]: [Gradient method / Interior-point / Global search / Satisficing / Pareto]`
|
|
116
|
-
6. **Sensitivity analysis**: Shadow prices of key constraints? How do conclusions change under X% variation?
|
|
117
|
-
7. **GPU viability** (if used for algorithm/operator/training): Does the solution method pass the eight-dimensional gate? Label as friendly / retrofittable / unfriendly, with adaptation recommendations.
|
|
118
|
-
8. **Action recommendations**: Explicitly state "Next, I will..."
|
|
119
|
-
|
|
120
|
-
**Output must not consist of analysis alone without conclusions.**
|
|
121
|
-
|
|
122
|
-
## Relations to Other Skills
|
|
123
|
-
|
|
124
|
-
- **Modeling**: Optimization requires prior modeling -- defining objectives and constraints is itself an act of modeling.
|
|
125
|
-
- **Probability and statistics**: Optimization under uncertainty requires stochastic / robust optimization.
|
|
126
|
-
- **Transformation**: Transforming to the dual problem often makes optimization easier; duality is the most profound transformation in optimization.
|
|
127
|
-
- **Game-theoretic thinking**: Multiple decision-makers simultaneously optimizing constitutes a game; the Nash equilibrium is the stable point of multi-player optimization.
|
|
128
|
-
- **Algorithmic thinking**: Solution methods depend on algorithm design -- convex optimization uses gradient methods, combinatorial optimization requires branch-and-bound / heuristics.
|
|
129
|
-
- **Modern mathematics activation**: `../../references/books/optimization-ml.md` (GPU-friendly optimizers, feasibility of second-order methods), `matrix-analysis.md` (condition numbers, low-rank, preconditioning).
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: optimization
|
|
3
|
-
description: |
|
|
4
|
-
触发:问题涉及资源分配、取舍、最大化/最小化目标、约束下决策;或需判断凸性、使用拉格朗日/KKT、分析对偶结构;或为算法/算子/训练设计选择优化方法时调用。
|
|
5
|
-
English: Trigger when a problem involves resource allocation, trade-offs, maximizing/minimizing objectives, decisions under constraints; or needs convexity analysis, Lagrangian/KKT methods, duality structure; or choosing optimization methods for algorithm/operator/training design.
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
> **语言路由**:若用户消息为英文,请读取并遵循同目录下的 `SKILL.en.md`,按其操作规程以英文输出;中文消息则继续使用本文件。
|
|
9
|
-
|
|
10
|
-
# ⚖️ 优化思想 / Optimization
|
|
11
|
-
|
|
12
|
-
> "在最一般的约束条件下,寻找目标函数的极值——凸性决定难度,KKT 给出必要条件,对偶揭示结构。"
|
|
13
|
-
> "Under the most general constraints, find extrema of the objective — convexity determines difficulty, KKT gives necessity, duality reveals structure."
|
|
14
|
-
>
|
|
15
|
-
> —— 最优化理论与运筹学 / Optimization Theory & Operations Research
|
|
16
|
-
|
|
17
|
-
## 核心原则 / Core Principle
|
|
18
|
-
|
|
19
|
-
**任何决策问题都可以表述为优化问题:在约束条件下最大化(或最小化)某个目标。优化的本质不是追求'最好',而是在约束下追求'可行中的最好'。**
|
|
20
|
-
|
|
21
|
-
**Any decision problem can be formulated as optimization: maximizing (or minimizing) an objective subject to constraints. The essence is not 'the best' in the abstract, but 'the best among the feasible'.**
|
|
22
|
-
|
|
23
|
-
优化的三个核心要素:**目标(Objective)**、**约束(Constraints)**、**可行域(Feasible set)**。
|
|
24
|
-
|
|
25
|
-
> **数学形式化 / Mathematical Formalization**
|
|
26
|
-
>
|
|
27
|
-
> 一般优化问题:$\min_{x \in \mathbb{R}^n} f(x) \quad \text{s.t.} \quad g_i(x) \leq 0,\; i=1,\dots,m; \quad h_j(x) = 0,\; j=1,\dots,p$
|
|
28
|
-
>
|
|
29
|
-
> 拉格朗日函数:$L(x, \lambda, \mu) = f(x) + \sum_i \lambda_i g_i(x) + \sum_j \mu_j h_j(x)$
|
|
30
|
-
>
|
|
31
|
-
> KKT 条件(核心必要条件,Slater 等正则性下):① 驻点 $\nabla_x L = 0$;② 原始可行 $g_i \le 0, h_j = 0$;③ 对偶可行 $\lambda_i \ge 0$;④ 互补松弛 $\lambda_i g_i = 0$。
|
|
32
|
-
>
|
|
33
|
-
> 凸性:若 $f$ 与各 $g_i$ 凸、各 $h_j$ 线性,则问题凸;此时 **KKT 充分**,局部最优 = 全局最优。
|
|
34
|
-
|
|
35
|
-
## GPU 友好性 / GPU-Friendliness(横切检查)
|
|
36
|
-
|
|
37
|
-
当优化用于**算法/算子/训练设计**时,求解方法本身必须过 `../../references/gpu-friendly-math.md` 八维门:
|
|
38
|
-
|
|
39
|
-
- **一阶法(SGD/Adam)**:GEMM 友好、可并行、低精度可行;注意优化器状态精度与分布式通信开销。
|
|
40
|
-
- **二阶/牛顿法**:Hessian 求逆 $O(n^3)$、显存爆炸——典型"美但不可算"→ 改造为 **K-FAC / 低秩 / 对角近似**(见 `../../references/books/optimization-ml.md`、`matrix-analysis.md`)。
|
|
41
|
-
- **约束投影**:投影是否有闭式、可张量化?迭代投影警惕串行依赖。
|
|
42
|
-
- **分布式**:计算/通信能否 overlap;是否需要梯度压缩。
|
|
43
|
-
|
|
44
|
-
八维最低判定(正式术语):**张量化**看目标/约束/梯度能否批量;**GEMM 可映射**看主计算是否为矩阵乘、HVP、K-FAC 小矩阵;**复杂度**明确一阶/二阶/组合求解阶;**显存与 KV-Cache**检查优化器状态、Hessian、激活保存;**低精度稳定**检查条件数、阻尼、loss scaling;**并行与通信**检查梯度同步和通信 overlap;**稀疏结构**看预条件/约束是否块结构化;**算子融合**看更新、裁剪、正则能否融合。
|
|
45
|
-
|
|
46
|
-
> 配合 `../../references/books/optimization-ml.md`(Chong/Lu/Żak)与 `../../references/books/matrix-analysis.md`。
|
|
47
|
-
|
|
48
|
-
## 不适用场景 / When NOT to Use
|
|
49
|
-
|
|
50
|
-
- **没有明确评价标准**(不知道什么是"好")——先定义目标再优化。
|
|
51
|
-
- **纯执行性任务**(如格式化代码)——没有优化空间。
|
|
52
|
-
- **用户已确定方案**——优化已完成。
|
|
53
|
-
- **本质是定性判断而非定量极值**——应先建模再优化。
|
|
54
|
-
|
|
55
|
-
## 何时使用 / When to Use
|
|
56
|
-
|
|
57
|
-
- 需要判断问题是否为凸优化以决定求解难度。
|
|
58
|
-
- 为算法/算子/训练设计选择优化方法,并评估其 GPU 可行性。
|
|
59
|
-
- 在约束条件下做可量化目标的理性决策。
|
|
60
|
-
- 实验设计、资源分配、超参/结构搜索的系统优化。
|
|
61
|
-
- 不确定当前策略是否最优,想系统分析(凸性、对偶、灵敏度)。
|
|
62
|
-
|
|
63
|
-
## 方法流程 / Method
|
|
64
|
-
|
|
65
|
-
### 第一步:定义目标 / Define the Objective
|
|
66
|
-
明确最大化/最小化什么。关键:单目标还是多目标?是否可量化(否则找代理变量)?静态还是动态?**$f$ 是否凸**(凸则局部=全局,非凸需警惕局部极值)?方向错了,走得越远越偏。
|
|
67
|
-
|
|
68
|
-
### 第二步:列出约束 / List the Constraints
|
|
69
|
-
区分**硬约束**(物理/预算/deadline)与**软约束**(偏好/质量下限);数学上分类:不等式 $g_i(x)\le 0$(定义可行域边界)、等式 $h_j(x)=0$(降维)、线性(可行域为凸多面体)vs 非线性(可能非凸)。
|
|
70
|
-
|
|
71
|
-
### 第三步:类型分类 / Classify the Problem Type
|
|
72
|
-
|
|
73
|
-
| 类型 | 目标 | 约束 | 核心性质 | 典型方法 |
|
|
74
|
-
|------|------|------|----------|----------|
|
|
75
|
-
| LP 线性规划 | 线性 | 线性不等式 | 最优在顶点 | 单纯形法 |
|
|
76
|
-
| QP 二次规划 | 二次 | 线性 | 正定 QP 为凸 | 内点法 |
|
|
77
|
-
| 凸优化 | 凸 | 凸不等式+线性等式 | 局部=全局 | 梯度下降、内点法 |
|
|
78
|
-
| 非凸优化 | 非凸 | 任意 | 多局部极值 | 全局搜索、模拟退火 |
|
|
79
|
-
| 组合优化 | 离散域 | 任意 | NP-hard 常见 | 分支定界、启发式 |
|
|
80
|
-
| 随机优化 | 含随机项 | 可能含随机 | 期望最优 vs 随机可行 | SAA、鲁棒优化 |
|
|
81
|
-
|
|
82
|
-
### 第四步:寻找最优解 / Find the Optimal Solution
|
|
83
|
-
- **LP/QP/凸**:利用凸性,梯度类或内点法保证收敛到全局最优。
|
|
84
|
-
- **非凸**:多起点、全局搜索,或松弛为凸近似。
|
|
85
|
-
- **组合**:精确解常 NP-hard——小规模分支定界,大规模启发式/近似。
|
|
86
|
-
- **随机**:样本平均近似(SAA)转化为确定性近似。
|
|
87
|
-
- **信息不足**:满意解(satisficing)即可。
|
|
88
|
-
|
|
89
|
-
### 第五步:灵敏度分析 / Sensitivity Analysis
|
|
90
|
-
拉格朗日乘子 $\lambda_i^*$ 为第 $i$ 个约束的**影子价格**——约束放松一单位,目标改善约 $\lambda_i^*$。互补松弛:$\lambda_i^*=0$ 为非活跃约束(对最优解无影响);$\lambda_i^*>0$ 为活跃约束(最优解恰在其边界)。关注:约束/目标微小变化时最优解如何变、哪些约束活跃。
|
|
91
|
-
|
|
92
|
-
### 第六步:多目标与帕累托 / Multi-Objective & Pareto
|
|
93
|
-
多目标 $f_1,\dots,f_k$ 通常无单一最优解。帕累托最优:不存在使所有目标同时改善的可行解。方法:**加权求和** $\min\sum w_i f_i$(不同权重对应前沿不同点);**$\epsilon$-约束法** $\min f_1$ s.t. $f_i\le\epsilon_i$(遍历 $\epsilon_i$ 覆盖前沿)。
|
|
94
|
-
|
|
95
|
-
### 第七步:监控约束变化 / Monitor Constraint Changes
|
|
96
|
-
最优解依赖约束——约束变了就要重新优化。活跃约束的变化影响最大(影子价格高),非活跃约束的微小变化通常不影响最优解。
|
|
97
|
-
|
|
98
|
-
## 常见错误 / Common Errors
|
|
99
|
-
|
|
100
|
-
| 错误 / Error | 批评 / Critique | 正确做法 / Correct Approach |
|
|
101
|
-
|-------------|----------------|---------------------------|
|
|
102
|
-
| 没有明确目标就优化 | 方向不确定 | 先精确定义目标 |
|
|
103
|
-
| 忽略隐式约束 | "最优解"实则不可行 | 穷尽检查所有约束 |
|
|
104
|
-
| 陷入局部最优 | 非凸贪心不保证全局 | 验证凸性;非凸用多起点/全局法 |
|
|
105
|
-
| 把最优当唯一 | 最优解可能不唯一 | 检查是否存在多个等价最优解 |
|
|
106
|
-
| 多目标用单目标方法 | 不同目标需 trade-off | 使用帕累托分析 |
|
|
107
|
-
| 未验证凸性 | 非凸误用凸方法 | 先判断凸性再选方法 |
|
|
108
|
-
| 忽略对偶理论 | 对偶问题可能更易解 | 构造对偶,利用强对偶性 |
|
|
109
|
-
| 混淆可行与最优 | 可行不一定最优 | 先验证可行性再验证最优性 |
|
|
110
|
-
| 忽略计算/GPU 复杂度 | 二阶法/组合优化可能不可算 | 评估复杂度,过 GPU 八维门,必要时近似 |
|
|
111
|
-
| 忘记重新优化 | 约束变了未更新 | 定期检查约束变化 |
|
|
112
|
-
|
|
113
|
-
## 操作规程 / Operating Procedure
|
|
114
|
-
|
|
115
|
-
当本 skill 被触发时,输出必须包含:
|
|
116
|
-
|
|
117
|
-
1. **目标函数**:`[目标]: [描述]` + `[凸性]: [凸/非凸/未知]`
|
|
118
|
-
2. **约束清单**:每条标 `[硬/软]` 与 `[不等式/等式]` `[线性/非线性]`
|
|
119
|
-
3. **类型分类**:`[类型]: [LP/QP/凸/非凸/组合/随机]`
|
|
120
|
-
4. **可行域分析**:哪些选项可行?活跃约束是哪些?
|
|
121
|
-
5. **最优解/满意解**:`[策略]: [梯度法/内点法/全局搜索/satisficing/帕累托]`
|
|
122
|
-
6. **灵敏度分析**:关键约束影子价格?变化 X% 结论如何变?
|
|
123
|
-
7. **GPU 可行性**(若用于算法/算子/训练):求解方法过八维门,标注友好/可改造/不友好 + 改造建议。
|
|
124
|
-
8. **行动建议**:明确写出"接下来我将……"
|
|
125
|
-
|
|
126
|
-
**输出不得只给分析而无结论。**
|
|
127
|
-
|
|
128
|
-
## 与其他 skill 的关系 / Relations to Other Skills
|
|
129
|
-
|
|
130
|
-
- **建模思想**:优化前需先建模——定义目标与约束本身就是建模。
|
|
131
|
-
- **概率与统计**:不确定性下的优化需随机/鲁棒优化。
|
|
132
|
-
- **变换思想**:变换到对偶问题常更易求解;对偶是优化中最深刻的变换。
|
|
133
|
-
- **博弈思想**:多决策者同时优化即博弈,纳什均衡为多人优化的稳定点。
|
|
134
|
-
- **算法思想**:求解依赖算法设计——凸优化用梯度法,组合优化需分支定界/启发式。
|
|
135
|
-
- **现代数学激活**:`../../references/books/optimization-ml.md`(GPU 友好优化器、二阶法可行性)、`matrix-analysis.md`(条件数、低秩、预条件)。
|