Educational NumPy API
The educational module mirrors the PyTorch API with small NumPy functions.
Use it when you want to see the algebra without autograd, modules, batching, or
GPU concerns.
Why This Module Exists
The PyTorch package is the production path. The NumPy helpers are for hand-sized derivations:
| Helper | Mathematical object |
|---|---|
np_picard |
Damped fixed-point iteration |
np_finite_difference_jacobian |
Central-difference Jacobian |
np_exact_tanh_affine_jacobian |
Closed-form Jacobian for tanh(Wz + s) |
np_power_iteration |
Dominant mode estimate for a materialized matrix |
np_implicit_gradient |
Explicit adjoint solve for a small DEQ |
Minimal Fixed Point
For
Picard iteration computes
import numpy as np
from silva_networks import np_picard
W = np.array([[0.2, 0.1], [-0.1, 0.25]])
s = np.array([0.5, -0.2])
trace = np_picard(lambda z: np.tanh(W @ z + s), np.zeros(2), alpha=0.8)
The result stores the final z and the residual curve.
Exact Jacobian for tanh(Wz + s)
Let
Because
the state Jacobian is
from silva_networks import np_exact_tanh_affine_jacobian
J = np_exact_tanh_affine_jacobian(W, trace.z, s)
Small Implicit Gradient
At a solved equilibrium, the total derivative obeys
For a loss gradient \(g=\partial \mathcal L/\partial z^\star\), solve
then compute
from silva_networks import np_implicit_gradient
grad_theta = np_implicit_gradient(J, grad_z, df_dtheta)
This is the explicit small-matrix version of the adjoint system used by the PyTorch diagnostics.
The corresponding equilibrium, implicit-function, and numerical-method sources are listed in Paper and References. Use Mathematical Foundations for the full derivations and tensor notation.
NumpySolverTrace
dataclass
Transparent NumPy trace for hand-sized fixed-point examples.
Source code in src/silva_networks/educational.py
np_exact_tanh_affine_jacobian
Jacobian of f(z) = tanh(W z + s).
np_finite_difference_jacobian
Central-difference Jacobian with columns J[:, i] = d f / d z_i.
Source code in src/silva_networks/educational.py
np_implicit_gradient
Compute grad_theta L = lambda^T df/dtheta from the DEQ adjoint solve.
Source code in src/silva_networks/educational.py
np_picard
Damped Picard iteration written as visible NumPy linear algebra.
Source code in src/silva_networks/educational.py
np_power_iteration
Dominant singular/eigenmode magnitude estimate for a materialized matrix.
Source code in src/silva_networks/educational.py
Where to Go Next
| Question | Page |
|---|---|
| Where is the underlying fixed-point mathematics derived? | Mathematical Foundations |
| Where is a scalar equilibrium checked exactly? | Scalar Equilibrium Example |
| Which tensor solvers implement the same ideas? | Solvers API |