Learning Trajectories of Hamiltonian Systems with Neural Networks

Katsiaryna Haitsiukevich, Alexander Ilin

Abstract

Modeling conservative physical systems—those that obey fundamental laws like the conservation of energy—is a critical challenge in scientific machine learning. While Hamiltonian Neural Networks (HNNs) have emerged as a powerful tool for embedding these physical priors into neural architectures, they typically require explicit time derivatives during training, making them sensitive to noise and irregular sampling. This paper introduces Deep Hidden Hamiltonian (DHH), a framework that treats system trajectories as learnable functions of time. By optimizing a solution network alongside a Hamiltonian network, DHH bypasses the need for finite difference approximations. Our results demonstrate that DHH provides superior robustness in noisy and low-frequency data regimes across various classical systems, including the pendulum and N-body problems.

Introduction

In the study of physical systems, conservation laws for energy, mass, and momentum provide the structural backbone for accurate modeling. Traditional deep learning approaches often struggle to maintain these constraints over long-term simulations, leading to "unphysical" behaviors such as energy drift. Hamiltonian Neural Networks (HNNs) were developed to address this by learning a scalar Hamiltonian function—representing the total energy—and using Hamilton’s equations to dictate the system's dynamics.

Despite their theoretical elegance, standard HNNs face significant practical hurdles. They generally require the time derivatives of the system's state (the rate of change for position and momentum) as training targets. In real-world scenarios, these derivatives are rarely observed directly; instead, researchers rely on snapshots of the state at discrete intervals. While finite difference methods can estimate these derivatives, they are notoriously sensitive to observational noise and require high-frequency sampling to remain accurate. When data is sparse or noisy, the performance of standard HNNs degrades rapidly.

The Deep Hidden Hamiltonian (DHH) Framework

To overcome the limitations of derivative-dependent training, the Deep Hidden Hamiltonian (DHH) method proposes a dual-network architecture that models the trajectory and the underlying physics simultaneously.

Architecture

The DHH framework consists of two primary components:

  1. The Solution Network ($s(t)$): This network maps time $t$ to the predicted state $(q, p)$, where $q$ represents position and $p$ represents momentum. It serves as a continuous, differentiable representation of the system's trajectory.
  2. The Hamiltonian Network ($H(q, p)$): This network learns to approximate the system's total energy function.

Optimization and Loss Functions

The synergy between these networks is enforced through a multi-component loss function that ensures the learned trajectory is both data-consistent and physically plausible:

  • Fit Loss: This term ensures the solution network $s(t)$ accurately tracks the observed data points.
  • ODE Loss: This is the core of the DHH method. Using automatic differentiation, the model calculates the exact time derivative of the solution network, $\dot{s}(t)$. It then enforces Hamilton’s equations: $\dot{q} = \frac{\partial H}{\partial p}$ and $\dot{p} = -\frac{\partial H}{\partial q}$. Because the derivative is computed through the network itself rather than through finite differences of noisy data, the model remains stable even under adverse conditions.
  • Energy Conservation Loss: An additional constraint is applied to ensure that the Hamiltonian $H$ remains constant along the trajectory predicted by $s(t)$, further reinforcing the conservative nature of the system.

Experimental Evaluation

The authors evaluated DHH against standard HNNs and Neural Ordinary Differential Equations (Neural ODEs) across four classic physical systems: the Mass-Spring oscillator, the Pendulum, and 2-Body/3-Body gravitational systems. The models were tested under three distinct data conditions:

  1. Clean, regularly-sampled observations: The baseline scenario.
  2. Noisy observations: Data corrupted with Gaussian noise to simulate sensor error.
  3. Irregularly-sampled observations: Snapshots taken at random intervals to simulate sparse data collection.

Key Insights and Results

Robustness as a Physics-Informed Denoiser

A primary advantage of DHH is its ability to act as a denoiser. Because the solution network is constrained by the ODE loss (the laws of physics), it cannot simply overfit to noise. Instead, it finds the "smoothest" trajectory that satisfies both the noisy observations and the Hamiltonian dynamics. In experiments, DHH maintained stable error rates as noise levels increased, whereas baseline models saw exponential growth in prediction error.

Handling Sparse and Missing Data

Unlike traditional numerical integrators that require small, fixed time steps, DHH is agnostic to sampling rates. It can learn from snapshots taken far apart in time because it treats the trajectory as a continuous function. Furthermore, the model demonstrated an ability to reconstruct "hidden" variables. For instance, in a mass-spring system where only noisy position ($q$) was measured, DHH successfully inferred the momentum ($p$) by leveraging the physical constraints of the Hamiltonian framework.

Long-Term Stability

Once the Hamiltonian network $H$ is trained, it can be used with standard numerical integrators (like Runge-Kutta) for long-term forecasting. In the complex 2-body and 3-body problems, DHH produced stable orbits that preserved energy over long durations. In contrast, non-Hamiltonian baselines like standard Neural ODEs often resulted in systems that either spiraled inward or flew apart due to accumulated energy errors.

Conclusion and Future Work

Deep Hidden Hamiltonian (DHH) represents a significant step forward in making physics-informed neural networks practical for real-world data. By eliminating the reliance on explicit time derivatives, DHH provides a robust framework for learning from noisy and irregularly sampled trajectories.

However, some limitations remain. The current implementation assumes the system is described in canonical coordinates, which may not always be available in complex robotics or fluid dynamics. Additionally, the model is strictly designed for conservative systems and does not yet account for dissipative forces like friction. Future research may focus on extending DHH to non-canonical systems and incorporating non-conservative terms to model a wider array of physical phenomena.

Summary updated

BibTeX
@inproceedings{haitsiukevich2022learning,
  author = {Katsiaryna Haitsiukevich and Alexander Ilin},
  title = {{Learning Trajectories of Hamiltonian Systems with Neural Networks}},
  booktitle = {ICANN},
  year = {2022},
  doi = {10.1007/978-3-031-15919-0\_47},
}
Figure