---
title: Hamiltonian Generative Networks
url: https://www.emergentmind.com/topics/hamiltonian-generative-networks-hgn
type: topic
---

# Hamiltonian Generative Networks

Hamiltonian Generative Networks (HGNs) are deep generative models that learn an abstract phase space and a neural Hamiltonian directly from high-dimensional observations such as images, thereby coupling representation learning with continuous-time latent dynamics. Introduced as “the first approach capable of consistently learning Hamiltonian dynamics from high-dimensional observations (such as images) without restrictive domain assumptions,” HGN combines an inference network, a Hamiltonian network, and a decoder in a temporal variational framework, and supports sampling, forward and backward rollouts, and changes in rollout speed through the learned latent dynamics [1909.13789]. Subsequent work has centered on whether the learned latent variables are genuinely Hamiltonian, how rollout stability and interpretability can be improved, and how continuous-time Hamiltonian video models behave when evaluated outside their training timestep regime [2111.05986][2607.07763].

## 1. Origins and formal motivation

HGN is grounded in the Hamiltonian formalism, which models continuous-time evolution in phase space using canonical coordinates \(q\) and \(p\). In the original formulation, the latent state is \(s=(q,p)\in\mathbb{R}^{2n}\), and the dynamics are defined by Hamilton’s equations,
\[
\frac{dq}{dt} = \frac{\partial \mathcal{H}}{\partial p}, \qquad
\frac{dp}{dt} = -\frac{\partial \mathcal{H}}{\partial q}.
\]
This formalism brings time reversibility, smooth interpolation in time, and conserved quantities into a deep generative model [1909.13789].

The motivating premise in HGN is that high-dimensional observations lie on a low-dimensional manifold and that observed trajectories correspond to flow along that manifold under Hamiltonian dynamics. The paper describes this as the “Hamiltonian manifold hypothesis.” In contrast to earlier Hamiltonian Neural Networks, which required access to low-dimensional state variables and their derivatives, HGN aims to infer both the abstract phase space and the Hamiltonian from pixels, with no need for ground-truth state or its derivatives [1909.13789].

This design places HGN at the intersection of physics-inspired representation learning, video prediction, and generative sequence modeling. A central claim of the original work is not that the latent coordinates must coincide with a known physical coordinate system, but that the learned phase space can be abstract while still supporting structured, reversible, and energy-conserving latent evolution. This suggests that Hamiltonian structure functions as an inductive bias for dynamical consistency rather than solely as an explicit system-identification mechanism.

## 2. Core architecture and objective

The original HGN consists of three main components: an inference network, a Hamiltonian network, and a decoder [1909.13789]. The inference network takes an image sequence \((x_0,\ldots,x_T)\) and infers a posterior over the initial abstract state,
\[
q_\phi(s_0 \mid x_0,\ldots,x_T),
\]
typically parameterized as a diagonal Gaussian. The latent initial state is \(s_0=(q_0,p_0)\).

The Hamiltonian network parameterizes a scalar Hamiltonian \(\mathcal{H}_\gamma(q,p)\). Given the current abstract state, the model computes latent updates through Hamilton’s equations and produces a latent rollout using a symplectic leapfrog integrator. The decoder maps only the abstract position \(q_t\) back to an observation \(\hat{x}_t=d_\theta(q_t)\). The stated reason is that momentum does not directly influence instantaneous appearance in many physical systems [1909.13789].

Training uses a temporal variational autoencoder objective,
\[
\mathcal{L} = \frac{1}{T+1} \sum_{t=0}^T \mathbb{E}_{q_\phi(s_0|x_{0:T})} [\log p_\theta (x_t|q_t)] - \mathrm{KL}(q_\phi(s_0|\cdot) \Vert p(s_0)),
\]
with a unit Gaussian prior over \(s_0\). In the more explicit notation given in the same source,
\[
\mathcal{L}(\phi, \psi, \gamma, \theta; x_0, ..., x_T) =
\frac{1}{T+1} \sum_{t=0}^{T} \mathbb{E}_{q_\phi(s_0 | x_{0:T})}
[ \log p_{\psi, \gamma, \theta}(x_t|q_t) ]
- \mathrm{KL}( q_\phi(s_0) || p(s_0) ).
\]
The leapfrog scheme is used for stability, volume preservation, and accurate energy conservation [1909.13789].

Operationally, HGN is trained end-to-end: the encoder infers an initial latent phase-space state from observed frames, the Hamiltonian network induces a latent trajectory, and the decoder reconstructs the corresponding image sequence. This is a generative model of trajectories rather than merely a one-step predictor.

## 3. Rollouts, reversibility, and density modeling

