- Home
- Library
- Computational Quantum Field Theory
- Solving Boundary and Evolution Equations
- Conserved Quantities in Learned Dynamics
Conserved Quantities in Learned Dynamics
A learned oscillator can predict one step accurately and still spiral inward over many periods. Constraining the model to conserve energy removes that failure, but it does not fix the clock: an orbit can stay on the correct energy circle while accumulating a large phase error.
This article separates three questions: what the model learns, what its continuous equations conserve, and what the numerical integrator preserves. An actual fit to noisy oscillator derivatives makes each distinction measurable. The constrained model preserves the physical energy extremely well, yet its long-time state error is not uniformly smaller than that of the unconstrained model.
Preparation. Hamilton's equations, least squares and time integration. The automatic-differentiation article explains how gradients of more general learned energies can be evaluated.
Specify the invariant before choosing the architecture
Use dimensionless canonical variables and
The physical solution is with . The exact angular frequency is one.
Compare two bias-free linear networks:
and
The first has four fitted parameters; the second has one. Both are odd and fix the origin. Equation (3) builds in the radial energy geometry and learns only a time scale. It is a strong, correct prior for this target, not a demonstration that a network discovers an unknown energy function.
For a differentiable autonomous learned Hamiltonian , antisymmetry of gives
This conserves the learned Hamiltonian. It need not conserve a separate physical . The radial choice (3) does conserve both, because . Learning an energy and differentiating it to construct the field is the principle in Greydanus, Dzamba and Yosinski, §2, Eqs. (2)–(3). Their nonlinear network experiments differ from the exactly solved linear fits here.
For the unconstrained model,
A small symmetric part produces a small instantaneous drift, but its effect can accumulate. A small derivative residual alone does not set the duration over which the orbit remains accurate.
Fit both models to the same noisy observations
Each training replica contains 256 inputs uniform in area on the annulus . In polar coordinates this means , , with independent uniform . Derivative observations are
The two models use exactly the same observations. Sixteen independent training replicas are retained; no fit is selected by its long-time outcome. An independent common test set contains 2048 noiseless inputs from the same annulus. There is no validation-selected regularization or time step.
With and , full row rank gives
The implementation solves the generic least squares by SVD rather than explicitly forming the inverse. It records the design rank, singular values and normal-equation residuals. The constrained estimate follows from differentiating its one-dimensional quadratic loss.
For the predetermined illustrative replica 0,
Its design condition number is , and both gradient residuals are below . There is no unresolved optimization error hiding the comparison.
| Replica 0 diagnostic | Generic field | Radial Hamiltonian |
|---|---|---|
| Noisy training MSE per component | ||
| Clean test derivative RMSE per component | ||
| Exact learned one-step RMSE, |
The flexible model has the smaller training loss. The constrained model has the smaller clean derivative error in this replica, consistent with its correct stronger prior. These are actual sample outcomes, not a general ordering theorem.
Five of the sixteen generic matrices have an eigenvalue with positive real part. All sixteen fitted values are positive. Both outcomes are reported rather than enforced after fitting. Replica 0 is stable but dissipative: its largest eigenvalue real part is .
Separate learned evolution from time discretization
First evolve each fitted model exactly, using or . These trajectories isolate model error. The companion checks an independent analytic exponential formula against a general matrix-exponential routine; the largest selected discrepancy is .
Then apply implicit midpoint to the same learned field:
For , the two factors commute and , giving . Thus midpoint preserves this quadratic in exact arithmetic. It is also symplectic, . For a generic fitted , neither identity follows simply from using the same named integrator.
Quadratic-invariant preservation and symplecticity are distinct statements about the method and the underlying vector field. The Runge–Kutta coefficient condition that ensures quadratic preservation is given in Sanz-Serna, §2.1, Theorems 1–2 and Eq. (8). It does not say that every symplectic method preserves every nonlinear Hamiltonian exactly.
For the radial oscillator, the midpoint step is a rotation through
The energy is exact, but the frequency is shifted. Relative to the true oscillator, the accumulated phase error is
The first term is a learned-model error and the second an integration error. Reducing controls only the latter.
For replica 0 at , the generic midpoint map has orthogonality defect and determinant . The constrained map's orthogonality and symplectic defects are about . Halving reduces the constrained integrator-only one-step RMSE from to , as expected for a local error of order . Its exact learned-flow error remains nonzero.
Energy and phase tell different long-time stories
The frozen scan uses initial states and , times , and steps . Energy error is ; state error is the Euclidean distance to the physical trajectory. Phase uses the continuously unwrapped , subtracting its initial value and the true phase .
For replica 0, initial state and :
| Evolution | Relative energy change | Phase error | State error |
|---|---|---|---|
| Generic, midpoint | |||
| Radial model, exact learned ODE | rounding level | ||
| Radial model, midpoint | |||
| Radial model, midpoint | rounding level |
The generic orbit has lost about of its energy. Nevertheless its endpoint state error is smaller than the radial model's error: the latter is on the correct circle but substantially out of phase. Energy conservation is a useful physical constraint, not a complete accuracy certificate.
Across all sixteen fits at , , the generic energy changes range from approximately to . The constrained energy changes stay below in magnitude, while their phase errors range from to radians. The spread comes from independent noisy fits; it is not a confidence interval for a different physical system.
Both learned models use the same derivative observations. Replica 0 was fixed before outcomes; the final-energy comparison retains all sixteen fits. The exact learned radial flow separates frequency error from midpoint's additional phase error. All plotted quantities come from the retained scan, with no selection by long-time accuracy.
The pure kernel learned_oscillator.py and driver oscillator_checks.py retain fit diagnostics, one-step tests and both long-time trajectories in oscillator-learning-results.json, under examples/computational-qft/machine-learning/. Training, derivative testing and integration refinement use distinct checks.
What other symmetries would guarantee
For a canonical generator , its derivative along a learned Hamiltonian flow is
An architecture invariant under the canonical transformation generated by makes this bracket vanish in continuous time. Merely writing a Hamiltonian ensures its own autonomous energy conservation, not every charge of the target system. A discretization must then be assessed for the particular invariant: the quadratic midpoint argument used here does not automatically extend to nonquadratic charges or to arbitrary time-stepping rules.
For constrained fields, the analogous question includes preservation of the constraint surface and the correct physical degrees of freedom. Gauge equivariance of a static map and Hamiltonian conservation of a time evolution are related design principles, but they are different mathematical requirements and need different tests.
Summary
Build the desired conservation statement into the continuous model, identify exactly which quantity it protects, and test the discrete evolution independently. The trained oscillator demonstrates a large improvement in energy behavior without eliminating model-frequency error or integration phase error. Derivative accuracy, energy, phase and long-time state accuracy are complementary diagnostics.
Exercises
1. Compare Euler with midpoint
For , derive the energy after forward-Euler steps. Show that midpoint instead preserves the norm but advances with the frequency (10). Explain why neither result establishes the correct physical frequency when is fitted.
Solution
Euler gives . Since and ,
Thus a continuously conserved quadratic energy grows under Euler for . At fixed final time , the growth factor is as ; long time and small step cannot be interchanged without controlling their product.
For midpoint, set . Using ,
This is orthogonal and yields (10). Its exact norm does not determine its angle. Even only recovers frequency ; the physical frequency is one, so fitting error remains unless .
2. Energy conservation is not every Noether charge
Take . Compute and for , and identify the symmetry that fails when .
Solution
Hamilton's equations are
Because is autonomous, . However,
The canonical transformation generated by is rotation in the plane. The term is not invariant under those rotations, so the corresponding is not conserved. Time-translation symmetry still conserves the full . This also shows why an arbitrary learned Hamiltonian should not be described as preserving a specified target energy unless the additional bracket condition is checked.
References
- S. Greydanus, M. Dzamba and J. Yosinski, “Hamiltonian Neural Networks,” arXiv:1906.01563v3. See §2, Eqs. (2)–(3), for Hamiltonian-gradient modeling and §§3.1–3.2 for learned dynamics. The linear training problem here is separately specified and solved.
- J. M. Sanz-Serna, “Symplectic Runge–Kutta schemes for adjoint equations, automatic differentiation, optimal control and more,” arXiv:1503.04021v2. See §2.1, Theorems 1–2 and Eq. (8), for quadratic invariants and symplecticity. The Euler and Cayley identities above are derived directly.
Further reading
- Adjoints for field evolution differentiates the actual discrete update, including endpoints and running losses.
- Gauge-equivariant networks distinguishes symmetry of a field map from dynamical conservation.
Scrollable formula. Use Left and Right arrow keys to reveal hidden content.
Scrollable table. Use Left and Right arrow keys to reveal hidden columns.
Scrollable figure. Use Left and Right arrow keys to reveal hidden content.