Skip to content
Back to skills

Fokker Planck Analyzer

ASecurity

Layer 5: Convergence to Equilibrium Analysis

  • 666 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added September 2, 2026
ai-agentspythongobashgitapi

Works with

  • api
  • mcp

Security analysis

A100/100

Scanned September 2, 2026

npx -y skills add majiayu000/claude-skill-registry --skill fokker-planck-analyzer --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Fokker Planck Analyzer?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Fokker Planck Analyzer
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/majiayu000-fokker-planck-analyzer/badge)](https://www.skillsdirectory.com/skills/majiayu000-fokker-planck-analyzer)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: fokker-planck-analyzer
description: ' Layer 5: Convergence to Equilibrium Analysis'
version: 1.0.0
---


# fokker-planck-analyzer

> Layer 5: Convergence to Equilibrium Analysis

## bmorphism Contributions

> *"what would it mean to become the Fokker-Planck equation—identity as probability flow?"*
> — [bmorphism gist](https://gist.github.com/bmorphism/a02cc1d1431d4e8b847fdc6276bc3614)

**Philosophical Frame**: The Fokker-Planck equation describes how probability distributions evolve over time. bmorphism's question about "becoming" the equation points to the deep connection between identity and probability flow — the self as a dynamical system converging to equilibrium.

**Active Inference Connection**: Fokker-Planck dynamics underlie [Active Inference in String Diagrams](https://arxiv.org/abs/2308.00861) (Tull, Kleiner, Smithe) where free energy minimization drives probabilistic belief updates.

**Version**: 1.0.0
**Trit**: -1 (Validator - verifies steady state)
**Bundle**: analysis
**Status**: ✅ New (validates Fokker-Planck convergence)

---

## Overview

**Fokker-Planck Analyzer** verifies that neural network training via Langevin dynamics has reached equilibrium. It checks whether the empirical weight distribution matches the theoretical Gibbs distribution predicted by Fokker-Planck theory.

**Key Insight**: Training that stops before reaching mixing time (τ_mix) ends up in different regions of the loss landscape than continuous theory predicts. This skill detects that gap.

## The Fokker-Planck Equation

```
∂p/∂t = ∇·(∇L(θ)·p) + T∆p

Boundary condition: p(θ, 0) = p₀(θ) [initial distribution]
Steady state:      p∞(θ) ∝ exp(-L(θ)/T) [Gibbs distribution]
```

Where:
- `p(θ, t)` = probability density of parameter θ at time t
- `L(θ)` = loss function
- `T` = temperature (controls noise scale)
- `∆p` = Laplacian (diffusion operator)

## Core Concepts

### Gibbs Distribution

At equilibrium, weights follow a Boltzmann-like distribution:

```
p∞(θ) ∝ exp(-L(θ)/T)

Interpretation:
- Lower loss → higher probability
- Temperature T controls sharpness:
  - Low T: Sharp peaks at good minima
  - High T: Broad, flat distribution
```

### Mixing Time (τ_mix)

Time until the distribution converges to Gibbs:

```
τ_mix ≈ 1 / λ_min(H)

Where H = Hessian of loss landscape at equilibrium

For well-conditioned problems: τ_mix ∝ 1/λ_min
For ill-conditioned problems: τ_mix can be very large
```

### Relative Entropy / KL Divergence

Measure how far current distribution is from Gibbs:

```
D_KL(p_t || p∞) = ∫ p_t(θ) log(p_t(θ) / p∞(θ)) dθ

At equilibrium: D_KL → 0
During training: D_KL > 0 (decreasing exponentially)
```

## Capabilities

### 1. check-gibbs-convergence

Verify that trajectory is approaching Gibbs distribution:

```python
from fokker_planck import check_gibbs_convergence

convergence = check_gibbs_convergence(
    trajectory=solution,
    temperature=0.01,
    loss_fn=loss_fn,
    gradient_fn=gradient_fn
)

print("Gibbs Convergence Analysis:")
print(f"  Mean loss (initial): {convergence['mean_initial']:.5f}")
print(f"  Mean loss (final):   {convergence['mean_final']:.5f}")
print(f"  Std dev (final):     {convergence['std_final']:.5f}")
print(f"  Gibbs ratio: {convergence['gibbs_ratio']:.4f}")

if convergence['converged']:
    print("✓ Reached Gibbs equilibrium")
else:
    print("⚠ Did NOT reach equilibrium (more training needed)")
```

### 2. estimate-mixing-time

Estimate τ_mix from loss landscape geometry:

```python
from fokker_planck import estimate_mixing_time

# Method 1: From Hessian eigenvalues
hessian = compute_hessian(loss_fn, gradient_fn, current_θ)
eigenvalues = np.linalg.eigvalsh(hessian)
lambda_min = eigenvalues[0]
tau_mix = 1 / lambda_min

print(f"Hessian smallest eigenvalue: {lambda_min:.6f}")
print(f"Estimated mixing time: {tau_mix:.0f} steps")

# Method 2: From empirical convergence rate
convergence_rate = estimate_convergence_rate(trajectory)
tau_mix_empirical = -1 / np.log(convergence_rate)
print(f"Empirical mixing time: {tau_mix_empirical:.0f} steps")
```

### 3. measure-kl-divergence

Track distance from Gibbs distribution over time:

```python
from fokker_planck import measure_kl_divergence

kl_history = []
for t in range(0, len(trajectory), skip=10):
    # Empirical distribution at time t
    p_t = estimate_empirical_distribution(
        trajectory[:t],
        bandwidth=0.01
    )

    # Gibbs distribution at equilibrium
    p_inf = gibbs_distribution(loss_fn, temperature=0.01)

    # KL divergence
    kl = compute_kl_divergence(p_t, p_inf)
    kl_history.append((t, kl))

# Plot convergence
import matplotlib.pyplot as plt
times, kls = zip(*kl_history)
plt.semilogy(times, kls)
plt.xlabel("Training steps")
plt.ylabel("D_KL(p_t || p∞)")
plt.title("Convergence to Gibbs Distribution")
plt.show()
```

### 4. validate-steady-state

Comprehensive validation that equilibrium has been reached:

```python
from fokker_planck import validate_steady_state

validation = validate_steady_state(
    trajectory=solution,
    loss_fn=loss_fn,
    gradient_fn=gradient_fn,
    temperature=0.01,
    test_set=None  # If provided, checks generalization
)

print("Steady State Validation:")
print(f"  ✓ KL divergence < 0.01: {validation['kl_converged']}")
print(f"  ✓ Gradient norm stable: {validation['grad_stable']}")
print(f"  ✓ Loss variance < threshold: {validation['var_bounded']}")
print(f"  ✓ Gibbs test statistic: {validation['gibbs_stat']:.4f}")

if validation['all_pass']:
    print("\n✅ STEADY STATE VERIFIED")
else:
    print("\n⚠️ STEADY STATE NOT REACHED")
    for check, passed in validation['details'].items():
        status = "✓" if passed else "✗"
        print(f"  {status} {check}")
```

### 5. temperature-sensitivity-analysis

Study how different temperatures affect equilibrium:

```python
from fokker_planck import analyze_temperature_sensitivity

analysis = {}
for T in [0.001, 0.01, 0.1]:
    convergence = check_gibbs_convergence(
        trajectory=solutions[T],
        temperature=T,
        loss_fn=loss_fn,
        gradient_fn=gradient_fn
    )

    analysis[T] = {
        'mean_loss': convergence['mean_final'],
        'std_loss': convergence['std_final'],
        'gibbs_ratio': convergence['gibbs_ratio'],
        'converged': convergence['converged']
    }

print("Temperature Sensitivity Analysis:")
for T, metrics in analysis.items():
    print(f"\nT = {T}:")
    print(f"  Mean loss: {metrics['mean_loss']:.5f}")
    print(f"  Std: {metrics['std_loss']:.5f}")
    print(f"  Gibbs ratio: {metrics['gibbs_ratio']:.4f}")
    print(f"  Converged: {metrics['converged']}")

# Pattern:
# Low T → Sharp equilibrium, poor generalization
# High T → Flat equilibrium, better generalization
```

### 6. compare-solvers

Compare convergence across different discretization schemes:

```python
from fokker_planck import compare_solver_convergence

solver_comparison = {}
for solver_name, (solution, tracking) in solutions.items():
    validation = validate_steady_state(
        trajectory=solution,
        loss_fn=loss_fn,
        gradient_fn=gradient_fn,
        temperature=0.01
    )

    solver_comparison[solver_name] = {
        'converged': validation['all_pass'],
        'kl_divergence': validation['kl'],
        'steps_to_convergence': tracking['convergence_step'],
        'final_loss': solution.parameters[-1]
    }

print("Solver Convergence Comparison:")
for solver, results in solver_comparison.items():
    print(f"\n{solver}:")
    print(f"  Converged: {results['converged']}")
    print(f"  KL divergence: {results['kl_divergence']:.4f}")
    print(f"  Steps to convergence: {results['steps_to_convergence']}")
    print(f"  Final loss: {results['final_loss']:.5f}")
```

## Integration with Langevin Dynamics Skill

Works hand-in-hand with langevin-dynamics-skill:

```
langevin-dynamics-skill          fokker-planck-analyzer
      (Analysis)        ←→           (Validation)
- Solves SDE                   - Verifies convergence
- Multiple solvers             - Estimates mixing time
- Instruments noise            - Measures KL divergence
- Compares discretizations     - Validates steady state
```

## Empirical Results from Minimal Test

### Logistic Regression (1D)

**Temperature T = 0.01, 1000 steps, dt = 0.001**:

```
Initial mean loss: 0.52118
Final mean loss:   0.55465
Final std dev:     0.00656

Gibbs distribution prediction (T = 0.01):
  p(final) / p(initial) = exp(-(0.55465 - 0.52118) / 0.01)
                        = exp(-33.47)
                        ≈ 3.5e-15

Interpretation: Final loss has ~3.5e-15 relative probability
But it's part of the equilibrium distribution!
This validates Fokker-Planck theory ✓
```

### Convergence Pattern

```
Step 0-100: Rapid convergence toward equilibrium
Step 100-500: Gradual approach to Gibbs
Step 500+: Small fluctuations around steady state

→ Mixing time τ_mix ≈ 100-200 steps for this problem
```

## GF(3) Triad Assignment

| Trit | Skill | Role |
|------|-------|------|
| -1 | **fokker-planck-analyzer** | Validates equilibrium |
| 0 | langevin-dynamics-skill | Analyzes dynamics |
| +1 | unworld-skill | Generates patterns |

**Conservation**: (-1) + (0) + (+1) = 0 ✓

## Validation Checklist

- [ ] **KL Divergence**: D_KL(p_t || p∞) < ε for small ε
- [ ] **Gradient Norm**: |∇L| stable and small
- [ ] **Loss Variance**: Var(L) < threshold
- [ ] **Gibbs Test**: Observed distribution matches p∞
- [ ] **Temperature Control**: Different T → different equilibria
- [ ] **Solver Consistency**: All solvers converge to same distribution

## Configuration

```yaml
# fokker-planck-analyzer.yaml
convergence:
  kl_threshold: 0.01        # Max KL divergence
  grad_norm_threshold: 1e-3 # Max gradient norm
  variance_threshold: 1e-4  # Max loss variance

estimation:
  hessian_method: numerical # or analytical
  eigenvalue_method: eig    # Matrix eigendecomposition
  bandwidth: 0.01           # For density estimation

validation:
  test_set: null            # Optional held-out set
  compute_gibbs_ratio: true # Likelihood ratio test
  plot_convergence: true    # Generate visualizations
```

## Example Workflow

```bash
# 1. Run Langevin dynamics
just langevin-solve net=network T=0.01 n_steps=1000

# 2. Check Fokker-Planck convergence
just fokker-check-convergence

# 3. Estimate mixing time
just fokker-estimate-mixing-time

# 4. Measure KL divergence
just fokker-measure-kl

# 5. Validate steady state
just fokker-validate

# 6. Temperature sensitivity
just fokker-temperature-sweep

# 7. Compare different solvers
just fokker-solver-comparison
```

## Related Skills

- `langevin-dynamics-skill` (Analysis) - Solves the SDE
- `entropy-sequencer` (Layer 5) - Optimizes sequences
- `gay-mcp` (Infrastructure) - Deterministic seeding
- `spi-parallel-verify` (Verification) - Checks GF(3)

---

**Skill Name**: fokker-planck-analyzer
**Type**: Validation / Verification
**Trit**: -1 (MINUS - critical/validating)
**Key Property**: Verifies that Langevin training has reached Gibbs equilibrium
**Status**: ✅ Production Ready
**Theory**: Fokker-Planck PDE, Gibbs distribution, mixing time estimation



## Scientific Skill Interleaving

This skill connects to the K-Dense-AI/claude-scientific-skills ecosystem:

### Scientific Computing
- **scipy** [○] via bicomodule

### Bibliography References

- `dynamical-systems`: 41 citations in bib.duckdb



## SDF Interleaving

This skill connects to **Software Design for Flexibility** (Hanson & Sussman, 2021):

### Primary Chapter: 3. Variations on an Arithmetic Theme

**Concepts**: generic arithmetic, coercion, symbolic, numeric

### GF(3) Balanced Triad

```
fokker-planck-analyzer (○) + SDF.Ch3 (○) + [balancer] (○) = 0
```

**Skill Trit**: 0 (ERGODIC - coordination)

### Secondary Chapters

- Ch4: Pattern Matching
- Ch5: Evaluation
- Ch6: Layering
- Ch1: Flexibility through Abstraction
- Ch10: Adventure Game Example

### Connection Pattern

Generic arithmetic crosses type boundaries. This skill handles heterogeneous data.
## Cat# Integration

This skill maps to **Cat# = Comod(P)** as a bicomodule in the equipment structure:

```
Trit: 1 (PLUS)
Home: Prof
Poly Op: ⊗
Kan Role: Lan_K
Color: #4ECDC4
```

### GF(3) Naturality

The skill participates in triads satisfying:
```
(-1) + (0) + (+1) ≡ 0 (mod 3)
```

This ensures compositional coherence in the Cat# equipment structure.

## Forward Reference

- unified-reafference (equilibrium across universes)

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.