Derivations to Code
The package is organized so every major equation has a nearby implementation object. This page shows the main derivation path and the matching code. The fixed-point and implicit-gradient lineage is indexed at [3] and [4], with solver sources at [10] through [13].
For the full traceability manual, including solver algorithms, SILVA families, tensor contracts, Jacobian estimators, and reporting best practices, see Implementation Derivations.
Fixed-Point Residual
Start with a transition map \(f_\theta\). The equilibrium is the state where applying the map changes nothing:
Move all terms to one side:
Solving the layer means finding a state whose residual norm is small:
from silva_networks import SolverConfig, fixed_point
result = fixed_point(f, z0, SolverConfig(solver="picard", max_iter=25, alpha=0.5))
z_star = result.z
residual = result.residual
Damped Solver Step
The Picard step with damping is
Subtract \(z_k\) to see the residual direction:
Thus alpha controls how far the iterate moves along the residual direction.
SILVA Interaction Field
The generic SILVA transition decomposes into stimulus, optional learned self interaction, local interaction, and global interaction:
The package implementation follows the same sequence:
s = self.stimulus(x)
y = self.activation(z)
self_update = self.self_term(y)
local = self.local(y, edge_index=edge_index, edge_attr=edge_attr)
global_context = self.global_term(y, batch=batch)
z_next = self.norm(self.output_activation(s + self_update + local + global_context))
Local Message Passing
For GraphLocal, each source state \(z_j\) is first projected:
For destination \(i\), incoming messages are averaged:
Code:
src, dst = edge_index
messages = proj(z)
out = torch.zeros_like(messages)
out.index_add_(0, dst, messages[src])
Graph Attention Local Term
For GraphAttentionLocal, first project each state into attention-head space:
For an edge \(j\to i\), compute an unnormalized score:
Normalize only over incoming edges to the same destination:
Then aggregate:
Edge attributes add one more score term,
which is the path used by bond-aware molecular SILVA layers.
Global Mean Field
For each graph \(g\), compute the mean state:
Broadcast a learned projection:
The gated SILVA-style variant computes
Code:
from silva_networks import GatedMeanFieldGlobal
global_term = GatedMeanFieldGlobal(dim=64)
g_update = global_term(z, batch=batch)
Jacobian Diagnostics
At an equilibrium, local behavior is controlled by
For small states, materialize the full Jacobian:
from silva_networks import full_jacobian
J = full_jacobian(lambda z: layer.f(z, x, edge_index=edge_index), z_star)
For larger states, compute products:
The same interface supports spectral-radius and Lyapunov-style diagnostics:
from silva_networks import damped_spectral_radius, solve_with_energy
rho = damped_spectral_radius(f, z_star, alpha=0.5)
Custom Branch Rule
A custom branch is mathematically valid for the package when it maps the current state and optional context back to the state shape:
import torch
class MyGlobal(torch.nn.Module):
def __init__(self, dim):
super().__init__()
self.proj = torch.nn.Linear(dim, dim)
def forward(self, z, batch=None):
context = z.mean(dim=0, keepdim=True)
return self.proj(context).expand_as(z)
The solver, gradients, diagnostics, and device behavior stay the same.
Verify the Translation
For every equation-to-code step, check four invariants:
- each active branch returns the declared state shape;
- the composed transition preserves shape, dtype, and device;
- the solver residual is computed from the same transition used in training;
- gradients reach every trainable branch that contributes to the loss.
The complete source lineage is organized in Implementation Derivations, with primary method links in Paper and References.
Where to Go Next
| Question | Page |
|---|---|
| Where are the complete implementation derivations? | Implementation Derivations |
| What fixed-point assumptions support the translation? | Fixed Points |
| Can I execute the derivation cell by cell? | Equation-to-Code Walkthrough |