Galton Flow Everywhere: Classification, Attention, RL, and More
Image Classification
Attention Mechanism
RL Policy
The Pattern
Instead of CNN โ softmax over 10 digits, we create a 2D probability landscape where probes naturally flow toward the correct digit's region.
Watch as probes drop randomly and flow through the learned geometry toward digit classes arranged in a circle!
2D Flow Field: Each image creates a unique 2D velocity field via a learned SDF network.
Class Centers: The 10 digit classes are arranged in a circle (learnable positions).
Probe Integration: Probes start at random positions and flow toward the correct digit's region using RK2 integration.
Soft Assignment: Gaussian windows around class centers convert probe positions โ class probabilities.
See the full implementation with CNN encoder, 2D SDF flow field, and training loop:
๐ examples/mnist_classifier.pypython examples/mnist_classifier.py # Creates model with: # - SimpleCNN encoder (image โ embedding) # - FlowField2D (embedding โ 2D velocity field) # - Learnable class centers in a circle # - RK2 integration for probe trajectories # - Visualization functions included!
Attention is fundamentally about routing information. Instead of computing routing weights via softmax(QK^T), let them emerge from geometric flow.
Probes flow from a uniform distribution across the sequence toward relevant key positions!
Standard Attention:
Q, K, V = projections(x) scores = Q @ K.T / โd # O(Lยฒ) dot products weights = softmax(scores) # Normalize output = weights @ V
Flow Attention:
Q, K, V = projections(x)
for each query:
field = sdf_network(query, K) # Create routing field
probes = integrate(field) # Flow to relevant keys
weights = probe_density(probes) # Where did they land?
output = weights @ V # Same as standard!
Full implementation with Q/K/V projections and probe-based routing:
๐ examples/attention_flow.pypython examples/attention_flow.py # Creates FlowAttention module: # - Standard Q, K, V projections # - AttentionFlowField (SDF for routing) # - Per-query probe integration # - Soft bucket assignment to keys # - Visualize attention patterns!
Policy networks map states to action distributions. Instead of state โ logits โ softmax, create a flow field over action space.
The agent "feels out" the action landscapeโprobes flow toward good actions, uncertainty guides exploration!
Standard Policy:
logits = policy_network(state) action_probs = softmax(logits) action = sample(action_probs)
Flow Policy:
field = sdf_network(state, action_space) probes = integrate(field) # Flow to good actions action_probs = probe_density() # Where did they land? action = sample(action_probs) # Same sampling!
Complete RL policy implementation with GridWorld environment:
๐ examples/rl_policy_flow.pypython examples/rl_policy_flow.py # Creates FlowPolicy with: # - State encoder network # - PolicyFlowField (1D action space) # - Probe integration with RK2 # - GridWorld environment included # - Training loop sketch for REINFORCE/PPO
The core insightโprobability as geometric flowโapplies anywhere you use softmax.
All three examples follow the same template. This isn't just for LLMsโit's a fundamental rethinking of categorical probability!
// Traditional approach (everywhere) logits = neural_network(input) probabilities = softmax(logits) choice = sample(probabilities) // Galton approach (universal) context = neural_network(input) field = sdf_network(context, choice_space) probes = integrate(field) probabilities = probe_density(probes) choice = sample(probabilities)
| Benefit | How It Helps |
|---|---|
| ๐ฏ Uncertainty | Probe spread = confidence (no post-hoc entropy calculations) |
| ๐ Interpretability | Visualize decision landscapes, understand why choices were made |
| โก Adaptive Compute | Confident decisions = few probes (fast), uncertain = more probes (careful) |
| ๐จ Smooth Optimization | Continuous flow = stable gradients, better training dynamics |
| ๐ Physical Intuition | Decisions as flow (not algebra), natural and interpretable |
The pattern extends to:
See docs/use-cases.md for detailed patterns and code!
Step-by-step:
The geometry handles the rest!
"For decades, we've calculated probabilities algebraically. But in the physical world, probability flows. Water finds its level. Particles settle. Energy minimizes.
Galton Lab isn't just for language models. It's a new way of thinking about uncertainty in AIโone where the geometry does the work, the physics guides the bits, and probability emerges naturally from flow."
โ Explore the code, run the examples, try it on your domain!