Learning dynamical systems through purely data-driven methods is challenging as they do not learn the underlying conservation laws that enable them to correctly generalize. Existing port-Hamiltonian neural network methods have recently been successfully applied for modeling mechanical systems. However, even though these methods are designed on power-balance principles, they usually do not consider power-preserving discretizations and often rely on Runge-Kutta numerical methods. In this work, we propose to use a second-order discrete gradient method embedded in the learning of dynamical systems with port-Hamiltonian neural networks. Numerical results are provided for three systems deliberately selected to span different ranges of dynamical behavior under control: a baseline harmonic oscillator with quadratic energy storage; a Duffing oscillator, with a non-quadratic Hamiltonian offering amplitude-dependent effects; and a self-sustained oscillator, which can stabilize in a controlled limit cycle through the incorporation of a nonlinear dissipation. We show how the use of this discrete gradient method outperforms the performance of a Runge-Kutta method of the same order. Experiments are also carried out to compare two theoretically equivalent port-Hamiltonian systems formulations and to analyze the impact of regularizing the Jacobian of port-Hamiltonian neural networks during training.
\begin{array}[]{rll}q:&\text{centered position (elongation)}&\text{[m]}\\ p:&\text{momentum}&\text{[Kg.m.s{}^{-1}]}\\ u=f:&\text{force (applied or exterior)}&\text{[N]}\end{array}
Table 1: Different port-Hamiltonian structural elements, Jacobian matrices and related quantities for the considered oscillators.
Figure 1: Architecture of the two PHNN models considered in this work. White boxes with orange contour denote fixed algebraic operations whereas orange boxes indicate the trainable parameters.
Table 2: Fixed and learned objects for the different port-Hamiltonian networks based on formulations (i) and (ii).
Figure 2: Training and inference diagram for the continuous models fθ .
Figure 3: Training and inference diagram for the discrete models gθ .
Accuracy order
Name
Characteristic
Power-balance
2
Explicit midpoint (RK2)
Explicit
×
2
Discrete gradient (DG)
Inverse-explicit
✓
Table 3: Accuracy order, name, characteristic and whether power-balance is respected for the chosen numerical schema.
System
Harmonic Oscillator
Duffing Oscillator
Self-sustained oscillator
Intrinsic parameters
(m,k)
(m,k1,k3)
(m,k)
f0 [Hz]
1Hz
m [kg]
0.16
1/k,1/k1 [ N/m ]
0.16
k3 [ N/m3 ]
-
100k1
-
z(w)
0.9w [N]
1.3w3−4w2+3w[m/s]
Table 4: Implementation hyperparameters for the different experiments.
Figure 4: Training points, test initial points and two complete test trajectories for each of the three oscillatory systems. Note that in the case of the harmonic and Duffing oscillator, the applied control shifted the equilibrium point from (p,q)=(0,0) whereas in the case of the self-sustained oscillator, it stabilizes the trajectories in a limit cycle.
Figure 5: Schematic sampling and dataset construction procedure. A trajectory generated at sampling frequency srgen over a duration D=Dinfer=βT0 is shown as white dot markers. From this trajectory, a training point, highlighted with a green star marker, is uniformly sampled from a subset of samples, shown as black dot markers, obtained at frequency srtrain and restricted to t≤αT0 . The training horizon Dtrain and the inference horizon Dinfer are indicated by arrows, with the vertical dashed line marking the end of the training interval.
Figure 6: Boxplot of the inference errors for the three different oscillators and varying numbers of training points (small models). From left to right: harmonic, Duffing and self-sustained oscillators.
Figure 7: Comparison of the learned trajectory discretizations for each oscillatory system starting on x0 such that H(x0)=0.5J . ( Left ) NODE and PHNN-S models trained on Ntrain=25 from the harmonic oscillator. ( Center ) NODE and PHNN-S models trained on Ntrain=100 from the Duffing oscillator. ( Right ) NODE and PHNN-JR models trained on Ntrain=25 from the self-sustained oscillator. For the harmonic and Duffing oscillator, the trajectory is obtained with u=0 ; and for the self-sustained, with u such that the system stabilizes in a limit cycle.
Figure 8: Boxplot of the inference errors for the three different oscillators and model sizes ( Ntrain=25 ). From left to right: harmonic, Duffing and self-sustained oscillators.
Figure 9: Comparison of the learned trajectory discretizations by the discrete gradient for each oscillatory system starting on x0 such that H(x0)=0.75J . ( Left ) PHNN-S models trained on Ntrain=25 from the harmonic oscillator. ( Center ) PHNN-S models trained on Ntrain=25 from the Duffing oscillator. ( Right ) PHNN-JR models trained on Ntrain=25 from the self-sustained oscillator. For the harmonic and Duffing oscillator, the trajectory is obtained with u=0 ; and for the self-sustained, with u such that the system stabilizes in a limit cycle.
Figure 10: Mean condition number ( left ), spectral norm ( center ) and stiffness ratio ( right ) per optimizer step during the training for the different architectures when modeling the Duffing oscillator with Ntrain=25 points and no Jacobian regularization (BL). For each optimizer step, the corresponding mean value (solid line) is obtained computing the average over the 10 model initializations, with the shaded area indicating the range between the minimum and maximum values.
Figure 11: Boxplot of the inference errors for the three different oscillators and normalizations ( Ntrain=25 and small number of parameters). Notation: BL refers to the baseline (i.e. no Jacobian regularization); CN, to the condition number regularization ( 34 ); SN, to the spectral norm regularization ( 35 ); and SR, to the stiffness ratio regularization ( 36 ). From left to right: harmonic, Duffing and self-sustained oscillators.
Figure 12: Impact on the mean condition number ( left ), spectral norm ( center ) and stiffness ratio ( right ) per optimizer step during the training for the different architectures when modeling the Duffing oscillator with Ntrain=25 points and the proposed Jacobian regularizations. For each optimizer step, the corresponding mean value (solid line) is obtained computing the average over the 10 model initializations, with the shaded area indicating the range between the minimum and maximum values.
Table 7: Jacobian matrix, spectral norm, condition number and stiffness ratio for the self-sustained oscillator.
q←k12E0sinθ,p←2mE0cosθ
Appendix
Algorithm 1 Initial condition sampling for HO and SSO
Model
Components
Network
Input
Layers
Hidden
Output
Number of parameters
type
dimension
units
dimension
(per component)
(per model)
NODE
Black-box
MLP
3
3
100
2
21,4k
21,4k
PHNN-JR
LθLH(x)
MLP
2
2
100
3
10,7k
21,8k
LθLR(x,u)
MLP
3
2
100
3
11,1k
PHNN-S
LθLH(x)
MLP
2
2
100
3
10,7k
21,1k
LθLz(w)
MLP
1
2
100
1
10,4k
Appendix
Table 8: Specificities of the implemented port-Hamiltonian neural networks with large number of parameters.
Model
Components
Network
Input
Layers
Hidden
Output
Number of parameters
type
dimension
units
dimension
(per component)
(per model)
NODE
Black-box
MLP
3
2
60
2
4,3k
4,3k
PHNN-JR
LθLH(x)
MLP
2
2
42
3
2,1k
4,3k
LθLR(x,u)
MLP
3
2
42
3
2,2k
PHNN-S
LθLH(x)
MLP
2
2
42
3
2,1k
4,1k
LθLz(w)
MLP
1
2
42
1
2k
Appendix
Table 9: Specificities of the implemented port-Hamiltonian neural networks with medium size of parameters.
Model
Components
Network
Input
Layers
Hidden
Output
Number of parameters
type
dimension
units
dimension
(per component)
(per model)
NODE
Black-box
MLP
3
2
24
2
848
848
PHNN-JR
LθLH(x)
MLP
2
2
16
3
371
809
LθLR(x,u)
MLP
3
2
16
3
438
PHNN-S
LθLH(x)
MLP
2
2
16
3
371
852
LθLz(w)
MLP
1
2
20
1
481
Appendix
Table 10: Specificities of the implemented port-Hamiltonian neural networks with low size of parameters.
Harmonic
25
100
400
NODE-RK2
2.53e-02 [2.33e-02]
1.69e-04 [1.54e-04]
2.79e-05 [1.84e-05]
PHNN-JR-DG
2.58e-04 [3.82e-04]
9.10e-06 [1.22e-05]
7.29e-06 [5.07e-06]
PHNN-JR-RK2
1.14e-04 [1.02e-04]
6.88e-06 [3.81e-06]
5.18e-06 [5.50e-06]
PHNN-S-DG
4.22e-05 [5.99e-05]
6.24e-06 [4.97e-06]
4.78e-06 [1.21e-05]
PHNN-S-RK2
4.89e-05 [2.11e-04]
5.77e-06 [9.55e-06]
3.73e-06 [8.89e-06]
Duffing
25
100
400
Appendix
Table 11: Median inference error and IQR (in brackets) for different numbers of training points when learning the three oscillatory systems with small models. In bold, the best result for each combination of system and number of training points.
Harmonic
Small size
Medium size
Large size
NODE-RK2
2.53e-02 [2.33e-02]
2.85e-02 [2.59e-02]
1.45e-01 [4.67e-02]
PHNN-JR-DG
2.58e-04 [3.82e-04]
1.47e-04 [2.68e-04]
7.33e-04 [2.52e-03]
PHNN-JR-RK2
1.14e-04 [1.02e-04]
5.56e-05 [1.19e-04]
1.51e-04 [3.87e-04]
PHNN-S-DG
4.22e-05 [5.99e-05]
5.56e-05 [9.58e-05]
2.45e-04 [4.59e-04]
PHNN-S-RK2
4.89e-05 [2.11e-04]
4.28e-05 [3.73e-05]
2.01e-04 [2.13e-04]
Duffing
Small size
Medium size
Large size
Appendix
Table 12: Median inference error and IQR (in brackets) for different model sizes when learning the three oscillatory systems with Ntrain=25 . In bold, the best result for each combination of system and model size.
Harmonic
BL
CN
SN
SR
NODE-RK2
2.53e-02 [2.33e-02]
7.82e-02 [1.63e+00]
2.63e-02 [2.53e-02]
2.56e-02 [5.70e-02]
PHNN-JR-DG
2.58e-04 [3.82e-04]
2.20e-04 [3.40e-04]
1.94e-04 [3.09e-04]
2.30e-04 [3.19e-04]
PHNN-JR-RK2
1.14e-04 [1.02e-04]
1.50e-04 [5.70e-04]
7.18e-05 [9.39e-05]
1.26e-04 [1.46e-04]
PHNN-S-DG
4.22e-05 [5.99e-05]
3.84e-05 [4.05e-05]
3.44e-05 [6.62e-05]
1.13e-04 [3.07e-04]
PHNN-S-RK2
4.89e-05 [2.11e-04]
1.17e-05 [5.67e-05]
5.66e-05 [2.02e-04]
2.97e-05 [5.35e-04]
Duffing
BL
CN
SN
SR
Appendix
Table 13: Median inference error and IQR (in brackets) after applying the different Jacobian regularizations when learning the three oscillatory systems with Ntrain=25 and small models. The best result for each combination of system and Jacobian regularization is shown in bold. Notation: BL refers to the baseline (i.e. no Jacobian regularization); CN, to the condition number regularization ( 34 ); SN, to the spectral norm regularization ( 35 ); and SR, to the stiffness ratio regularization ( 36 )
This paper investigates the problem of data-driven modeling of port-Hamiltonian systems while preserving their intrinsic Hamiltonian structure and stability properties. We propose a novel neural-network-based port-Hamiltonian modeling technique that relaxes the convexity constraint commonly imposed by neural network-based Hamiltonian approximations, thereby improving the expressiveness and generalization capability of the model. By removing this restriction, the proposed approach enables the use of more general non-convex Hamiltonian representations to enhance modeling flexibility and accuracy. Furthermore, the proposed method incorporates information about stable equilibria into the learning process, allowing the learned model to preserve the stability of multiple isolated equilibria rather than being restricted to a single equilibrium as in conventional methods. Two numerical experiments are conducted to validate the effectiveness of the proposed approach and demonstrate its ability to achieve more accurate structure- and stability-preserving learning of port-Hamiltonian systems compared with a baseline method.
Binh Nguyen, Nam T. Nguyen, Truong X. Nghiem
Department of Electrical and Computer Engineering, College of Engineering and Computer Science, University of Central Florida, Orlando, FL 32816, USA
We introduce Quantum Port-Hamiltonian Neural Networks (Q-pHNNs), a family of parameterised quantum circuits that learn classical dynamics in a structure-preserving manner. The framework relies on the Isomorphic Hamiltonian Mapping (IHM): the skew-symmetric interconnection matrix J corresponds to unitary gate evolution, and the positive-semidefinite dissipation matrix R corresponds to Measurement-Induced NonLinearity (MINL) realised via mid-circuit measurement and classical feedforward. This ensures conservation and passivity are enforced by construction rather than penalty terms. We instantiate the IHM in four architectures: (1) a Quantum HNN that learns conservative energy manifolds and extracts Hamilton's equations exactly via the Parameter-Shift Rule; (2) a Q-pHNN using Born-rule measurement for dissipation; (3) a Q-pHNN jointly learning the energy ansatz and damping coefficient; and (4) a topology-entangled Quantum Graph Neural Network for N-node coupled-phasor networks. Experiments on the nonlinear pendulum and damped harmonic oscillator demonstrate: (i)1.35% relative energy drift with a symplectic integrator and scale correction; (ii)100% energy monotonicity for the MINL circuit; and (iii)~12.1% error in damping-coefficient identification from vector-field snapshots with no direct supervision on the damping coefficient.
Stochastic port-Hamiltonian systems represent open dynamical systems with dissipation, inputs, and stochastic forcing in an energy based form. We introduce stochastic port-Hamiltonian neural networks, SPH-NNs, which parameterize the Hamiltonian with a feedforward network and enforce skew symmetry of the interconnection matrix and positive semidefiniteness of the dissipation matrix. For Itô dynamics we establish a weak passivity inequality in expectation under an explicit generator condition, stated for a stopped process on a compact set. We also prove a universal approximation result showing that, on any compact set and finite horizon, SPH-NNs approximate the coefficients of a target stochastic port-Hamiltonian system with C2 accuracy of the Hamiltonian and yield coupled solutions that remain close in mean square up to the exit time. Experiments on noisy mass spring, Duffing, and Van der Pol oscillators show improved long horizon rollouts and reduced energy error relative to a multilayer perceptron baseline.
Luca Di Persio, Matthias Ehrhardt, Youness Outaleb
Department of Computer Science - College of Mathematics University of Verona, Strada le Grazie 15 - 37134 Verona, Italy · University of Wuppertal, Chair of Applied and Computational Mathematics, Gaußstrasse 20, 42119 Wuppertal, Germany · Doctoral School in Mathematics, University of Trento Via Sommarive, 14 - 38123 Povo, Italy