A defining property of HGN is that the latent dynamics are reversible. Because Hamiltonian evolution is invertible when integrated with an appropriate scheme, the model can perform rollouts both forward and backward in time. In practice, the original paper states that backward rollout is achieved by negating the integration time-step \(dt\) [1909.13789].

The same continuous-time structure enables smooth interpolation and speed control. Once trained, HGN can “speed up or slow down the learned dynamics” by changing the integration step size, and it can generate plausible trajectories from latent samples. The paper reports faithful reversible rollouts on unseen test trajectories and emphasizes that symplectic integration preserves the learned Hamiltonian over long rollouts [1909.13789].

The original work also introduced Neural Hamiltonian Flow (NHF), obtained by a simple architectural modification that turns HGN into a normalizing flow model. The key observation is that Hamiltonian flows are invertible and volume-preserving. In NHF, the flow is implemented through learned Hamiltonian updates,
\[
s_{t+1} = \mathcal{H}_i^{dt}(s_t),
\]
and the determinant of the Jacobian is \(1\) to \(O(dt^2)\), which removes the need for explicit Jacobian determinant evaluation in density computation. The resulting likelihood expression is written as
\[
\ln\, p(s_T) = \ln\, \pi(\mathcal{H}_1^{-dt} \circ ... \circ \mathcal{H}_T^{-dt}(s_T)) + O(dt^2).
\]
For density modeling over observed variables with latent momentum, the paper gives the variational lower bound
\[
\mathrm{ELBO}(q_T) = \mathbb{E}_{f_\psi(p_T|q_T)}[\ln \pi(\mathcal{H}_1^{-dt} \circ ... \circ \mathcal{H}_T^{-dt}(q_T, p_T)) - \ln f_\psi(p_T|q_T) ].
\]
Within the HGN literature, NHF represents a distinct use of Hamiltonian structure: not sequence reconstruction from images, but expressive density estimation with reversible, volume-preserving flows [1909.13789].

## 4. Evaluation methodology and HGN++

A major issue identified after the original HGN is that image reconstruction quality does not reliably measure whether the latent dynamics are Hamiltonian. The paper “SyMetric: Measuring the Quality of Learnt Hamiltonian Dynamics Inferred from Vision” argues that image-space metrics such as MSE correlate poorly with physical correctness, because a model can reconstruct frames well while learning incorrect or trivial latent dynamics [2111.05986].

To address this, the paper introduces three related measures: \(R^2\) for variance explained, \(Sym\) for symplecticity error, and SyMetric as a binary indicator of Hamiltonian fidelity. The symplecticity condition is based on the Jacobian \(J=\frac{\partial F}{\partial S}\) of a learned map from latent state to ground-truth phase space, with the canonical symplectic form
\[
A = \begin{bmatrix} 0 & I \\ -I & 0 \end{bmatrix},
\]
and the condition
\[
J^T A J = A.
\]
The paper defines
\[
Sym = \text{MSE}(c \hat{A} \hat{A}^T,\, I),
\]
where \(\hat{A}=J A_m J^T\), and then combines this with \(R^2\) through
\[
\text{SyMetric} =
\begin{cases}
1 & \text{if } R^2 > \alpha \text{ and } Sym < \epsilon\\
0 & \text{otherwise}
\end{cases}
\]
with empirically chosen thresholds \(\alpha=0.9\) and \(\epsilon=0.05\) [2111.05986].

Using these measures, the authors performed an architecture and hyperparameter search leading to HGN++. The reported modifications include a 1D vector phase space instead of a 3D tensor latent, direct inference of latent positions and momenta, encoder and decoder with leaky ReLU activations and \(3\times 3\) kernels, a Hamiltonian network using Swish activations and an MLP architecture, a shift from GECO-based training to a \(\beta\)-VAE objective, longer rollout horizons of 60 steps, prediction-based training instead of reconstruction, training for both forward and backward rollouts, and leapfrog integration with tuned step size and layers for stability [2111.05986].

Empirically, HGN++ is reported to be “stable for significantly longer rollouts on a diverse range of 13 datasets,” and on a subset of those datasets it produces “rollouts of essentially infinite length both forward and backwards in time with no degradation in quality.” The same work states that HGN++ can discover an interpretable phase space with physically meaningful latents on some datasets and achieves near-perfect recovery of Hamiltonian dynamics on several benchmark tasks [2111.05986]. A common misconception in this area is therefore that good reconstruction alone demonstrates successful Hamiltonian learning; the evaluation literature explicitly rejects that equivalence.

## 5. Temporal generalization beyond conservative dynamics

