Lagrangian and Hamiltonian Neural Networks With a Dissipative System

1, 2University of Richmond

Abstract

We investigate the applicability of Lagrangian and Hamiltonian Neural Network models to a dissipative system that has explicit time dependence in its Lagrangian, Hamiltonian, and total energy. To do so we consider these neural network models for simulated systems of a harmonic one-dimensional, one-component oscillator with damping, as well as without damping for comparison. We find that both the Lagrangian and Hamiltonian approaches are able to predict the empirical physical behavior of the damped oscillator systems and to effectively "learn" to varying degrees the underlying Lagrangians and Hamiltonians, as has previously been shown to be the case with undamped oscillator systems. These investigations elucidate important properties of Lagrangian and Hamiltonian mechanics, including properties that are not manifest when considering systems without explicit time dependence.

What happens when energy is no longer conserved?

Lagrangian and Hamiltonian Neural Networks are designed to learn hidden mechanical structure from observed trajectories. Foundational demonstrations largely focus on conservative systems, where the Lagrangian and Hamiltonian have no explicit time dependence and the Hamiltonian is often identified with a conserved total energy.

Dissipation changes that picture. Friction, drag, and other interactions can make the Lagrangian and Hamiltonian explicitly time-dependent. In the damped oscillator studied here, the Hamiltonian is not generally equal to the total energy and is not conserved. This gives us a simple but revealing question: can LNNs and HNNs still learn the dynamics, and what physical quantity do they learn when the usual conservative assumptions break?

Damped-oscillator example illustrating the open problem of dissipative systems.

Figure 1. Dissipation introduces explicit time dependence and separates the Hamiltonian from conserved total energy.

Learning the mechanics, not just the motion

A standard neural network can directly map a state to its time derivative. LNNs and HNNs instead predict a scalar mechanical function first, then use in-network derivatives of that learned function to reproduce the observed dynamics.

The Lagrangian model learns a function of position, velocity, and, when needed, time. The Hamiltonian model learns a function of position, momentum, and time. Their gradients are then constrained by the Euler-Lagrange or Hamilton equations.

This lets us ask a more interesting question than whether the trajectory is accurate: what hidden physical function did the network actually recover?

LNN and HNN architecture schematic.

Figure 2. LNN and HNN architecture schematic.

What did we find?

Dissipation is still learnable.

Both LNNs and HNNs can be extended to the damped oscillator when time is provided as an input. The models recover the observed dynamics even though the system is no longer energy-conserving.

Time changes what the network learns.

Removing time does not always destroy predictive performance. Under special structural relationships, the networks can still reproduce the dynamics, but the learned scalar may no longer be the actual Lagrangian or Hamiltonian.

A surprising "Energy NN" emerges.

In the damped HNN, replacing generalized momentum with observable linear momentum and omitting time produces a convergent model that learns the total non-dissipative kinetic plus potential energy instead of the Hamiltonian.

The LNN learns damped dynamics

The oscillation decays, but the learned dynamics stay on track. The Lagrangian NN successfully predicts the damped oscillator dynamics in both the noise-free and noisy experiments.

With time supplied as an input, the model can recover an actual Lagrangian for the dissipative system. We also test a second strategy that removes time from the network and exploits the special relationship between the explicit time derivative of the Lagrangian and the Lagrangian itself.

That second model still predicts the dynamics, but what it learns is a modified Lagrangian function rather than the actual time-dependent Lagrangian. The result separates two questions that are easy to conflate: did the network predict the motion correctly, and did it recover the physical function we intended it to learn?

Damped Oscillator – Lagrangian NN

With Time Parameter
Without Time Parameter

No Noise

Actual and LNN-predicted acceleration over time with a time parameter and no noise.
Actual and LNN-predicted Lagrangian over time with a time parameter and no noise.
Actual and LNN-predicted acceleration over time without a time parameter and with no noise.
Actual and LNN-predicted modified Lagrangian over time without a time parameter and with no noise.

With Noise

Actual and LNN-predicted acceleration over time with a time parameter and simulated noise.
Actual and LNN-predicted Lagrangian over time with a time parameter and simulated noise.
Actual and LNN-predicted acceleration over time without a time parameter and with simulated noise.
Actual and LNN-predicted modified Lagrangian over time without a time parameter and with simulated noise.
Figure 3. Actual and predicted acceleration q̈D(t) versus time (first, third column) and actual and predicted Lagrangian LD versus time (second, fourth column) for the damped oscillator, with no noise (upper) and full simulated noise (lower) in the observed data.

When a Hamiltonian NN becomes an Energy NN

The most surprising result appears when we remove time. For the damped oscillator, the generalized momentum required by Hamiltonian mechanics is not the same as the directly observable linear momentum.

Using generalized momentum together with time, the HNN converges and recovers the damped dynamics and Hamiltonian. Removing time while keeping generalized momentum does not converge. But replacing generalized momentum with linear momentum allows the network to converge again.

