Mathematical Bridges: Representation, Probability, and Emergence
Representation, PCA, Encoders, Information as Curvature, Entropy, etc
Technology: Information Geometry, Representation Learning
Skill: Mathing
22 views2 likes
7 months ago · updated 7 months ago
David\ \ Campos](/content/david/index.html)
1. The Manifold of Representation
1.1 The Manifold Hypothesis
Real-world data do not fill the ambient space Rn\mathbb{R}^nRn uniformly.
They concentrate near a much lower-dimensional manifold M\mathcal{M}M of dimension d ≪ nd\!\ll\!nd≪n.
Formally, there exists a smooth embedding
ϕ:Rd→Rn,M={ϕ(z)∣z∈Rd}.\phi:\mathbb{R}^d \to \mathbb{R}^n,\qquad \mathcal{M} = \{\,\phi(z)\,|\,z\in\mathbb{R}^d\}.ϕ:Rd→Rn,M={ϕ(z)∣z∈Rd}.
Each point x∈Mx\in\mathcal{M}x∈M corresponds to a latent coordinate zzz in a hidden space of factors of variation (pose, lighting, semantics, etc.).
Learning, therefore, means discovering a chart ψ\psiψ such that
z=ψ(x),x≈ϕ(z).z = \psi(x),\qquad x \approx \phi(z).z=ψ(x),x≈ϕ(z).
In ML language:
| Mathematical map | ML analogue | Role |
|---|---|---|
| ψ\psiψ | Encoder | compresses input to latent coordinates |
| ϕ\phiϕ | Decoder | reconstructs or generates input |
| ϕ ∘ ψ\phi\!\circ\!\psiϕ∘ψ | Autoencoder | identity approximation on M\mathcal{M}M |
1.2 Local Linearity and the Jacobian
A differentiable map f:Rn → Rmf:\mathbb{R}^n\!\to\!\mathbb{R}^mf:Rn→Rm is locally linear:
f(x+Δx)≈f(x)+Jf(x)Δx,f(x+\Delta x)\;\approx\; f(x) + J_f(x)\,\Delta x,f(x+Δx)≈f(x)+Jf(x)Δx,
where
Jf(x)=∂f∂xJ_f(x)=\frac{\partial f}{\partial x}Jf(x)=∂x∂f
is the Jacobian matrix whose columns span the tangent space of the image manifold.
For an encoder EEE, the Jacobian JE(x)J_E(x)JE(x) tells us how input directions are stretched or compressed in latent space.
For a decoder DDD, JD(z)J_D(z)JD(z) controls how latent directions re-expand into data space.
If JEJ_EJE has rank ddd, the manifold has dimension ddd.
If its singular values vary widely, local curvature and distortion appear — some directions preserve information, others collapse.
1.3 Metric Induced by an Encoder
The Euclidean metric in input space induces a Riemannian metric in latent space:
g(z)=JE(x) ⊤JE(x)g(z) = J_E(x)^{\!\top} J_E(x)g(z)=JE(x)⊤JE(x)
This tensor tells us how infinitesimal distances change under the encoder:
∥E(x+Δx)−E(x)∥2=Δx ⊤g(z)Δx.\|E(x+\Delta x)-E(x)\|^2 \;=\; \Delta x^{\!\top} g(z)\,\Delta x.∥E(x+Δx)−E(x)∥2=Δx⊤g(z)Δx.
Flat regions of ggg correspond to invariant directions (the encoder ignores them);
high-curvature regions correspond to features the model deems important.
1.4 Dimensionality Reduction: from PCA to Autoencoders
Principal Component Analysis
PCA seeks an orthogonal projection W ∈ Rn×dW\!\in\!\mathbb{R}^{n\times d}W∈Rn×d minimizing reconstruction error:
minWE[∥x−WW ⊤x∥2].\min_W E[\|x - WW^{\!\top}x\|^2].WminE[∥x−WW⊤x∥2].
The solution uses the top ddd eigenvectors of the covariance matrix Σ=E[xx ⊤]\Sigma=E[x\,x^{\!\top}]Σ=E[xx⊤].
It is the linear autoencoder minimizing mean-squared error.
Nonlinear Autoencoders
Replace W ⊤W^{\!\top}W⊤ and WWW with nonlinear encoder–decoder networks (E,D)(E,D)(E,D):
L(E,D)=E[∥x−D(E(x))∥2].\mathcal{L}(E,D)=E[\|x-D(E(x))\|^2].L(E,D)=E[∥x−D(E(x))∥2].
Optimization learns curved charts that approximate the manifold M\mathcal{M}M beyond linear subspaces.
1.5 Spectral and Tangent-Space Intuition
The Jacobian’s singular values σi(x)\sigma_i(x)σi(x) measure local stretching.
The log determinant
log∣detJE(x)∣=∑ilogσi(x)\log|\det J_E(x)| = \sum_i \log\sigma_i(x)log∣detJE(x)∣=i∑logσi(x)
quantifies volume change — vital for normalizing-flow models and likelihood estimation.
- Small σi\sigma_iσi → collapsed directions → information loss.
- Large σi\sigma_iσi → sensitive directions → instability.
Good encoders balance contraction (compression) with invertibility (recoverability).
1.6 Curvature, Reconstruction, and Regularization
Define reconstruction energy
E(x)=∥x−D(E(x))∥2.E(x)=\|x-D(E(x))\|^2.E(x)=∥x−D(E(x))∥2.
Minimizing E(x)E(x)E(x) while constraining JEJ_EJE’s norm prevents degenerate mappings.
Regularizers like contractive autoencoders add
λ∥JE(x)∥F2\lambda\|J_E(x)\|_F^2λ∥JE(x)∥F2
to encourage smooth manifolds with low curvature — local invariance to small perturbations.
This has a geometric meaning: the encoder learns coordinates that vary slowly along high-density regions of the data manifold.
1.7 ML Mapping
| Geometric object | ML interpretation | Intuition |
|---|---|---|
| Manifold M\mathcal{M}M | data manifold | intrinsic degrees of freedom |
| Chart (ϕ,ψ)(\phi,\psi)(ϕ,ψ) | decoder/encoder | coordinate mapping |
| Tangent space TxMT_x\mathcal{M}TxM | local feature directions | infinitesimal variations |
| Metric g(z)g(z)g(z) | sensitivity matrix | how distances warp |
| Curvature | regularization target | encourages smooth generalization |
1.8 Why This Matters
In deep learning, every layer defines a map
h(l)=f(l)(h(l−1)),h^{(l)} = f^{(l)}(h^{(l-1)}),h(l)=f(l)(h(l−1)),
so the whole network composes Jacobians:
Jf(L) ∘⋯∘f(1)(x)=JLJL−1…J1.J_{f^{(L)}\!\circ\dots\circ f^{(1)}}(x) = J_L\,J_{L-1}\,\dots\,J_1.Jf(L)∘⋯∘f(1)(x)=JLJL−1…J1.
Understanding representations means understanding how these Jacobians reshape space layer by layer.
Gradients propagate through the same operators — hence, curvature of the representation manifold directly affects training dynamics and generalization.
1.9 Looking Ahead
The next section, Information as Curvature, will connect this geometry to information theory:
- entropy as volume,
- mutual information as overlap between manifolds,
- Fisher information as a metric tensor.
We will see how learning representations is equivalent to sculpting information geometry so that compression and recoverability balance perfectly.
A representation is good when it flattens the manifold just enough to compress,
but not so much that meaning collapses.
2. Information as Curvature
2.1 From Geometry to Information
In Section 1, we described how an encoder EEE reshapes local neighborhoods by its Jacobian JE(x)J_E(x)JE(x).
Now we turn to the statistical shape of data: how probability mass bends, spreads, and contracts.
Information theory provides an intrinsic coordinate system for probability distributions.
Where geometry studies curvature of space, information theory studies curvature of belief.
2.2 Entropy as Volume
For a discrete variable XXX with probability p(x)p(x)p(x),
H(X)=−∑xp(x)logp(x)H(X) = -\sum_x p(x)\log p(x)H(X)=−x∑p(x)logp(x)
measures the expected surprise of events.
In continuous form (differential entropy):
H(X)=−∫p(x)logp(x)dx.H(X) = -\int p(x)\log p(x)\,dx.H(X)=−∫p(x)logp(x)dx.
Entropy plays the role of volume in probability space.
Uniform distributions (flat densities) have large entropy → flat manifolds.
Highly concentrated densities have small entropy → sharp curvature.
ML mapping:
High-entropy layers (e.g., dropout or noisy embeddings) encourage exploration;
low-entropy posteriors (e.g., confident classifiers) reflect sharp decision boundaries.
2.3 Mutual Information — Overlap Between Manifolds
Given variables XXX and YYY with joint p(x,y)p(x,y)p(x,y), mutual information (MI) is
I(X;Y)=H(X)+H(Y)−H(X,Y)=∫p(x,y)logp(x,y)p(x)p(y)dxdy.I(X;Y) = H(X) + H(Y) - H(X,Y) = \int p(x,y)\log\frac{p(x,y)}{p(x)p(y)}\,dx\,dy.I(X;Y)=H(X)+H(Y)−H(X,Y)=∫p(x,y)logp(x)p(y)p(x,y)dxdy.
It quantifies how much knowing XXX reduces uncertainty about YYY.
Geometrically, think of the two manifolds of possible XXX and YYY values. Their overlap region—where p(x,y)p(x,y)p(x,y) concentrates—has curvature proportional to shared information.
ML mapping:
- In representation learning, I(X;Z)I(X;Z)I(X;Z) measures how much information the latent Z=E(X)Z=E(X)Z=E(X) retains about input.
- I(Z;Y)I(Z;Y)I(Z;Y) measures how predictive ZZZ is for the target.
Balancing them yields information bottleneck behavior.
2.4 The Information Bottleneck Principle
Goal: find an encoder EEE producing representation ZZZ that is maximally informative about YYY but minimally dependent on XXX.
Formally:
minp(z∣x)I(X;Z)−βI(Z;Y)\min_{p(z|x)} I(X;Z) - \beta\, I(Z;Y)p(z∣x)minI(X;Z)−βI(Z;Y)
The Lagrange multiplier β\betaβ controls compression vs. prediction.
Large β\betaβ → more predictive power; small β\betaβ → stronger compression.
This is equivalent to optimizing the free-energy-like objective
LIB=Ep(x,y,z)[−logp(y∣z)]+βDKL(p(z∣x)∥p(z)),\mathcal{L}_{IB} = E_{p(x,y,z)}[-\log p(y|z)] + \beta\, D_{KL}(p(z|x)\|p(z)),LIB=Ep(x,y,z)[−logp(y∣z)]+βDKL(p(z∣x)∥p(z)),
which reappears later as the Variational Autoencoder loss.
Intuition:
Information bottleneck geometry flattens directions irrelevant to YYY and preserves those aligned with predictive structure.
2.5 Kullback–Leibler Divergence as Geodesic Distance
The KL divergence between distributions ppp and qqq:
DKL(p∥q)=∫p(x)logp(x)q(x)dxD_{KL}(p\|q) = \int p(x)\log\frac{p(x)}{q(x)}\,dxDKL(p∥q)=∫p(x)logq(x)p(x)dx
is not symmetric but acts as a local metric on the manifold of probability densities.
For nearby q=p+dpq = p + dpq=p+dp:
DKL(p∥p+dp)≈12dp ⊤Gdp,D_{KL}(p\|p+dp) \approx \tfrac{1}{2}\, dp^{\!\top} G\, dp,DKL(p∥p+dp)≈21dp⊤Gdp,
where GGG is the Fisher Information Matrix.
Thus, Fisher information defines the curvature of the statistical manifold.
2.6 Fisher Information — The Metric of Belief Space
Given a parametric model p(x∣θ)p(x|\theta)p(x∣θ), the Fisher matrix is
Gij(θ)=Ep(x∣θ) [∂logp(x∣θ)∂θi∂logp(x∣θ)∂θj].G_{ij}(\theta) =
\mathbb{E}_{p(x|\theta)}
\!\left[
\frac{\partial \log p(x|\theta)}{\partial \theta_i}
\frac{\partial \log p(x|\theta)}{\partial \theta_j}
\right].Gij(θ)=Ep(x∣θ)[∂θi∂logp(x∣θ)∂θj∂logp(x∣θ)].
This tensor acts exactly like the metric ggg in Riemannian geometry: it measures how sensitive the distribution is to parameter changes.
- High GiiG_{ii}Gii → small parameter perturbations cause big likelihood shifts.
- Low GiiG_{ii}Gii → parameters in flat regions (uninformative).
Geometric interpretation:
Parameter space (Θ,G)(\Theta,G)(Θ,G) is a Riemannian manifold of models.
The Fisher metric measures curvature of log-likelihood.
ML mapping:
- Natural gradient descent uses G−1∇θLG^{-1}\nabla_\theta LG−1∇θL → steepest descent under this metric.
- Sharp minima → large Fisher curvature → potential overfitting.
2.7 Entropy, Curvature, and Flat Minima
Around a local minimum θ\*\theta^\*θ\* of loss L(θ)L(\theta)L(θ), approximate the posterior over parameters:
p(θ∣D)∝exp(−L(θ)).p(\theta|D) \propto \exp(-L(\theta)).p(θ∣D)∝exp(−L(θ)).
The entropy of this posterior depends on the determinant of the Hessian H=L′′(θ\*)H=L''(\theta^\*)H=L′′(θ\*):
H(θ\*) large⇒sharp minimum, low entropy;H(θ\*) small⇒flat minimum, high entropy.H(\theta^\*) \text{ large} \Rightarrow \text{sharp minimum, low entropy;}\
H(\theta^\*) \text{ small} \Rightarrow \text{flat minimum, high entropy.}H(θ\*) large⇒sharp minimum, low entropy;H(θ\*) small⇒flat minimum, high entropy.
Flatter minima correspond to wider, more stable basins → better generalization.
This links optimization curvature to information capacity.
2.8 Information Flow Through Layers
Each layer lll forms a Markov chain X→H1→H2→⋯→YX \to H_1 \to H_2 \to \dots \to YX→H1→H2→⋯→Y.
By the Data Processing Inequality:
I(X;H1)≥I(X;H2)≥⋯≥I(X;Y).I(X;H_1) \ge I(X;H_2) \ge \dots \ge I(X;Y).I(X;H1)≥I(X;H2)≥⋯≥I(X;Y).
Information can only decrease along deterministic layers.
Early layers preserve rich detail; deeper layers discard irrelevant variance, approaching a minimal sufficient statistic.
Practical manifestation:
- Early convolutional features carry high I(X;H)I(X;H)I(X;H) — textures, edges.
- Later layers carry low I(X;H)I(X;H)I(X;H) but high I(H;Y)I(H;Y)I(H;Y) — semantic abstraction.
2.9 Entropy and Temperature
In probabilistic and physical analogies, temperature TTT controls entropy:
p(x)∝e−E(x)/T.p(x) \propto e^{-E(x)/T}.p(x)∝e−E(x)/T.
Lower TTT → distribution concentrates (less entropy, sharper manifold).
Higher TTT → flatter landscape, more exploration.
This link between entropy and temperature is the bridge to energy-based models, where training sculpts energy surfaces to shape information geometry.
2.10 Summary of Section 2
| Concept | Mathematical Form | Geometric Meaning | ML Role |
|---|---|---|---|
| Entropy H(X)H(X)H(X) | −∫plogp-\int p\log p−∫plogp | volume of uncertainty | measure of spread |
| Mutual Information I(X;Y)I(X;Y)I(X;Y) | ∫plogppxpy\int p\log\frac{p}{p_xp_y}∫plogpxpyp | overlap of manifolds | relevance of representation |
| KL Divergence | ∫plogpq\int p\log\frac{p}{q}∫plogqp | directed geodesic distance | loss on distributions |
| Fisher Information | E[∂logp∂logp⊤]E[\partial\log p\,\partial\log p^\top]E[∂logp∂logp⊤] | curvature of belief space | metric for natural gradient |
| Flat minima | small Hessian ⇒\Rightarrow⇒ high entropy | smooth manifold | better generalization |
2.11 Bridge Forward
We now have the language to link energy and information:
entropy measures the volume of possible states,
energy measures their probability weight.
Next, we’ll see how deep models assign energy landscapes to data and how learning reshapes those landscapes to encode the world.
→ Section 3 – Energy-Based Models
3. Energy-Based Models — Learning by Shaping Probability Landscapes
3.1 The Energy View of Probability
Probability can be reinterpreted as geometry under an energy field.
Any normalized density can be written as
p(x)=1Ze−E(x),p(x) = \frac{1}{Z}\, e^{-E(x)},p(x)=Z1e−E(x),
where:
- E(x)E(x)E(x) = energy function — assigns “height” to each configuration.
- Z=∫e−E(x)dxZ = \int e^{-E(x)}dxZ=∫e−E(x)dx = partition function — normalizing volume.
Low energy ⇒ high probability.
Learning = sculpting the energy surface so real data points occupy low valleys.
ML mapping:
- In classification, logits define relative energies of labels.
- In diffusion and score-based models, energy gradients guide sampling.
- In contrastive models (e.g., CLIP, SimCLR), energies rank similarity between embeddings.
3.2 Gradients and Forces
Taking the gradient of the log-density gives:
∇xlogp(x)=−∇xE(x)−∇xlogZ=−∇xE(x).\nabla_x \log p(x) = -\nabla_x E(x) - \nabla_x \log Z = -\nabla_x E(x).∇xlogp(x)=−∇xE(x)−∇xlogZ=−∇xE(x).
since ZZZ is constant w.r.t xxx.
This score function ∇xlogp(x)\nabla_x \log p(x)∇xlogp(x) behaves like a physical force field that pushes samples toward high-probability regions.
Hence, sampling algorithms simulate dynamics on the energy landscape.
3.3 Boltzmann Machines — The Archetype
An energy-based model (EBM) defines energy over visible xxx and hidden hhh units:
E(x,h)=−x⊤Wh−b⊤x−c⊤h.E(x,h) = -x^\top W h - b^\top x - c^\top h.E(x,h)=−x⊤Wh−b⊤x−c⊤h.
The marginal probability is
p(x)=1Z∑he−E(x,h).p(x) = \frac{1}{Z}\sum_h e^{-E(x,h)}.p(x)=Z1h∑e−E(x,h).
Training minimizes negative log-likelihood:
∂logp(x)∂W=Ep(h∣x)[xh⊤]−Ep(x,h)[xh⊤].\frac{\partial \log p(x)}{\partial W} = E_{p(h|x)}[x h^\top] - E_{p(x,h)}[x h^\top].∂W∂logp(x)=Ep(h∣x)[xh⊤]−Ep(x,h)[xh⊤].
The first term pulls energy down at data points;
the second pushes it up elsewhere — contrastive divergence.
Intuition:
The network balances attraction to real data with repulsion from fake configurations, forming a potential surface shaped like data clusters.
3.4 Energy and Entropy — The Free Energy Principle
Free energy unites energy minimization and entropy maximization:
F=E−TH.F = E - T H.F=E−TH.
Minimizing FFF simultaneously lowers energy (fit the data) and raises entropy (avoid overconfidence).
In probabilistic models:
F[p]=Ep[E(x)]+T∫p(x)logp(x)dx.F[p] = \mathbb{E}_p[E(x)] + T \int p(x)\log p(x)dx.F[p]=Ep[E(x)]+T∫p(x)logp(x)dx.
At equilibrium, δF/δp=0\delta F/\delta p = 0δF/δp=0 yields the Boltzmann distribution again.
ML mapping:
VAEs and diffusion models both minimize variants of free energy — energy terms encourage accuracy, entropy terms encourage diversity.
3.5 Variational Autoencoders as Free-Energy Minimizers
A VAE defines latent prior p(z)p(z)p(z), decoder pθ(x∣z)p_\theta(x|z)pθ(x∣z), and encoder qϕ(z∣x)q_\phi(z|x)qϕ(z∣x).
The variational free energy is
LVAE=Eqϕ(z∣x)[−logpθ(x∣z)]+DKL(qϕ(z∣x)∥p(z)).\mathcal{L}_{VAE} = \mathbb{E}_{q_\phi(z|x)}[-\log p_\theta(x|z)] + D_{KL}(q_\phi(z|x)\|p(z)).LVAE=Eqϕ(z∣x)[−logpθ(x∣z)]+DKL(qϕ(z∣x)∥p(z)).
Interpretation:
- Reconstruction term → expected energy under pθp_\thetapθ.
- KL term → entropy–regularization penalty.
Minimizing L\mathcal{L}L pushes qϕ(z∣x)q_\phi(z|x)qϕ(z∣x) toward the prior, flattening unnecessary curvature while maintaining faithful reconstructions.
Geometric intuition:
Each data point induces a local energy basin in latent space; training shapes these basins to tile the data manifold smoothly.
3.6 Score-Based and Diffusion Models
These models learn the score function ∇xlogpt(x)\nabla_x \log p_t(x)∇xlogpt(x) of a noisy data distribution evolving over time ttt.
Diffusion forward process:
qt(xt∣x0)=N(αtx0,(1−αt)I),q_t(x_t|x_0) = \mathcal{N}(\sqrt{\alpha_t}x_0, (1-\alpha_t)I),qt(xt∣x0)=N(αtx0,(1−αt)I),
adds Gaussian noise; the model learns to reverse it via score estimation.
The score network sθ(xt,t)s_\theta(x_t,t)sθ(xt,t) predicts ∇xtlogqt(xt)\nabla_{x_t}\log q_t(x_t)∇xtlogqt(xt).
Training objective (denoising score matching):
LDSM=Et,x0,ϵ [∥sθ(αtx0+σtϵ,t)−−ϵσt∥2].\mathcal{L}_{DSM} =
E_{t,x_0,\epsilon}
\!\left[
\|s_\theta(\sqrt{\alpha_t}x_0+\sigma_t\epsilon,t)
- \frac{-\epsilon}{\sigma_t}\|^2
\right].LDSM=Et,x0,ϵ[∥sθ(αtx0+σtϵ,t)−σt−ϵ∥2].
This teaches the network the geometry of the data manifold under progressive noise —
a direct, continuous analogue of energy minimization.
Sampling:
Run the reverse SDE
dx=[drift−12σ2sθ(x,t)]dt+σdWt,dx = [\text{drift} - \tfrac{1}{2}\sigma^2 s_\theta(x,t)]dt + \sigma dW_t,dx=[drift−21σ2sθ(x,t)]dt+σdWt,
which traces back down the learned energy gradients — denoising as manifold restoration.
3.7 Contrastive and Self-Supervised EBMs
Modern contrastive objectives (e.g., SimCLR, CLIP) define energies
E(x,y)=−fθ(x)⊤gθ(y),E(x,y) = - f_\theta(x)^\top g_\theta(y),E(x,y)=−fθ(x)⊤gθ(y),
and train via InfoNCE loss:
L=−E(x,y) [loge−E(x,y)∑y′e−E(x,y′)].\mathcal{L}
= -E_{(x,y)}
\!\left[
\log\frac{e^{-E(x,y)}}
{\sum_{y'} e^{-E(x,y')}}
\right].L=−E(x,y)[log∑y′e−E(x,y′)e−E(x,y)].
This approximates maximizing mutual information between paired views (x,y)(x,y)(x,y). The denominator implements a soft partition function; minimizing L\mathcal{L}L deepens correct wells while raising incorrect ones.
Interpretation:
Each embedding pair carves a potential well; learning adjusts the landscape so semantically aligned examples fall into the same valley.
3.8 Gradients, Forces, and Learning Dynamics
The energy gradient defines both physical forces and optimization directions:
dxdt=−∇xE(x).\frac{dx}{dt} = -\nabla_x E(x).dtdx=−∇xE(x).
Gradient descent on E(x)E(x)E(x) literally simulates physical relaxation toward equilibrium.
This unifies:
- optimization (descent in parameter space),
- sampling (descent in data space with noise),
- inference (descent in latent space).
All learning algorithms are energy flows under different coordinate systems.
3.9 ML Mapping
| Concept | Mathematical Form | Geometric Role | Example in ML |
|---|---|---|---|
| Energy | E(x)E(x)E(x) | scalar potential | logits, reconstruction loss |
| Partition function | Z=∫e−EZ=\int e^{-E}Z=∫e−E | normalization volume | log-sum-exp |
| Free energy | F=E−THF = E - T HF=E−TH | trade-off surface | VAE loss |
| Score | ∇xlogp(x)\nabla_x\log p(x)∇xlogp(x) | force field | diffusion models |
| Contrastive energy | −f(x)⊤g(y)-f(x)^\top g(y)−f(x)⊤g(y) | relational potential | CLIP, SimCLR |
3.10 Bridge Forward
So far we’ve established that representation = manifold,
information = curvature, and learning = energy flow.
The next layer of this synthesis explores optimization—how gradients traverse these curved energy surfaces,
and how algorithms like SGD, Adam, and RMSProp emerge as physical laws of motion in parameter space.
→ Section 4 – Optimization as Dynamics
4. Optimization as Dynamics
4.1 The Geometry of Descent
Training a model is not just algebra — it is dynamics on a curved manifold of parameters.
Every parameter update defines motion:
dθdt=−∇θL(θ),\frac{d\theta}{dt} = -\nabla_\theta L(\theta),dtdθ=−∇θL(θ),
where L(θ)L(\theta)L(θ) is the energy or loss function.
This is gradient flow — the continuous-time limit of gradient descent.
If we visualize L(θ)L(\theta)L(θ) as a potential surface, optimization corresponds to a particle rolling downhill under the force field −∇L-\nabla L−∇L.
- Valleys = minima (stable equilibria).
- Saddles = unstable points where descent can stall.
- Basins’ shape defines generalization behavior.
4.2 Discrete Gradient Descent
Discretizing gradient flow with step size η\etaη gives:
θt+1=θt−η∇θL(θt).\theta_{t+1} = \theta_t - \eta\, \nabla_\theta L(\theta_t).θt+1=θt−η∇θL(θt).
The step size η\etaη acts as a time constant controlling how far we move per update.
Too large → oscillations or divergence.
Too small → slow convergence.
4.3 Momentum and Inertia
Momentum introduces a velocity variable vtv_tvt:
vt+1=βvt+(1−β)∇θL(θt),θt+1=θt−ηvt+1.v_{t+1} = \beta v_t + (1-\beta)\nabla_\theta L(\theta_t), \qquad \theta_{t+1} = \theta_t - \eta v_{t+1}.vt+1=βvt+(1−β)∇θL(θt),θt+1=θt−ηvt+1.
This is a discrete form of physical momentum:
mθ¨+γθ˙=−∇θL(θ).m\ddot{\theta} + \gamma \dot{\theta} = -\nabla_\theta L(\theta).mθ¨+γθ˙=−∇θL(θ).
It smooths out noisy or conflicting gradient directions and allows the optimizer to carry inertia across flat regions.
Geometric intuition:
Momentum integrates over the manifold’s curvature, effectively following geodesics rather than raw gradients.
4.4 Adaptive Preconditioning — RMSProp, Adam
Gradients can vary wildly across coordinates.
Adaptive methods rescale them using estimates of second-order moments.
Let gt=∇θL(θt)g_t = \nabla_\theta L(\theta_t)gt=∇θL(θt).
RMSProp:
st=ρst−1+(1−ρ)gt2,θt+1=θt−ηgtst+ϵ.s_t = \rho s_{t-1} + (1-\rho) g_t^2, \quad \theta_{t+1} = \theta_t - \eta \frac{g_t}{\sqrt{s_t+\epsilon}}.st=ρst−1+(1−ρ)gt2,θt+1=θt−ηst+ϵgt.
Adam:
mt=β1mt−1+(1−β1)gt,vt=β2vt−1+(1−β2)gt2,m^t=mt1−β1t,v^t=vt1−β2t,θt+1=θt−ηm^tv^t+ϵ.m_t = \beta_1 m_{t-1} + (1-\beta_1) g_t, \
v_t = \beta_2 v_{t-1} + (1-\beta_2) g_t^2, \
\hat{m}_t = \frac{m_t}{1-\beta_1^t}, \quad
\hat{v}_t = \frac{v_t}{1-\beta_2^t}, \
\theta_{t+1} = \theta_t - \eta \frac{\hat{m}_t}{\sqrt{\hat{v}_t}+\epsilon}.mt=β1mt−1+(1−β1)gt,vt=β2vt−1+(1−β2)gt2,m^t=1−β1tmt,v^t=1−β2tvt,θt+1=θt−ηv^t+ϵm^t.
These schemes effectively approximate natural gradient descent using diagonal curvature estimates.
Intuition:
Each parameter moves in proportion to its signal-to-noise ratio — large gradients with high variance are damped; consistent ones accelerate.
4.5 Second-Order Geometry — Newton’s Method
If the loss is locally quadratic:
L(θ+Δθ)≈L(θ)+∇L ⊤Δθ+12Δθ ⊤HΔθ,L(\theta+\Delta\theta) \approx L(\theta) + \nabla L^{\!\top}\Delta\theta + \tfrac{1}{2}\Delta\theta^{\!\top} H \Delta\theta,L(θ+Δθ)≈L(θ)+∇L⊤Δθ+21Δθ⊤HΔθ,
then minimizing this approximation yields the Newton step:
Δθ=−H−1∇L.\Delta\theta = -H^{-1}\nabla L.Δθ=−H−1∇L.
Here H=∇2LH = \nabla^2 LH=∇2L is the Hessian, describing local curvature.
In continuous form, this corresponds to preconditioning gradient flow by the metric tensor HHH — i.e. moving isotropically in curved space.
Drawback: computing and inverting HHH is expensive (O(n3)O(n^3)O(n3)).
Hence practical methods (L-BFGS, K-FAC) approximate its structure.
4.6 The Natural Gradient
Amari (1998) showed that the steepest descent direction on a statistical manifold under the Fisher metric GGG is
θ˙=−G−1∇θL.\dot{\theta} = - G^{-1}\nabla_\theta L.θ˙=−G−1∇θL.
This is the natural gradient — it accounts for information geometry, ensuring updates respect the model’s intrinsic curvature.
For a neural network parameterizing p(x∣θ)p(x|\theta)p(x∣θ),
GGG measures how output distributions change with θ\thetaθ.
Intuition:
Ordinary gradient descent measures distance in parameter space;
natural gradient measures distance in distribution space.
4.7 Stochastic Gradient Descent — Noise as Regularization
In practice, we approximate ∇θL\nabla_\theta L∇θL with mini-batch estimates g\tilde{g}g:
θt+1=θt−ηgt,\theta_{t+1} = \theta_t - \eta \tilde{g}_t,θt+1=θt−ηgt,
which introduces noise ξt=gt−E[gt]\xi_t = \tilde{g}_t - \mathbb{E}[\tilde{g}_t]ξt=gt−E[gt].
This stochasticity acts like a temperature term in Langevin dynamics:
dθ=−∇Ldt+2TdWt.d\theta = -\nabla L\,dt + \sqrt{2T}\,dW_t.dθ=−∇Ldt+2TdWt.
The stationary distribution:
p(θ)∝e−L(θ)/T.p(\theta) \propto e^{-L(\theta)/T}.p(θ)∝e−L(θ)/T.
Thus SGD explores low-energy basins instead of converging to the first minimum.
- High TTT (large batches, high noise) → exploration.
- Low TTT → exploitation.
Flat minima correspond to broad valleys that trap more stochastic trajectories — explaining why SGD often generalizes better than deterministic descent.
4.8 Learning Rate as Temperature
The step size η\etaη and batch size jointly control effective temperature:
Teff∝ηB.T_{\text{eff}} \propto \frac{\eta}{B}.Teff∝Bη.
Smaller batches or higher learning rates add more diffusion.
Modern optimizers carefully tune this balance to maintain stable yet exploratory dynamics.
4.9 Optimization and Curvature — A Unified Picture
| Concept | Mathematical Form | Physical Analogy | ML Intuition |
|---|---|---|---|
| Gradient descent | θ˙=−∇L\dot{\theta}=-\nabla Lθ˙=−∇L | overdamped flow | pure relaxation |
| Momentum | mθ¨+γθ˙=−∇Lm\ddot{\theta}+\gamma\dot{\theta}=-\nabla Lmθ¨+γθ˙=−∇L | inertia | accelerates through flat regions |
| Adam / RMSProp | −∇L/var-\nabla L / \sqrt{\text{var}}−∇L/var | adaptive friction | balances coordinates |
| Newton / Natural | −H−1∇L-H^{-1}\nabla L−H−1∇L, −G−1∇L-G^{-1}\nabla L−G−1∇L | motion in curved metric | curvature-aware |
| SGD noise | +2TdWt+\sqrt{2T}dW_t+2TdWt | thermal diffusion | regularization, exploration |
All optimizers are variants of gradient flow with friction and noise on a manifold with metric tensor MMM:
Mθ˙=−∇L+noise.M\dot{\theta} = -\nabla L + \text{noise}.Mθ˙=−∇L+noise.
Choosing MMM defines an optimizer;
choosing noise level defines generalization.
4.10 The Energy–Learning Duality
Optimization and inference are two sides of the same equation:
| Inference | Optimization |
|---|---|
| Seeks most probable xxx under p(x)∝e−E(x)p(x)\propto e^{-E(x)}p(x)∝e−E(x) | Seeks minimum of L(θ)L(\theta)L(θ) |
| Gradient of log-likelihood: ∇xlogp(x)=−∇xE(x)\nabla_x \log p(x)=-\nabla_x E(x)∇xlogp(x)=−∇xE(x) | Gradient of loss: −∇θL(θ)-\nabla_\theta L(\theta)−∇θL(θ) |
| Langevin dynamics samples from posterior | SGD samples from flat minima |
In both, trajectories follow forces derived from energy gradients.
4.11 ML Mapping — Optimizers as Physical Systems
| Optimizer | Differential equation form | Physical analogy | Key behavior |
|---|---|---|---|
| Gradient descent | θ˙=−∇L\dot{\theta}=-\nabla Lθ˙=−∇L | viscous drag | converges slowly |
| Momentum | θ¨+γθ˙=−∇L\ddot{\theta}+\gamma\dot{\theta}=-\nabla Lθ¨+γθ˙=−∇L | mass-spring | smooths oscillations |
| Adam | θ˙=−ηM−1∇L\dot{\theta}=-\eta M^{-1}\nabla Lθ˙=−ηM−1∇L | anisotropic friction | adaptive step sizes |
| SGD | θ˙=−∇L+2Tξ\dot{\theta}=-\nabla L+\sqrt{2T}\xiθ˙=−∇L+2Tξ | Brownian particle | exploration |
| Natural gradient | θ˙=−G−1∇L\dot{\theta}=-G^{-1}\nabla Lθ˙=−G−1∇L | curved manifold flow | information-efficient |
4.12 Closing the Loop
Optimization reveals the dynamics of learning:
how representations evolve under forces derived from loss geometry.
- Gradients = forces
- Curvature = resistance
- Noise = temperature
- Momentum = inertia
- Metrics = manifold shape
When we train a neural network, we are not merely adjusting numbers —
we are running a thermodynamic process where energy, entropy, and curvature balance to encode structure.
Learning is the slow crystallization of information under pressure from data.
4.13 Bridge Forward
Next we complete the circle: connecting optimization dynamics to emergent intelligence — how local gradient laws yield global structure, attention, and reasoning in modern architectures.
→ Section 5 – Emergence and Attention
5. Emergence and Attention
5.1 From Gradient Flow to Information Flow
Optimization describes how parameters evolve.
But at inference time, information flows through the network in exactly the same way gradients flowed during training:
x→Ez→transformationsx^.x \;\xrightarrow{E}\; z \;\xrightarrow{\text{transformations}}\; \hat{x}.xEztransformationsx^.
Each layer transports representations across the manifold it has learned.
The velocity field of this flow is given by the Jacobian Jf(x)J_f(x)Jf(x),
and when layers are stacked deeply enough, this flow begins to show emergent structure:
tokens attend, features specialize, context self-organizes.
5.2 Why Attention Arises at All
In any sequence model, we need to determine which parts of the input affect which others.
Recurrent nets (RNNs) did this through temporal recurrence:
ht=f(Whht−1+Wxxt).h_t = f(W_h h_{t-1} + W_x x_t).ht=f(Whht−1+Wxxt).
Information decays exponentially with distance → vanishing gradients.
The attention mechanism replaces recurrence with direct pairwise coupling between all positions:
influence(i → j)=similarity(xi,xj).\text{influence}(i \!\to\! j) = \text{similarity}(x_i, x_j).influence(i→j)=similarity(xi,xj).
Thus attention is an adaptive kernel over the manifold of tokens,
dynamically estimating curvature — which neighbors matter most for a given point.
5.3 Mathematical Formulation of Self-Attention
Given a matrix of token embeddings X ∈ Rn×dX\!\in\!\mathbb{R}^{n\times d}X∈Rn×d:
Q=XWQ,K=XWK,V=XWV,Q = XW_Q,\quad K = XW_K,\quad V = XW_V,Q=XWQ,K=XWK,V=XWV,
where
- QQQ = queries,
- KKK = keys,
- VVV = values.
The attention output is
Attn(X)=softmax (QK ⊤dk)V.\text{Attn}(X) = \text{softmax}\!\left(\frac{QK^{\!\top}}{\sqrt{d_k}}\right)V.Attn(X)=softmax(dkQK⊤)V.
Each token produces a query that compares itself (dot product) against all keys,
yielding normalized weights that sum to 1.
Those weights average the corresponding values.
Interpretation:
Attention computes a data-dependent kernel smoother:
yi=∑jαijVj,αij=exp(Qi ⋅ Kj/dk)∑kexp(Qi ⋅ Kk/dk).y_i = \sum_j \alpha_{ij} V_j,\quad \alpha_{ij} = \frac{\exp(Q_i\!\cdot\!K_j/\sqrt{d_k})} {\sum_{k}\exp(Q_i\!\cdot\!K_k/\sqrt{d_k})}.yi=j∑αijVj,αij=∑kexp(Qi⋅Kk/dk)exp(Qi⋅Kj/dk).
So each output token lives at the center of mass of its contextual neighborhood
under a learned similarity metric.
5.4 Geometric View
Let each token embedding be a point on manifold M ⊂ Rd\mathcal{M}\!\subset\!\mathbb{R}^dM⊂Rd.
The dot-product similarity defines an affinity matrix A(Q,K)A(Q,K)A(Q,K) whose entries approximate
the exponential of negative squared distance:
Aij∝e−∥qi−kj∥2/2.A_{ij}\propto e^{-\|q_i - k_j\|^2/2}.Aij∝e−∥qi−kj∥2/2.
The softmax normalization ensures each row of AAA lies on the probability simplex —
a discrete geodesic neighborhood for point iii.
Thus self-attention performs parallel transport of features along the manifold’s tangent graph.
Multi-head attention performs this under multiple learned metrics {WQ(h),WK(h)}\{W_Q^{(h)},W_K^{(h)}\}{WQ(h),WK(h)},
capturing different curvature directions (syntax, semantics, position, etc.).
5.5 Energy and Attention
From an energy standpoint, each pair (i,j)(i,j)(i,j) defines interaction energy
Eij=−qi ⊤kj/dk.E_{ij} = - q_i^{\!\top} k_j / \sqrt{d_k}.Eij=−qi⊤kj/dk.
The softmax implements a Boltzmann distribution over these energies:
αij=e−Eij∑ke−Eik.\alpha_{ij} = \frac{e^{-E_{ij}}}{\sum_k e^{-E_{ik}}}.αij=∑ke−Eike−Eij.
Low energy ⇒ strong attention weight.
Training shapes EijE_{ij}Eij so that meaningful token pairs occupy low-energy valleys —
just as earlier sections described energy shaping in representation learning.
5.6 Normalization and Residuals as Manifold Stabilizers
Layer Normalization rescales activations to unit variance per token:
LN(x)=x−μσ⊙γ+β.\text{LN}(x) = \frac{x - \mu}{\sigma}\odot \gamma + \beta.LN(x)=σx−μ⊙γ+β.
Geometrically, this re-centers the coordinate chart on each patch of the manifold,
keeping curvature stable and preventing runaway energy magnitudes.
Residual connections
y=x+f(x)y = x + f(x)y=x+f(x)
approximate an Euler step of continuous dynamics
x˙=f(x)\dot{x}=f(x)x˙=f(x) — they discretize neural ODE flow.
Together, normalization + residuals keep the manifold well-conditioned during deep composition,
allowing thousands of layers to behave as a smooth vector field rather than an exploding fractal.
5.7 Multi-Head Mechanism = Factorized Curvature
Each attention head hhh learns its own metric tensor g(h)=WQ(h)⊤WK(h)g^{(h)} = W_Q^{(h)\top}W_K^{(h)}g(h)=WQ(h)⊤WK(h).
Combining heads aggregates multiple curvature views:
Y=Concat(H1,…,HH)WO,Hh=softmax (QhKh ⊤dk)Vh.Y = \text{Concat}(H_1,\dots,H_H)W_O, \qquad H_h = \text{softmax}\!\left(\frac{Q_hK_h^{\!\top}}{\sqrt{d_k}}\right)V_h.Y=Concat(H1,…,HH)WO,Hh=softmax(dkQhKh⊤)Vh.
Conceptually, the network builds a low-rank approximation to global curvature —
a collection of learned local coordinate frames that together cover the space of relations.
5.8 Optimization and Emergent Structure
Attention layers are optimized via the same gradient flow we studied earlier.
But because attention weights themselves depend on inner products of representations,
gradients propagate through relational geometry — not fixed topology.
Consequences:
- Token clustering: optimization sharpens affinity basins → self-organization of topics.
- Compositionality: residual stacking composes linear maps → emergent syntax trees.
- Long-range dependency: self-attention’s fully connected graph eliminates diffusion limits of recurrence.
- Emergent memory: certain heads stabilize attention patterns that act as long-term slots.
5.9 Attention as Information Routing
Define entropy of an attention row:
Hi=−∑jαijlogαij.H_i = -\sum_j \alpha_{ij}\log\alpha_{ij}.Hi=−j∑αijlogαij.
- High HiH_iHi → broad, diffuse attention → exploration.
- Low HiH_iHi → sharp focus → information bottleneck.
During training, layers naturally organize into an entropy cascade:
early heads maintain high entropy (collect global context),
later heads focus (collapse uncertainty).
This mirrors the information bottleneck principle from Section 2.
5.10 Causal and Masked Attention
For autoregressive models (GPT-style), we enforce a triangular mask Mij=0M_{ij}=0Mij=0 for j>ij>ij>i.
The softmax then operates only on accessible past tokens:
αij=exp(qi ⋅ kj/dk)∑k≤iexp(qi ⋅ kk/dk).\alpha_{ij} = \frac{\exp(q_i\!\cdot\!k_j/\sqrt{d_k})} {\sum_{k\le i}\exp(q_i\!\cdot\!k_k/\sqrt{d_k})}.αij=∑k≤iexp(qi⋅kk/dk)exp(qi⋅kj/dk).
This constraint converts the global attention kernel into a directed acyclic graph,
allowing sequential generation while retaining parallel computation.
Causality is thus built into the topology of the energy manifold.
5.11 From Attention to Transformer Dynamics
Each Transformer block can be viewed as a time-discretized dynamical system:
ht+1=ht+fattn(ht)+fmlp(ht),h_{t+1} = h_t + f_{\text{attn}}(h_t) + f_{\text{mlp}}(h_t),ht+1=ht+fattn(ht)+fmlp(ht),
with layer norm maintaining local stability.
Stacking LLL blocks integrates this ODE over LLL steps,
gradually diffusing and refining information.
Hence, the “depth” of a Transformer is integration time.
Attention supplies the vector field; residuals integrate it;
normalization stabilizes curvature.
5.12 Emergent Phenomena in Large Models
As parameter count NNN and data scale DDD increase,
optimization dynamics transition from under-parameterized (noisy) to mean-field regime.
Here, individual weights behave like particles in a potential field,
and collective behavior obeys smooth PDEs —
yielding emergent properties:
- Sparse specialization: heads partition tasks automatically.
- Linear probes: representations align with latent factors.
- In-context learning: the network simulates gradient descent internally.
- Compositional reasoning: low-energy manifolds overlap, forming reusable subspaces.
These are not hard-coded — they arise from the geometry of gradient flow itself.
5.13 Mathematical Summary of Self-Attention
| Symbol | Meaning | Geometric / Information Role |
|---|---|---|
| Q,K,VQ,K,VQ,K,V | projections of inputs | define local coordinate frames |
| QK ⊤/dkQK^{\!\top}/\sqrt{d_k}QK⊤/dk | similarity matrix | energy landscape between tokens |
| softmax | normalization | Boltzmann distribution over neighbors |
| αij\alpha_{ij}αij | attention weights | probability mass transport |
| VVV aggregation | weighted average | parallel transport of features |
| multi-head concat | multiple metrics | factorized curvature basis |
| residual + LN | stabilization | maintain manifold consistency |
5.14 Bridge Forward
Attention is geometry made discrete:
it lets every token see every other through a dynamically learned metric.
Optimization sculpts that metric until information flow mirrors meaning.
Next we’ll climb the final ridge — how this machinery produces emergence:
reasoning, abstraction, and modular world-models.
→ Section 6 – Emergence and Abstraction
6. Emergence and Abstraction
6.1 From Mechanics to Meaning
Up to now, we have treated neural networks as dynamical systems.
They propagate vectors, minimize energy, and reshape manifolds.
Yet at scale, something new appears — semantics.
When optimization equilibria stabilize across billions of examples,
the network’s internal geometry begins to encode concepts rather than raw patterns.
Abstraction is the low-dimensional order parameter of these high-dimensional dynamics.
Formally, if representations h(x)h(x)h(x) cluster by meaning rather than appearance,
then there exists a projection WWW such that:
Wh(xi)≈Wh(xj)iffsem(xi)=sem(xj).W h(x_i) \approx W h(x_j) \quad \text{iff} \quad \text{sem}(x_i)=\text{sem}(x_j).Wh(xi)≈Wh(xj)iffsem(xi)=sem(xj).
This defines a semantic manifold: the quotient space of perception under invariance.
6.2 Scaling Laws and the Phase Transition of Learning
Empirically, models exhibit emergent abilities when capacity and data scale cross critical thresholds.
Loss vs. model size often follows a power law:
L(N)∝N−α,L(N) \propto N^{-\alpha},L(N)∝N−α,
until an inflection where new qualitative behaviors emerge (e.g., in-context reasoning, translation).
Interpretation:
Optimization explores the manifold of functions.
At small scale, parameters live in separate basins (local memorization).
Beyond the critical dimension, basins connect → a single smooth manifold of solutions.
Abstraction arises as a phase transition in the topology of representation space.
6.3 Information Geometry of Abstraction
Consider mutual information between input XXX, latent ZZZ, and target YYY.
I(X;Z)≥I(Z;Y).I(X;Z)\ge I(Z;Y).I(X;Z)≥I(Z;Y).
Early layers preserve much of I(X;Z)I(X;Z)I(X;Z); deeper layers compress it, preserving only predictive information.
At convergence, ZZZ becomes a minimal sufficient statistic of XXX for YYY:
p(Y∣Z)=p(Y∣X),I(X;Z) minimal.p(Y|Z) = p(Y|X), \quad I(X;Z)\text{ minimal.}p(Y∣Z)=p(Y∣X),I(X;Z) minimal.
This collapse onto a lower-dimensional manifold is abstraction:
discarding microscopic details while retaining causal essence.
6.4 Linear Subspaces and Concept Vectors
In large networks, neurons align along approximately linear directions that correlate with interpretable features.
Let h(x)∈Rdh(x)\in\mathbb{R}^dh(x)∈Rd be a hidden representation, and let vcv_cvc be the average embedding for concept ccc.
Then for input xxx exhibiting that concept:
h(x)⋅vc≈activation strength.h(x)\cdot v_c \approx \text{activation strength}.h(x)⋅vc≈activation strength.
Concepts become directions in representation space.
This explains linear probes:
a linear classifier can separate abstract features because the manifold flattens along those dimensions.
6.5 Emergent Linearity and Superposition
Suppose tokens correspond to latent basis functions ϕi\phi_iϕi.
Training learns weights wiw_iwi such that:
h(x)=∑iaiϕi.h(x) = \sum_i a_i \phi_i.h(x)=i∑aiϕi.
At small scale, ϕi\phi_iϕi are entangled (distributed code).
At large scale, optimization orthogonalizes them → superposition becomes sparse.
Each dimension specializes, minimizing cross-talk energy:
E=∑i≠j(ϕi⋅ϕj)2.E = \sum_{i\ne j} (\phi_i\cdot\phi_j)^2.E=i=j∑(ϕi⋅ϕj)2.
Gradient descent on EEE implicitly performs an eigen-decomposition of correlation structure,
leading to emergent factorization of knowledge.
6.6 Attention as Emergent Graph Topology
From Section 5, recall attention weights αij\alpha_{ij}αij form an adjacency matrix of a dynamic graph.
As training progresses, this graph self-organizes:
- Clusters of tokens form communities = local topics.
- Inter-cluster edges encode hierarchical relations.
- Certain heads stabilize recurrent motifs → circuits.
Thus, Transformers learn structured connectivity internally —
a neural syntax graph evolving out of flat pairwise interactions.
Mathematical view:
Let A\mathbf{A}A be the average attention matrix.
Spectral clustering on A\mathbf{A}A yields eigenvectors corresponding to global latent topics.
Their Laplacian eigenvalues measure connectivity curvature — low values → smooth, coherent abstraction.
6.7 Emergent Memory and Recurrence Without Recurrence
Although Transformers lack explicit recurrence,
attention plus residual accumulation form an implicit memory:
ht=ht−1+fattn(ht−1).h_t = h_{t-1} + f_{\text{attn}}(h_{t-1}).ht=ht−1+fattn(ht−1).
Unrolled across layers, this recurrence builds trajectories of state through token-space.
Heads that consistently reference past positions act as temporal integrators.
In linearized form, this recursion resembles a discrete neural ODE:
dhdl=f(h,l),\frac{dh}{dl} = f(h,l),dldh=f(h,l),
where layer index lll plays the role of time.
Hence, depth substitutes for recurrence — memory emerges as integrated attention flow.
6.8 Emergent Modularity
Networks at scale begin to specialize:
different subsets of neurons or heads handle distinct sub-problems.
Formally, the parameter space partitions into weakly coupled submanifolds {Mk}\{\mathcal{M}_k\}{Mk} minimizing cross-curvature:
∥∇Mi∇MjL∥≈0,i≠j.\|\nabla_{\mathcal{M}_i}\nabla_{\mathcal{M}_j} L\|\approx 0, \quad i\ne j.∥∇Mi∇MjL∥≈0,i=j.
This modularization increases optimization efficiency and interpretability.
It mirrors how natural systems evolve modular designs to manage complexity.
Information-theoretic interpretation:
Each module forms a cluster maximizing internal mutual information I(Hi;Yi)I(H_i;Y_i)I(Hi;Yi)
while minimizing I(Hi;Hj)I(H_i;H_j)I(Hi;Hj) across modules —
the information bottleneck principle applied hierarchically.
6.9 Compositionality and Function Composition
Emergent reasoning stems from compositional reuse of modules.
If representations h1,h2h_1,h_2h1,h2 correspond to subfunctions f1,f2f_1,f_2f1,f2,
then the network can approximate compositions:
f(h1,h2)≈f2∘f1.f(h_1,h_2)\approx f_2\circ f_1.f(h1,h2)≈f2∘f1.
Optimization discovers local minima where composition error
∥f2(f1(x))−f12(x)∥\|f_2(f_1(x))-f_{12}(x)\|∥f2(f1(x))−f12(x)∥
is small across examples.
Such aligned minima accumulate in large models,
allowing learned operators to chain semantically.
6.10 In-Context Learning as Internal Gradient Descent
When a model processes a sequence of examples and adapts predictions mid-stream,
it effectively performs gradient descent in its hidden activations.
Let the hidden state after ttt examples be hth_tht.
For small updates Δht\Delta h_tΔht proportional to loss gradient in activation space:
Δht∝−∇htℓt.\Delta h_t \propto -\nabla_{h_t} \ell_t.Δht∝−∇htℓt.
Attention and residual dynamics implement this implicit optimization.
Thus the Transformer simulates learning within inference —
an emergent meta-learning process derived from its architecture and training statistics.
6.11 Scaling, Curvature, and Emergent Flatness
As networks scale, their parameter manifolds become smoother;
loss curvature (Hessian eigenvalues) concentrates around zero.
Empirically:
ρ(λ)∝λ−β(λ>0),\rho(\lambda) \propto \lambda^{-\beta} \quad (\lambda>0),ρ(λ)∝λ−β(λ>0),
where ρ\rhoρ is eigenvalue density.
This flattening permits high-dimensional manifolds of nearly equal loss → flexible reasoning behavior.
The system becomes a statistical fluid rather than a rigid function —
able to interpolate and extrapolate without overfitting.
6.12 Abstraction as Information Compression
All emergence reduces to selective compression.
Abstraction minimizes description length:
Lcode(X∣Z)=H(X∣Z),L_{\text{code}}(X|Z)=H(X|Z),Lcode(X∣Z)=H(X∣Z),
subject to maintaining predictive power I(Z;Y)I(Z;Y)I(Z;Y).
When compression saturates the bottleneck while retaining mutual information,
representations correspond to causal factors — the true generative variables of the environment.
This explains why large models learn usable world models without explicit supervision:
information geometry alone forces the discovery of invariant latent axes.
6.13 Mathematical Summary
| Concept | Mathematical Signature | Emergent Property | Interpretation |
|---|---|---|---|
| Critical scaling | L(N) ∝ N−αL(N)\!\propto\!N^{-\alpha}L(N)∝N−α | phase transition | new abilities appear |
| Information bottleneck | minI(X;Z) − βI(Z;Y)\min I(X;Z)\!-\!\beta I(Z;Y)minI(X;Z)−βI(Z;Y) | abstraction | compression of noncausal info |
| Concept vectors | $v_c=\mathbb{E}[h(x) | c]$ | linear semantics |
| Modularity | ∇Mi∇MjL≈0\nabla_{\mathcal{M}_i}\nabla_{\mathcal{M}_j}L\approx0∇Mi∇MjL≈0 | specialization | decoupled subspaces |
| In-context learning | Δht∝−∇htℓt\Delta h_t\propto-\nabla_{h_t}\ell_tΔht∝−∇htℓt | meta-learning | learning during inference |
| Flat curvature | ρ(λ) ∝ λ−β\rho(\lambda)\!\propto\!\lambda^{-\beta}ρ(λ)∝λ−β | flexibility | smooth reasoning manifold |
6.14 Intuitive Summary
- Abstraction = compression of irrelevant details.
- Concepts = directions in representation space.
- Reasoning = composition of modular operators.
- Memory = integrated attention flow.
- Emergence = topological phase change in the geometry of learning.
When networks scale, optimization transforms high-dimensional noise
into low-dimensional order —
the same mathematical symmetry-breaking seen in physics and evolution.
6.15 Bridge Forward
We have traced the full arc:
| Domain | Core Quantity | Governing Equation |
|---|---|---|
| Representation | manifold metric g(z)g(z)g(z) | JE⊤JEJ_E^\top J_EJE⊤JE |
| Information | curvature of p(x)p(x)p(x) | Fisher metric |
| Energy | potential E(x)E(x)E(x) | p(x) ∝ e−Ep(x)\!\propto\!e^{-E}p(x)∝e−E |
| Optimization | flow θ˙=−∇L\dot{\theta}=-\nabla Lθ˙=−∇L | gradient dynamics |
| Attention | adaptive kernel | Boltzmann over similarity |
| Emergence | phase transition | information compression |
The final step is Evaluation and Reflection —
how we measure, test, and stabilize these emergent systems in production environments.
→ Section 7 – Evaluation and Reflection
7. Evaluation and Reflection
7.1 Why Evaluation is Geometry
Evaluation is not merely about accuracy — it is the measurement of how well a learned manifold aligns with reality.
Every metric we use—loss, perplexity, calibration—measures some geometric distortion between:
- The model’s internal probability surface pθ(x)p_\theta(x)pθ(x), and
- The empirical data manifold pdata(x)p_{\text{data}}(x)pdata(x).
The smaller this distortion, the more isometric the learned representation is to the world.
Formally, for any divergence D(pdata∥pθ)D(p_{\text{data}}\|p_\theta)D(pdata∥pθ), perfect learning means:
pθ(x)=pdata(x),D=0.p_\theta(x) = p_{\text{data}}(x), \qquad D=0.pθ(x)=pdata(x),D=0.
The various evaluation metrics we employ are approximations of this divergence under different projections.
7.2 Likelihood and Perplexity
In generative models, the canonical score is log-likelihood:
L=1N∑ilogpθ(xi),\mathcal{L} = \frac{1}{N}\sum_i \log p_\theta(x_i),L=N1i∑logpθ(xi),
or equivalently perplexity:
PPL=e−L.\text{PPL} = e^{-\mathcal{L}}.PPL=e−L.
Perplexity measures the effective branching factor —
how many equally likely choices the model faces at each prediction step.
- Lower perplexity → tighter, sharper energy valleys (less entropy).
- Higher perplexity → flatter surface (more uncertainty).
Intuition:
A perfect model compresses data to its minimal entropy;
perplexity quantifies how far we are from that ideal compression.
7.3 Cross-Entropy and Calibration
Cross-entropy decomposes as
H(p,q)=H(p)+DKL(p∥q).H(p,q) = H(p) + D_{KL}(p\|q).H(p,q)=H(p)+DKL(p∥q).
Since H(p)H(p)H(p) is fixed for the dataset, minimizing cross-entropy is equivalent to minimizing the KL divergence between predicted and true distributions.
But calibration checks something subtler:
whether predicted probabilities correspond to empirical frequencies.
Let p^\hat{p}p^ be the model’s predicted confidence and pˉ\bar{p}pˉ the actual observed accuracy.
A calibrated model satisfies:
P(Y=1∣p^=p)=p.P(Y=1\mid\hat{p}=p) = p.P(Y=1∣p^=p)=p.
Plots of pˉ\bar{p}pˉ vs. p^\hat{p}p^ form the reliability curve.
Deviation from the diagonal indicates over- or under-confidence —
curvature mismatch in the model’s belief space.
7.4 Sharpness, Flatness, and Generalization
From Section 4, we know curvature of the loss landscape determines generalization.
We can approximate sharpness by the spectral norm of the Hessian:
λmax(H)=max∥v∥=1v⊤Hv.\lambda_{\max}(H)=\max_{\|v\|=1} v^\top H v.λmax(H)=∥v∥=1maxv⊤Hv.
Lower λmax\lambda_{\max}λmax → flatter minima → higher robustness to perturbations.
Empirically, flatness correlates with better out-of-distribution (OOD) performance,
since nearby data points map to similar energies.
Regularization via geometry:
- Weight decay → penalizes large norms (shrinks curvature).
- Dropout → randomizes tangent directions.
- Sharpness-aware minimization (SAM) → explicitly optimizes for low curvature.
7.5 Probing and Linear Separability
To test what the model “knows,” we fit linear probes on intermediate activations h(x)h(x)h(x).
If a simple linear classifier can predict attribute yyy from h(x)h(x)h(x):
y=sign(w⊤h(x)+b),y = \text{sign}(w^\top h(x) + b),y=sign(w⊤h(x)+b),
then the concept is linearly separable in that layer’s representation space.
Layerwise probe performance over depth reveals the flow of abstraction:
- early layers → local features (edges, syntax),
- mid layers → compositional semantics,
- final layers → task-specific reasoning.
Geometrically, this measures how flatly a concept lies on the manifold.
7.6 Representation Similarity Metrics
Several tools quantify how similar two models’ internal geometries are:
| Metric | Definition | Measures |
|---|---|---|
| CKA (Centered Kernel Alignment) | correlation between Gram matrices of activations | alignment of manifolds |
| RSA (Representational Similarity Analysis) | correlation of pairwise distances | topological isometry |
| Procrustes distance | optimal orthogonal alignment error | rotational difference |
| SVCCA | canonical correlation of singular vector spaces | shared subspace |
These reveal whether different architectures learn congruent embeddings —
a key step in studying emergent universality across models.
7.7 Information-Theoretic Evaluation
Recall from Section 2:
Mutual information I(X;Z)I(X;Z)I(X;Z) quantifies retained input information,
while I(Z;Y)I(Z;Y)I(Z;Y) quantifies predictive power.
We can measure:
- Compression: how fast I(X;Z)I(X;Z)I(X;Z) decreases with depth,
- Utility: how much I(Z;Y)I(Z;Y)I(Z;Y) remains at final layers.
Good models exhibit steep compression followed by stabilization —
mirroring the information bottleneck curve.
Empirically, this can be approximated by density models or MINE estimators that measure MI between activations and labels.
7.8 Robustness and Distributional Shift
OOD evaluation tests whether the manifold extrapolates beyond training support.
Given train distribution ptrain(x)p_{\text{train}}(x)ptrain(x) and test distribution ptest(x)p_{\text{test}}(x)ptest(x),
define shift:
DKL(ptest∥ptrain)>0.D_{KL}(p_{\text{test}}\|p_{\text{train}}) > 0.DKL(ptest∥ptrain)>0.
Robust models maintain low expected loss under perturbations δx\delta xδx:
E[L(f(x+δx),y)]≈E[L(f(x),y)].E[L(f(x+\delta x),y)] \approx E[L(f(x),y)].E[L(f(x+δx),y)]≈E[L(f(x),y)].
This corresponds to local Lipschitz continuity:
∥∇xf(x)∥≤κ.\|\nabla_x f(x)\|\le \kappa.∥∇xf(x)∥≤κ.
Training with noise, adversarial examples, or contrastive augmentations directly shapes this Lipschitz bound —
flattening the learned manifold.
7.9 Interpretability and Saliency Geometry
Gradient-based saliency measures derive from:
Si=∂y∂xi.S_i = \frac{\partial y}{\partial x_i}.Si=∂xi∂y.
These define vector fields of attribution over the input space.
Smoothness and alignment of S(x)S(x)S(x) across examples indicate coherent local geometry.
Integrated gradients and Layer-wise Relevance Propagation approximate the cumulative flow of contribution across the network’s vector field.
Intuition:
Interpretability = differentiable explainability —
the manifold is interpretable when its tangent directions align with human-perceived causal axes.
7.10 Emergent Metrics: Perplexity Is Not Enough
In large models, downstream capabilities (e.g., reasoning, code synthesis) often improve without significant perplexity change.
Hence, new evaluative dimensions emerge:
| Axis | Proxy Metric | Description |
|---|---|---|
| Knowledge | factual QA accuracy | static recall of world data |
| Reasoning | chain-of-thought consistency | multi-step inference |
| Abstraction | analogy completion | relational mapping |
| Ethics/Value alignment | preference models | coherence with normative constraints |
| Creativity | diversity/novelty indices | entropy in semantic space |
These go beyond local curvature — they probe global structure of the learned manifold.
7.11 Monitoring Model Drift
In production, parameters evolve via continued fine-tuning.
We can monitor drift through metrics on weight-space geometry:
- Weight-space cosine similarity: cos(θ1,θ2)=⟨w1,w2⟩∥w1∥∥w2∥.\cos(\theta_1,\theta_2) = \frac{\langle w_1,w_2\rangle}{\|w_1\|\|w_2\|}.cos(θ1,θ2)=∥w1∥∥w2∥⟨w1,w2⟩.
- Fisher information distance between checkpoints.
- Spectral norm change of Jacobians.
Drift signals whether adaptation preserves prior knowledge or distorts it —
analogous to measuring curvature change of a dynamic manifold.
7.12 Evaluating Attention Geometry
For Transformer-based models, evaluate attention entropy and sparsity:
- Mean attention entropy across heads:
Hˉ=1nH∑i,hHi(h).\bar{H}=\frac{1}{nH}\sum_{i,h} H_i^{(h)}.Hˉ=nH1∑i,hHi(h).
- Head diversity: correlation of attention maps.
Lower correlation ⇒ richer decomposition of relational structure.
Plotting Hˉ\bar{H}Hˉ vs. performance reveals the entropy–accuracy frontier:
too diffuse → underfitting; too sharp → overfitting.
7.13 Calibration of Large-Scale Models
Large language models can be overconfident even when wrong.
We calibrate via temperature scaling:
p′(y∣x)=exp(zy/T)∑jexp(zj/T).p'(y|x)=\frac{\exp(z_y/T)}{\sum_j\exp(z_j/T)}.p′(y∣x)=∑jexp(zj/T)exp(zy/T).
Choosing TTT to minimize negative log-likelihood on a validation set rescales energy magnitudes.
This linear correction aligns the manifold’s local curvature with empirical uncertainty —
a post-hoc fix for distorted Fisher geometry.
7.14 Reflection — The Meta-Metric
Ultimately, all metrics reflect one invariant idea:
Learning succeeds when the model’s internal geometry mirrors the causal geometry of the world.
Whether we measure entropy, curvature, mutual information, or Hessian spectra,
we are assessing alignment between two manifolds: the manifold of data and the manifold of representation.
This perspective unifies all evaluation traditions —
statistics, optimization, and cognition — under the same geometric principle.
7.15 Bridge Forward
We now stand at the meta-level:
how to connect evaluation and geometry back to system design.
The next natural evolution is toward agentic systems:
models that maintain, test, and refine their own manifolds dynamically —
learning how to learn.
→ Section 8 – Agentic Systems and Self-Organization
8. Agentic Systems and Self-Organization
8.1 From Function Approximation to Behavior
A trained model defines a function
fθ:X→Y.f_\theta : \mathcal{X} \to \mathcal{Y}.fθ:X→Y.
An agent extends this to a closed loop with the environment:
st+1=T(st,at),at=fθ(ot),ot=O(st).s_{t+1} = \mathcal{T}(s_t, a_t), \qquad a_t = f_\theta(o_t), \quad o_t = \mathcal{O}(s_t).st+1=T(st,at),at=fθ(ot),ot=O(st).
Here T\mathcal{T}T is environment dynamics, O\mathcal{O}O is observation mapping, and fθf_\thetafθ the policy.
Thus, an agent is a dynamical system over belief space, not just a static map.
Learning now involves two intertwined manifolds:
- World manifold — transitions and rewards (s,a,s′)(s,a,s')(s,a,s′).
- Model manifold — parameters θ\thetaθ evolving by optimization.
Agency emerges when the model updates itself based on the feedback it induces in the world.
8.2 Reinforcement Learning as Energy Minimization
Reinforcement learning (RL) can be recast as free-energy minimization.
We maximize expected cumulative reward:
J(θ)=Eτ∼pθ(τ)[R(τ)],J(\theta) = \mathbb{E}_{\tau \sim p_\theta(\tau)}[R(\tau)],J(θ)=Eτ∼pθ(τ)[R(τ)],
where τ\tauτ is a trajectory (s0,a0,s1,…)(s_0,a_0,s_1,\dots)(s0,a0,s1,…) and RRR its return.
Equivalently, define energy E(τ)=−R(τ)E(\tau) = -R(\tau)E(τ)=−R(τ):
pθ(τ)∝eR(τ)=e−E(τ).p_\theta(\tau) \propto e^{R(\tau)} = e^{-E(\tau)}.pθ(τ)∝eR(τ)=e−E(τ).
Gradient ascent on J(θ)J(\theta)J(θ) corresponds to descending this energy:
∇θJ=Epθ(τ)[∇θlogpθ(τ)R(τ)].\nabla_\theta J = \mathbb{E}_{p_\theta(\tau)}[\nabla_\theta \log p_\theta(\tau) R(\tau)].∇θJ=Epθ(τ)[∇θlogpθ(τ)R(τ)].
This is the policy gradient theorem, the RL analogue of statistical mechanics:
trajectories with higher reward have lower energy.
8.3 The Policy Manifold and Natural Gradients
A policy πθ(a∣s)\pi_\theta(a|s)πθ(a∣s) defines a manifold of distributions over actions.
Its intrinsic geometry is measured by the Fisher information metric:
Gij(θ)=Eπθ [∂ilogπθ(a∣s)∂jlogπθ(a∣s)].G_{ij}(\theta)
= \mathbb{E}_{\pi_\theta}
\!\left[
\partial_i \log \pi_\theta(a|s)
\partial_j \log \pi_\theta(a|s)
\right].Gij(θ)=Eπθ[∂ilogπθ(a∣s)∂jlogπθ(a∣s)].
The steepest-ascent direction on this manifold is the natural gradient:
θ˙=G−1∇θJ.\dot{\theta} = G^{-1}\nabla_\theta J.θ˙=G−1∇θJ.
Thus RL optimization becomes motion along geodesics of expected return —
energy flows on the policy manifold.
Intuition:
ordinary gradients change parameters; natural gradients change behavior.
8.4 The Control-Theoretic View
An agent seeks to minimize future prediction error between desired and observed outcomes.
Define cost:
C=∑t∥st−s^t∥2,\mathcal{C} = \sum_t \|s_t - \hat{s}_t\|^2,C=t∑∥st−s^t∥2,
where s^t\hat{s}_ts^t is predicted next state.
Minimizing C\mathcal{C}C produces feedback control:
at=K(st−s^t).a_t = K(s_t - \hat{s}_t).at=K(st−s^t).
If the controller learns KKK adaptively, we obtain the dual gradient system:
| Space | State variable | Force / update |
|---|---|---|
| Environment | sss | f(s,a)f(s,a)f(s,a) |
| Model | θ\thetaθ | −∇θC-\nabla_\theta \mathcal{C}−∇θC |
The agent continually re-aligns its internal parameters to reduce prediction energy —
a generalization of both backpropagation and RL.
8.5 Active Inference and the Free-Energy Principle
In active inference, the agent minimizes variational free energy:
F=Eq(s)[E(s)]−H[q(s)],F = \mathbb{E}_{q(s)}[E(s)] - H[q(s)],F=Eq(s)[E(s)]−H[q(s)],
where E(s)=−logp(o,s)E(s)=-\log p(o,s)E(s)=−logp(o,s) is surprise and q(s)q(s)q(s) the agent’s belief about states.
Minimizing FFF simultaneously updates:
- Perception: adjust q(s)q(s)q(s) to fit observations,
- Action: adjust aaa to realize expected observations.
Formally:
q˙=−∇qF,a˙=−∇aF.\dot{q} = -\nabla_q F, \qquad \dot{a} = -\nabla_a F.q˙=−∇qF,a˙=−∇aF.
Thus, perception and control are dual gradient flows on the same energy surface —
the agent acts to make the world conform to its predictions.
8.6 Hierarchical Predictive Coding
Let predictions x^l\hat{x}_lx^l and errors εl=xl−x^l\varepsilon_l = x_l - \hat{x}_lεl=xl−x^l propagate between layers.
Top-down:
x^l−1=fl(xl),\hat{x}_{l-1} = f_l(x_l),x^l−1=fl(xl),
Bottom-up:
εl−1=xl−1−x^l−1.\varepsilon_{l-1} = x_{l-1} - \hat{x}_{l-1}.εl−1=xl−1−x^l−1.
Each layer updates to minimize local free energy:
x˙l=−∂F∂xl=fl+1⊤εl+1−εl.\dot{x}_l = -\frac{\partial F}{\partial x_l} = f_{l+1}^\top \varepsilon_{l+1} - \varepsilon_l.x˙l=−∂xl∂F=fl+1⊤εl+1−εl.
This reproduces both backpropagation (gradient of prediction error)
and Bayesian inference (belief update).
Hierarchical predictive coding unifies perception, memory, and reasoning as energy minimization across scales.
8.7 Memory and Recurrent Energy Landscapes
Memory arises when internal states evolve more slowly than external inputs:
dzdt=−∇zE(z,x),\frac{dz}{dt} = -\nabla_z E(z,x),dtdz=−∇zE(z,x),
with xxx changing faster than zzz.
Then zzz integrates a temporal average of past stimuli —
a dynamic low-pass filter.
Transformers simulate this by maintaining contextual embeddings that update via attention:
their energy landscape retains past minima as soft attractors.
8.8 Continual and Meta-Learning
Meta-learning introduces a slow parameter ϕ\phiϕ governing the fast parameter θ\thetaθ.
Inner loop:
θ′=θ−ηθ∇θLtask(θ).\theta' = \theta - \eta_\theta \nabla_\theta L_\text{task}(\theta).θ′=θ−ηθ∇θLtask(θ).
Outer loop:
ϕ←ϕ−ηϕ∇ϕLmeta(θ′(ϕ)).\phi \leftarrow \phi - \eta_\phi \nabla_\phi L_\text{meta}(\theta'(\phi)).ϕ←ϕ−ηϕ∇ϕLmeta(θ′(ϕ)).
Differentiating through the inner optimization embeds learning within learning —
a recursive energy flow.
This framework formalizes adaptivity:
the agent not only descends an energy surface, it learns how to reshape it.
8.9 Self-Organization and Order Parameters
Complex systems spontaneously organize when local updates minimize a global potential.
Let each component xix_ixi follow gradient descent on shared energy E(x1,…,xN)E(x_1,\dots,x_N)E(x1,…,xN):
x˙i=−∂E∂xi.\dot{x}_i = -\frac{\partial E}{\partial x_i}.x˙i=−∂xi∂E.
At equilibrium, collective patterns appear — order parameters ψ(x)\psi(x)ψ(x) summarizing macroscopic structure.
In neural networks:
- Neurons synchronize → feature maps.
- Heads specialize → attention circuits.
- Layers align → hierarchical abstraction.
Self-organization is simply gradient flow with coupling.
8.10 Multi-Agent Systems and Shared Energy
When multiple agents share environment E\mathcal{E}E, each with energy EiE_iEi,
the joint dynamics follow:
x˙i=−∇xiEi(xi,x−i).\dot{x}_i = -\nabla_{x_i} E_i(x_i,x_{-i}).x˙i=−∇xiEi(xi,x−i).
If EiE_iEi depends on others’ actions, interactions form potential games.
Equilibrium corresponds to a Nash configuration where no agent can unilaterally lower its energy.
In cooperative settings:
Eglobal=∑iEi.E_\text{global} = \sum_i E_i.Eglobal=i∑Ei.
In adversarial (GAN-like) setups:
Eglobal=Egen−Edisc.E_\text{global} = E_\text{gen} - E_\text{disc}.Eglobal=Egen−Edisc.
Training GANs is thus multi-agent energy minimax —
adversarial gradient flow on coupled manifolds.
8.11 Reflection and Self-Evaluation
An agent becomes reflective when it maintains an internal model of its own performance.
Let rtr_trt be reward, r^t\hat{r}_tr^t the predicted reward.
Define meta-loss:
Lreflect=(rt−r^t)2.L_{\text{reflect}} = (r_t - \hat{r}_t)^2.Lreflect=(rt−r^t)2.
Updating ϕ\phiϕ in a meta-model r^t=fϕ(ht)\hat{r}_t=f_\phi(h_t)r^t=fϕ(ht) forms an introspective loop:
the system learns a predictive model of its own learning success.
This loop produces self-stabilization:
agents adjust exploration, temperature, or confidence dynamically —
closing the gap between perception and control of themselves.
8.12 Information Geometry of Agency
Agentic systems operate on two coupled manifolds:
- Belief manifold: q(s)q(s)q(s) with metric GsG_sGs (Fisher information).
- Policy manifold: π(a∣s)\pi(a|s)π(a∣s) with metric GθG_\thetaGθ.
Free-energy gradients couple them:
q˙=−Gs−1∇qF,θ˙=−Gθ−1∇θF.\dot{q} = -G_s^{-1}\nabla_q F, \quad \dot{\theta} = -G_\theta^{-1}\nabla_\theta F.q˙=−Gs−1∇qF,θ˙=−Gθ−1∇θF.
This defines a dual-manifold flow — beliefs shape actions; actions reshape beliefs.
Equilibria correspond to stationary points where expected surprise is minimized across both manifolds.
8.13 Energy, Entropy, and Curiosity
Exploration requires temporary deviation from energy minima.
Define an intrinsic reward proportional to entropy change:
rtint=βΔH(qt).r_t^{\text{int}} = \beta \Delta H(q_t).rtint=βΔH(qt).
Agents maximize combined reward:
Rt=rtext+rtint.R_t = r_t^{\text{ext}} + r_t^{\text{int}}.Rt=rtext+rtint.
This encourages movement toward states that increase information gain —
the curiosity drive, equivalent to maximizing expected Fisher information over trajectories.
8.14 Emergent Planning and World Models
If the agent learns a generative model pϕ(s′∣s,a)p_\phi(s'|s,a)pϕ(s′∣s,a),
it can simulate imaginary rollouts s^t+k\hat{s}_{t+k}s^t+k and choose actions minimizing predicted energy.
Formally, define model-based control objective:
minaEpϕ(s′∣s,a)[E(s′,a)].\min_a \; \mathbb{E}_{p_\phi(s'|s,a)}[E(s',a)].aminEpϕ(s′∣s,a)[E(s′,a)].
Differentiating through the world model yields gradients in action space:
∇aE[E]=E[∇aE+(∇s′E)(∇as′)].\nabla_a \mathbb{E}[E] = \mathbb{E}[\nabla_a E + (\nabla_{s'}E)(\nabla_a s')].∇aE[E]=E[∇aE+(∇s′E)(∇as′)].
Thus planning is just backpropagation through a differentiable environment —
an agent’s mental simulation of future energy.
8.15 Emergent Communication and Coordination
In multi-agent language games, communication emerges when it reduces expected joint energy:
Ejoint=Ep(m1,m2)[E(s∣m1,m2)].E_{\text{joint}} = \mathbb{E}_{p(m_1,m_2)}[E(s|m_1,m_2)].Ejoint=Ep(m1,m2)[E(s∣m1,m2)].
If I(M1;S)I(M_1;S)I(M1;S) and I(M2;S)I(M_2;S)I(M2;S) both increase, messages m1,m2m_1,m_2m1,m2 align on a shared latent manifold.
Languages evolve as compressive codes minimizing free energy while maximizing mutual predictability —
the same trade-off that governed representation learning in Section 2.
8.16 Reflective Summary
At this point, the pattern is universal:
| Domain | Dynamical variable | Governing flow | Equilibrium condition |
|---|---|---|---|
| Supervised learning | weights θ\thetaθ | −∇θL-\nabla_\theta L−∇θL | ∇L=0\nabla L=0∇L=0 |
| Reinforcement | policy πθ\pi_\thetaπθ | G−1∇θJG^{-1}\nabla_\theta JG−1∇θJ | optimal return |
| Active inference | beliefs, actions | −∇F-\nabla F−∇F | minimal surprise |
| Multi-agent | states xix_ixi | −∇xiEi-\nabla_{x_i}E_i−∇xiEi | Nash equilibrium |
| Meta-learning | hyperparameters ϕ\phiϕ | −∇ϕLmeta-\nabla_\phi L_{\text{meta}}−∇ϕLmeta | adaptive equilibrium |
All are manifestations of the same geometric engine:
gradient flows on coupled manifolds, exchanging energy and information until equilibrium yields order.
8.17 Reflection — The Birth of Agency
From a reflective lens:
Agency is the closure of the learning loop.
When a system’s outputs modify the inputs that train it,
learning becomes self-referential.
Optimization transforms into autopoiesis — self-maintenance through feedback.
This perspective reframes intelligence:
not as rule execution, but as continuous energy regulation
across nested manifolds of data, model, and world.
8.18 Bridge Forward
The final synthesis is Evaluation and Control of Agentic Systems —
how to measure stability, alignment, and safety of these self-organizing dynamics.
We now turn to formal criteria for equilibrium, bounded entropy, and ethical curvature.
→ Section 9 – Stability, Alignment, and Control
9. Stability, Alignment, and Control
9.1 Stability as Curvature Control
Any learning or agentic system is a dynamical process:
x˙=f(x),x∈Rn.\dot{x}=f(x),\qquad x\in\mathbb{R}^n .x˙=f(x),x∈Rn.
Linearize near equilibrium x\*x^\*x\*:
δx˙=Jf(x\*)δx,Jf=∂f∂x.\dot{\delta x}=J_f(x^\*)\,\delta x,\quad J_f=\frac{\partial f}{\partial x}.δx˙=Jf(x\*)δx,Jf=∂x∂f.
If all eigenvalues λi(Jf)\lambda_i(J_f)λi(Jf) have ℜ(λi)<0\Re(\lambda_i)<0ℜ(λi)<0,
small perturbations decay — the system is locally stable.
In high-dimensional learning systems,
the Jacobian JfJ_fJf corresponds to the Hessian or Fisher curvature.
Hence stability ⇔ negative-definite curvature of the potential L(x)L(x)L(x).
9.2 Lyapunov Functions and Energy Basins
A Lyapunov function V(x)V(x)V(x) is a scalar energy satisfying
V(x)>0,V˙(x)=∇V ⋅ f(x)≤0.V(x)>0,\quad \dot{V}(x)=\nabla V\!\cdot\!f(x)\le0.V(x)>0,V˙(x)=∇V⋅f(x)≤0.
Then VVV monotonically decreases → trajectories converge to minima.
In learning, V=L(θ)V=L(\theta)V=L(θ) or expected free energy FFF.
Training is stable when L˙≤0\dot{L}\le0L˙≤0 despite stochastic noise.
Momentum and adaptive optimizers adjust friction to enforce this inequality.
9.3 Control Theory Analogue
We can recast optimization as feedback control:
| Control variable | Role in ML |
|---|---|
| State xxx | Parameters θ\thetaθ or latent zzz |
| Control uuu | Gradient update −∇L-\nabla L−∇L |
| Dynamics AAA | Curvature matrix HHH |
| Feedback gain KKK | Learning rate η\etaη |
| Stability criterion | Eigenvalues of I−ηHI-\eta HI−ηH inside unit circle |
Adaptive control → adaptive learning rates;
integral control → momentum;
state observer → gradient estimator.
9.4 Stochastic Stability and Diffusion Bounds
With stochastic noise ξt\xi_tξt:
dθ=−∇Ldt+Σ1/2dWt.d\theta = -\nabla L\,dt + \Sigma^{1/2} dW_t.dθ=−∇Ldt+Σ1/2dWt.
The steady-state distribution:
p(θ)∝e−L(θ)/T,T∝Σ.p(\theta)\propto e^{-L(\theta)/T},\quad T\propto \Sigma.p(θ)∝e−L(θ)/T,T∝Σ.
Bounded TTT ensures ergodic stability — exploration without divergence.
Too high TTT → chaos; too low TTT → premature convergence.
9.5 Robust Stability via Gain Margins
In feedback terms:
y=G(s)u,u=−K(s)y.y = G(s)u,\qquad u = -K(s)y.y=G(s)u,u=−K(s)y.
The loop gain L(s)=G(s)K(s)L(s)=G(s)K(s)L(s)=G(s)K(s).
Robust stability requires phase margin > 0 and gain margin > 1.
In learning, this corresponds to step-size vs. curvature balance:
0<ηλmax(H)<2.0<\eta \lambda_{\max}(H)<2.0<ηλmax(H)<2.
Violation → oscillation or exploding gradients.
Adaptive optimizers maintain η\etaη below the Nyquist limit.
9.6 Alignment as Objective Coherence
Let environment utility U(s,a)U(s,a)U(s,a) and model objective Rθ(s,a)R_\theta(s,a)Rθ(s,a) differ.
Alignment means their gradients align:
∇aRθ∝∇aU.\nabla_a R_\theta \propto \nabla_a U.∇aRθ∝∇aU.
Misalignment = non-zero angle:
cosϕ=∇aRθ ⋅ ∇aU∥∇aRθ∥∥∇aU∥.\cos \phi = \frac{\nabla_a R_\theta \!\cdot\!\nabla_a U} {\|\nabla_a R_\theta\|\|\nabla_a U\|}.cosϕ=∥∇aRθ∥∥∇aU∥∇aRθ⋅∇aU.
Control theoretically, alignment ≡ matching the controller’s cost function to the plant’s true performance index.
9.7 Energy Constraints and Value Boundedness
To prevent unbounded optimization, constrain expected energy:
E[L]≤Lmax,Var[L]≤σmax2.E[L]\le L_{\max},\quad \text{Var}[L]\le\sigma^2_{\max}.E[L]≤Lmax,Var[L]≤σmax2.
Equivalent to keeping Hessian spectrum within limits:
∣λi(H)∣≤Λ.|\lambda_i(H)| \le \Lambda.∣λi(H)∣≤Λ.
Bounding curvature → bounded force → safe control.
Regularization and gradient clipping implement this physically.
9.8 Entropy Regulation and Exploration Balance
In RL and active inference, entropy term:
L=−E[R]−βH(π).\mathcal{L} = -\mathbb{E}[R] - \beta H(\pi).L=−E[R]−βH(π).
Large β\betaβ → safe exploration; small β\betaβ → exploitative stability.
Entropy acts as a temperature controller, ensuring the agent does not collapse into degenerate policies.
9.9 Information-Theoretic Alignment
For an aligned agent, its policy information flow matches environment causality:
I(A;S′)πθ≈I(A;S′)env.I(A;S')_{\pi_\theta} \approx I(A;S')_{\text{env}}.I(A;S′)πθ≈I(A;S′)env.
Deviation ΔI\Delta IΔI quantifies over- or under-control:
- ΔI>0\Delta I > 0ΔI>0 → agent acts on spurious correlations.
- ΔI<0\Delta I < 0ΔI<0 → agent ignores causal structure.
Regularizing ΔI→0\Delta I \to 0ΔI→0 enforces causal alignment.
9.10 Ethical Curvature (Reflection)
Ethical alignment can be cast as a constraint on energy gradients over value dimensions viv_ivi:
∥∇viE(x)∥≤ϵi.\|\nabla_{v_i} E(x)\| \le \epsilon_i.∥∇viE(x)∥≤ϵi.
Bounded magnitude prevents optimization that distorts human utility space too steeply.
In practice: reward penalties, KL regularization to reference policies, or RLHF constraints.
9.11 Stability in Multi-Agent Settings
For coupled agents:
x˙i=−∇xiEi(xi,x−i).\dot{x}_i = -\nabla_{x_i} E_i(x_i,x_{-i}).x˙i=−∇xiEi(xi,x−i).
Linearizing around joint equilibrium x\*x^\*x\* gives Jacobian JJJ partitioned into blocks JijJ_{ij}Jij.
Stability requires the symmetric part (J+J⊤)/2(J+J^\top)/2(J+J⊤)/2 be negative definite.
This condition ensures energy decreases for all agents collectively — no limit cycles or divergent competition.
9.12 Lyapunov-Based Alignment Checks
Define global potential V(x)=∑iwiEi(x)V(x)=\sum_i w_i E_i(x)V(x)=∑iwiEi(x).
If V˙≤0\dot{V}\le0V˙≤0 under joint updates, the system is aligned.
Otherwise introduce coordination terms to restore monotonic descent:
x˙i=−∇xiEi− ∑jcij(xi−xj).\dot{x}_i=-\nabla_{x_i} E_i -\!\sum_j c_{ij}(x_i-x_j).x˙i=−∇xiEi−j∑cij(xi−xj).
Coupling matrix CCC adds dissipation across agents — a formal model of alignment mechanisms like consensus regularization.
9.13 Spectral Diagnostics for Safety
Track eigenvalues of the Hessian or Jacobian through training:
- Positive outliers → exploding modes.
- Complex pairs → oscillations.
- Dense bulk near 0 → flat, safe regime.
Tools: Lanczos approximation, power iteration, or Hutchinson trace.
Plot spectral radius vs. time to ensure curvature remains bounded.
9.14 Formal Guarantees
For a system x˙=f(x)\dot{x}=f(x)x˙=f(x), if there exists P>0P>0P>0 such that:
A⊤P+PA<0,A=∂f∂x,A^\top P + P A < 0, \quad A=\frac{\partial f}{\partial x},A⊤P+PA<0,A=∂x∂f,
then V=x⊤PxV=x^\top P xV=x⊤Px is a Lyapunov function → exponential stability.
In learning, this means choosing optimizer hyperparameters so the linearized update matrix is Hurwitz.
9.15 Alignment through Regularization and Constraint Optimization
Enforce alignment by embedding constraints directly in the objective:
minθL(θ)s.t.gi(θ)≤0.\min_\theta L(\theta) \quad \text{s.t.}\quad g_i(\theta)\le0.θminL(θ)s.t.gi(θ)≤0.
Lagrangian:
L=L(θ)+∑iλigi(θ).\mathcal{L} = L(\theta) + \sum_i \lambda_i g_i(\theta).L=L(θ)+i∑λigi(θ).
Choosing gig_igi as ethical or safety bounds translates normative rules into differentiable geometry.
Dual variables λi\lambda_iλi become shadow prices for constraint violations.
9.16 Robust Optimization and Distributional Shift
For uncertain distributions p(x)∈Pp(x)\in\mathcal{P}p(x)∈P, solve
minθmaxp∈PEp[L(x,θ)].\min_\theta \max_{p\in\mathcal{P}} \mathbb{E}_p[L(x,\theta)].θminp∈PmaxEp[L(x,θ)].
This minimax formulation bounds worst-case loss, analogous to H∞H_\inftyH∞ control in engineering.
Approximation methods:
- Adversarial training → samples worst ppp.
- Distributionally robust optimization (DRO).
- Wasserstein balls around ptrainp_{\text{train}}ptrain.
All ensure bounded energy under perturbation of input geometry.
9.17 Monitoring and Feedback in Deployed Systems
Live agents require continuous feedback control:
- Monitor loss landscape curvature via Hessian traces.
- Measure entropy of policy outputs.
- Track KL divergence from reference distribution.
- Trigger retraining or rate adaptation when metrics exceed thresholds.
This forms an autonomous safety controller analogous to PID stabilization.
9.18 Summary Table
| Concept | Mathematical Form | Physical Meaning | Purpose |
|---|---|---|---|
| Stability | ℜ(λi)<0\Re(\lambda_i)<0ℜ(λi)<0 | decaying perturbations | training convergence |
| Lyapunov function | V˙≤0\dot{V}\le0V˙≤0 | energy dissipation | safety criterion |
| Alignment | ∇R ∥ ∇U\nabla R\!\parallel\!\nabla U∇R∥∇U | objective coherence | ethical control |
| Entropy constraint | βH(π)\beta H(\pi)βH(π) | exploration vs. safety | uncertainty balance |
| Spectral radius | ρ(H)\rho(H)ρ(H) | curvature bound | robustness |
| DRO | minθmaxpEp[L]\min_\theta \max_p E_p[L]minθmaxpEp[L] | worst-case control | OOD stability |
9.19 Reflection — Geometry of Responsibility
Stability and alignment are not extra features; they are boundary conditions on learning flows.
A safe intelligent system is simply one whose energy and information curvature remain bounded under all perturbations.
Control is ethics expressed as geometry.
When we regularize gradients or constrain entropy, we are embedding responsibility into the manifold itself.
9.20 Bridge Forward
With stability and alignment formalized, we can finally treat learning systems as controlled thermodynamic entities — objects whose flows of energy and information can be monitored, bounded, and optimized for safety.
The next and final chapter will connect these principles to evaluation and experimentation:
how to verify curvature, entropy, and alignment properties empirically.
→ Section 10 – Empirical Verification and Experimental Design
10. Empirical Verification and Experimental Design
10.1 Purpose and Framing
Every mathematical structure must confront observation.
For learning systems, experiments expose how gradient flows, curvature, and entropy behave under real data.
Our goals:
- Quantify curvature (Hessian / Fisher geometry).
- Track energy descent and stability margins.
- Measure entropy, alignment, and causal information flow.
- Validate theoretical predictions through reproducible diagnostics.
10.2 Experimental Setup
| Component | Example implementation |
|---|---|
| Framework | PyTorch / JAX |
| Model | MLP, CNN, Transformer |
| Dataset | MNIST, CIFAR-10, synthetic dynamical systems |
| Metrics | Loss, curvature spectrum, entropy, KL divergence |
| Sampling | mini-batch SGD or policy rollouts |
| Visualization | Plotly / Matplotlib interactive dashboards |
Each experiment produces a trajectory{θt,Lt,Ht,H(πt)}\{\theta_t, L_t, H_t, H(\pi_t)\}{θt,Lt,Ht,H(πt)}—the full state of learning flow.
10.3 Measuring Curvature
Compute Hessian-vector products using autograd:
Copy
v = torch.randn_like(params) Hv = torch.autograd.grad( outputs=torch.dot(grad, v), inputs=params, retain_graph=True )[0]
Estimate dominant eigenvalues via power iteration:
λmax≈v⊤Hvv⊤v.\lambda_{\max}\approx \frac{v^\top Hv}{v^\top v}.λmax≈v⊤vv⊤Hv.
Plot λmax(t)\lambda_{\max}(t)λmax(t) to track curvature over time.
Stable training ⇔ bounded λmax\lambda_{\max}λmax.
Intuition:
Sharp minima → large curvature → brittle generalization.
Flat minima → small curvature → robust, energy-dissipative equilibria.
10.4 Hessian Trace and Effective Dimensionality
The trace Tr(H)\text{Tr}(H)Tr(H) approximates total curvature energy.
Estimate via Hutchinson’s trick:
Tr(H)≈1K∑k=1Kvk⊤(Hvk),vk∼N(0,I).\text{Tr}(H)\approx \frac{1}{K}\sum_{k=1}^K v_k^\top (H v_k), \quad v_k\sim\mathcal{N}(0,I).Tr(H)≈K1k=1∑Kvk⊤(Hvk),vk∼N(0,I).
Plot Tr(H)\text{Tr}(H)Tr(H) vs. epoch to see compression of parameter space—
a proxy for intrinsic dimensionality.
10.5 Gradient Flow Diagnostics
At each step record:
gt=∇θLt,∥gt∥,⟨gt,gt−1⟩,∥gt∥∥gt−1∥.g_t = \nabla_\theta L_t,\quad \|g_t\|,\; \langle g_t, g_{t-1}\rangle,\; \frac{\|g_t\|}{\|g_{t-1}\|}.gt=∇θLt,∥gt∥,⟨gt,gt−1⟩,∥gt−1∥∥gt∥.
Visualize:
- Gradient norm collapse → stagnation.
- Oscillating inner product → limit cycles.
- Smooth decay → stable Lyapunov flow.
10.6 Energy Descent Verification
Compute discrete derivative:
ΔLt=Lt+1−Lt.\Delta L_t = L_{t+1}-L_t.ΔLt=Lt+1−Lt.
Check E[ΔLt]≤0\mathbb{E}[\Delta L_t]\le0E[ΔLt]≤0 under noise.
Plot ΔLt\Delta L_tΔLt histogram; long positive tails → potential instability.
Lyapunov check:
Vt=Lt,Vt+1−Vt≤0.V_t=L_t,\quad V_{t+1}-V_t\le0.Vt=Lt,Vt+1−Vt≤0.
If violated persistently, adjust learning rate η\etaη or damping β\betaβ.
10.7 Entropy and Policy Temperature
For stochastic policies:
H(πt)=−∑aπt(a∣s)logπt(a∣s).H(\pi_t)= -\sum_a \pi_t(a|s)\log\pi_t(a|s).H(πt)=−a∑πt(a∣s)logπt(a∣s).
Track HtH_tHt to ensure non-collapse.
Plot (Lt,Ht)(L_t,H_t)(Lt,Ht) phase plane—stable regimes show a smooth inverse relation.
Add temperature τ\tauτ and verify gradient of entropy term:
∂τL=−H(π).\partial_\tau L = -H(\pi).∂τL=−H(π).
This quantifies exploration–exploitation coupling.
10.8 Information Flow Metrics
Compute mutual information:
I(X;Z)=H(Z)−H(Z∣X)I(X;Z)=H(Z)-H(Z|X)I(X;Z)=H(Z)−H(Z∣X)
via variational bounds (MINE estimator or InfoNCE):
Copy
I_est = torch.mean(f(x,z)) - torch.log(torch.mean(torch.exp(f(x, z_perm))))
Monitor I(X;Z)I(X;Z)I(X;Z) through layers → information bottleneck visualization.
Collapse → over-compression; inflation → memorization.
10.9 Alignment Verification
Compare gradients of model and reference objectives:
cosϕt=∇θLmodel ⋅ ∇θLref∥∇θLmodel∥∥∇θLref∥.\cos\phi_t = \frac{\nabla_\theta L_{\text{model}}\!\cdot\!\nabla_\theta L_{\text{ref}}} {\|\nabla_\theta L_{\text{model}}\|\|\nabla_\theta L_{\text{ref}}\|}.cosϕt=∥∇θLmodel∥∥∇θLref∥∇θLmodel⋅∇θLref.
cosϕt ≈ 1\cos\phi_t\!\approx\!1cosϕt≈1 ⇒ coherent alignment.
Sudden drops indicate objective drift (e.g., RL reward mis-specification).
Plot ϕt\phi_tϕt vs. time alongside loss.
10.10 Spectral Tracking of Dynamics
Linearize parameter updates:
θt+1=θt−ηHtgt.\theta_{t+1} = \theta_t - \eta H_t g_t.θt+1=θt−ηHtgt.
Estimate spectral radius ρ(Ht)\rho(H_t)ρ(Ht) each epoch.
Condition for discrete-time stability:
0<ηρ(Ht)<2.0<\eta\rho(H_t)<2.0<ηρ(Ht)<2.
Plot ηρ(Ht)\eta\rho(H_t)ηρ(Ht); crossing 2 signals oscillatory divergence.
10.11 Visualization — Energy Landscape Mapping
Generate 2-D loss contours:
Copy
alpha, beta = np.mgrid[-1:1:100j, -1:1:100j] L_map = [] for a,b in zip(alpha.ravel(), beta.ravel()): params_perturbed = theta_star + a*v1 + b*v2 L_map.append(loss(params_perturbed))
Reshape into surface and plot.
Observe basins, ridges, and curvature transitions
Comments
Sign in to leave a comment.
No comments yet.