Standard HGN is inherently conservative, which is advantageous for reversible physical systems but restrictive in the presence of friction, external forcing, or dissipation. A later study on temporal generalization in Hamiltonian video dynamics models observes that HGNs learn a continuous-time energy function over latent phase space and are, in principle, independent of observation frame rate, allowing evaluation at arbitrary step sizes. However, the same study reports that “in practice, their temporal generalization breaks down in non-conservative settings” [2607.07763].

To model externally forced and dissipative environments, that work adopts a port-Hamiltonian generalization,
\[
\dot{q} = \frac{\partial H}{\partial p}, \qquad
\dot{p} = -\frac{\partial H}{\partial q} - \gamma \frac{\partial H}{\partial p} + G(a),
\]
where \(\gamma\) is a learned damping coefficient and \(G(a)\) is a learned mapping from action to phase space. The Hamiltonian is written as
\[
H(q,p)=T(p)+V(q),
\]
with \(T\) and \(V\) learned via neural networks [2607.07763].

The analysis identifies two failure modes when evaluation uses timesteps outside the training regime. The first is latent magnitude growth driven by an unconstrained action-force map, producing amplitude blowup and visible artifacts. The second is global truncation error accumulation, causing phase drift even when the rollout remains bounded. The paper recommends two targeted fixes: spectral normalization of the action-force map \(G(a)\), capping its norm at \(1\), and inference-time integration substepping, in which each coarse evaluation step is subdivided into \(N\) leapfrog substeps of size \(\Delta t/N\) while preserving the total action impulse [2607.07763].

This line of work clarifies an important boundary condition for HGN-style models. Continuous-time Hamiltonian structure does enable interpolation and extrapolation in timestep, but it does not, by itself, guarantee robust temporal generalization in non-conservative environments. The failure is not presented as a refutation of HGN; rather, it is a statement that conservative Hamiltonian inductive bias must be augmented when the target dynamics are externally forced or dissipative.

## 6. Related Hamiltonian generative models and terminological boundaries

HGN has influenced a broader family of Hamiltonian generative models, but these models address different problems and should not be conflated. In “Hamiltonian GAN,” the temporal component of a GAN-based video generator is replaced with a Hamiltonian Neural Network motion model, and a learned configuration space map \(f\) is introduced so that the configuration space need not be specified a priori. The model is trained with a cyclic-coordinate loss,
\[
\mathcal{L}_\mathrm{cyc} = \frac{1}{N} \sum_i \lambda\, |\dot{p}_i|,
\]
which is intended to encourage a minimal representation of the configuration space and improve interpretability [2308.11216]. This differs from HGN’s temporal VAE formulation even though both use Hamiltonian latent dynamics.

In “Continuous Methods: Hamiltonian Domain Translation,” Hamiltonian structure is used to reformulate Cycle-GAN-style unsupervised domain translation as a continuous-time invertible flow in a shared latent space. The method learns an encoder and decoder for both domains and a Hamiltonian latent flow
\[
\frac{dx}{dt}=f_H(x)=
\begin{bmatrix}
-\frac{\partial H_\theta}{\partial q}\\
\frac{\partial H_\theta}{\partial p}
\end{bmatrix},
\]
with reverse mapping obtained by integrating backward in time. The paper emphasizes invertibility by construction, continuity, and the removal of explicit cycle-consistency loss [2207.03843]. This is closely related in spirit to HGN’s use of Hamiltonian latent evolution, but the task is domain translation rather than sequential world modeling.

A different contrast is provided by Symplectic Generative Networks. That work defines a latent-to-data mapping as the solution \(\Phi_T\) of Hamilton’s equations over a symplectic latent space and proves invertibility and volume preservation, with exact likelihood evaluation and no Jacobian determinant term. It explicitly distinguishes itself from HGNs by stating that HGNs focus on learning time-evolution of physical systems and “do not use a symplectic flow as a latent-to-data generative mapping” [2505.22527]. The distinction is structural: HGN is centered on latent trajectory generation from observations, whereas SGN is formulated as an invertible generative model.

Finally, the acronym “HGN” is not unique to Hamiltonian Generative Networks. In “Rapid training of Hamiltonian graph networks without gradient descent,” HGN denotes Hamiltonian Graph Networks rather than Hamiltonian Generative Networks, and the focus is permutation-invariant modeling of N-body mass-spring systems with random feature-based parameter construction and least-squares fitting [2506.06558]. This terminological overlap has created ambiguity in parts of the literature. A plausible implication is that references to “HGN” require contextual disambiguation, especially in recent work spanning graph networks, video models, and invertible generative systems.

Source: https://www.emergentmind.com/topics/hamiltonian-generative-networks-hgn