The resulting model does not learn the Hamiltonian. Instead, it learns the total non-dissipative kinetic plus potential energy while still reproducing the observed dynamics. The same differentiation machinery used by an HNN has effectively become an Energy NN without explicitly designing one.

Damped Oscillator – Hamiltonian NN

No Noise

Actual and HNN-predicted damped-oscillator velocity with no noise.
Actual and HNN-predicted linear momentum derivative versus velocity with no noise.
Actual and HNN-predicted damped-oscillator Hamiltonian with no noise.

With Noise

Actual and HNN-predicted damped-oscillator velocity with simulated noise.
Actual and HNN-predicted linear momentum derivative versus velocity with simulated noise.
Actual and HNN-predicted damped-oscillator Hamiltonian with simulated noise.
Figure 4. Actual and predicted velocity (left), linear momentum derivative versus velocity (middle), and Hamiltonian (right) for the damped oscillator in the Hamiltonian NN, with no noise (upper) and full simulated noise (lower) in the observed data.

Damped Oscillator – Energy NN

No Noise

Actual and Energy-NN-predicted damped-oscillator velocity with no noise.
Actual and Energy-NN-predicted linear momentum derivative versus velocity with no noise.
Actual and predicted non-dissipative energy with no noise.

With Noise

Actual and Energy-NN-predicted damped-oscillator velocity with simulated noise.
Actual and Energy-NN-predicted linear momentum derivative versus velocity with simulated noise.
Actual and predicted non-dissipative energy with simulated noise.
Figure 5. Actual and predicted velocity (left), linear momentum derivative versus velocity (middle), and non-dissipative energy (right) for the damped oscillator in the Energy NN, with no noise (upper) and full simulated noise (lower) in the observed data.

No Noise

Default and equivalent alternative Lagrangians for the undamped no-noise case.
Default and equivalent alternative Lagrangians for the damped no-noise case.

With Noise

Default and equivalent alternative Lagrangians for the undamped noisy case.
Default and equivalent alternative Lagrangians for the damped noisy case.
Figure 6. Calculated default Lagrangians and equivalent alternatives L' for the undamped (left) and damped (right) oscillators, with no noise (upper) and full simulated noise (lower).

A different Lagrangian can still be the right Lagrangian

The learned function does not need to look like the textbook expression. Some LNN predictions initially appear to disagree with the analytical Lagrangian even though the predicted dynamics are correct.

This exposes a fundamental property of Lagrangian mechanics: multiple Lagrangians can generate the same equations of motion. In particular, transformations of the form

\[ L' = A'\!\left(L + \frac{dF}{dt}\right) + C \]

leave the physical dynamics unchanged under the conditions discussed in the paper. Comparing the learned functions with these equivalent forms shows that the LNN can recover a correct Lagrangian even when it is not numerically identical to the expression we started with.

Results at a glance

Across the undamped and damped experiments, the models consistently recover the observed dynamics. What changes across formulations is the interpretation of the learned scalar function. Time-aware damped models recover the intended Lagrangian or Hamiltonian, while carefully chosen time-free formulations can preserve the dynamics by learning a related physical quantity instead.

Summary table of LNN and HNN results across undamped and damped cases.

Figure 7. Which models recover the dynamics and which physical quantity each formulation learns.

Additional Results

Undamped Oscillator – Lagrangian NN

No Noise

Actual and LNN-predicted acceleration for the undamped oscillator with no noise.
Actual and predicted undamped-oscillator Lagrangian with no noise.

With Noise

Actual and LNN-predicted acceleration for the undamped oscillator with simulated noise.
Actual and predicted undamped-oscillator Lagrangian with simulated noise.
Figure 8. Actual and predicted acceleration (left) and Lagrangian (right) for the undamped oscillator, with no noise (upper) and full simulated noise (lower) in the observed data.

Undamped Oscillator – Hamiltonian NN

No Noise

Actual and HNN-predicted velocity for the undamped oscillator with no noise.
Actual and HNN-predicted phase-space dynamics with no noise.
Actual and predicted Hamiltonian with no noise.

With Noise

Actual and HNN-predicted velocity for the undamped oscillator with simulated noise.
Actual and HNN-predicted phase-space dynamics with simulated noise.
Actual and predicted Hamiltonian with simulated noise.
Figure 9. Actual and predicted velocity (left), momentum derivative versus velocity (middle), and Hamiltonian (right) for the undamped oscillator, with no noise (upper) and full simulated noise (lower).

Conclusion

  • Lagrangian and Hamiltonian Neural Networks can recover the dynamics of a simple dissipative system under appropriate conditions.
  • Time can be essential for recovering the intended mechanical function in systems with explicit time dependence.
  • Generalized momentum and linear momentum need not coincide in a dissipative system.
  • The Hamiltonian need not equal the total energy when the system is dissipative.
  • Multiple equivalent Lagrangians can describe the same physical motion.