---
title: Stochastic Generating Function NN (SGFNN)
url: https://www.emergentmind.com/topics/stochastic-generating-function-neural-network-sgfnn
type: topic
---

# Stochastic Generating Function NN (SGFNN)

The stochastic generating function neural network (SGFNN) is a neural network model for learning stochastic Hamiltonian systems from observational data. SGFNN preserves symplectic structure of the underlying stochastic Hamiltonian system and produces symplectic predictions. The model uses an autoencoder framework to identify the randomness of the latent system by the encoder network, and detects the stochastic generating function of the system through the decoder network based on the random variables extracted from the encoder. Symplectic predictions are then generated by the stochastic generating function [2507.14467].

## 1. Stochastic Hamiltonian setting

SGFNN is formulated for \(2d\)-dimensional Stratonovich stochastic Hamiltonian systems of the form
\[
\begin{aligned}
d p &= f(p,q)\,dt + \sum_{k=1}^r \sigma_k(p,q) \circ dW_k(t), \quad p(t_0)=p_0, \\
d q &= g(p,q)\,dt + \sum_{k=1}^r \gamma_k(p,q) \circ dW_k(t), \quad q(t_0)=q_0.
\end{aligned}
\]
Here \(p,q \in \mathbb{R}^d\), and \(W_k\), \(k=1,\dots,r\), are independent standard Brownian motions. The system is Hamiltonian in the stochastic sense if there exist smooth functions \(H(p,q)\) and \(H_k(p,q)\), \(k=1,\dots,r\), such that
\[
\begin{aligned}
f(p,q) &= -\frac{\partial H}{\partial q}(p,q)^T, &\quad \sigma_k(p,q) &= -\frac{\partial H_k}{\partial q}(p,q)^T, \\
g(p,q) &= \phantom{-}\frac{\partial H}{\partial p}(p,q)^T, &\quad \gamma_k(p,q) &= \phantom{-}\frac{\partial H_k}{\partial p}(p,q)^T.
\end{aligned}
\]
This formulation covers additive and multiplicative noise, separable and non-separable Hamiltonians, and systems with single or multiple noises [2507.14467].

The solution flow \(\varphi_t(x_0;\omega)\), with \(x_t=(p_t^T,q_t^T)^T\), is symplectic almost surely. If \(D\varphi_t := \frac{\partial \varphi_t}{\partial x_0}\), then
\[
(D\varphi_t)^T J D\varphi_t = J, \quad \text{a.s.}, \qquad
J=\begin{bmatrix} 0 & I \\ -I & 0 \end{bmatrix}.
\]
A learned or numerical one-step map \(\widetilde{\varphi}: x_n \mapsto x_{n+1}\) is symplectic if it satisfies the same condition. In the SGFNN construction, this property is imposed by design rather than recovered only empirically [2507.14467].

The examples used to instantiate the framework include a linear stochastic oscillator with additive noise, the Kubo oscillator with multiplicative noise, a non-separable stochastic Hamiltonian system with
\[
H_0 = \tfrac12 (p^2+1)(q^2+1), \qquad H_1 = 0.1(p+q)^2,
\]
and synchrotron oscillations with two multiplicative noises. These examples are chosen to span distinct structural regimes of stochastic Hamiltonian dynamics [2507.14467].

## 2. Stochastic generating functions and random symplectic maps

In symplectic geometry, a generating function is a scalar function whose partial derivatives define a symplectic map. For the first kind, a function \(S(P,q)\) defines the map \((p,q)\mapsto (P,Q)\) through
\[
p = P + \frac{\partial S}{\partial q}^T, \qquad
Q = q + \frac{\partial S}{\partial P}^T.
\]
In the stochastic setting, the generating function becomes a random function \(S(P,q,\omega)\). If \(\varphi_\omega:(p,q)\mapsto(P,Q)\) is a smooth random map, then \(\varphi_\omega\) is symplectic if there exists locally a smooth random map \(S(P,q,\omega)\) such that \(\frac{\partial (P^T q + S)}{\partial P \partial q}\) is invertible almost surely and
\[
p = P + \frac{\partial S}{\partial q}^T(P,q,\omega), \qquad
Q = q + \frac{\partial S}{\partial P}^T(P,q,\omega), \qquad \text{a.s.}
\]
This is the structural device used by SGFNN to ensure that the learned one-step map is symplectic [2507.14467].

For a time step \(\Delta\), the exact one-step solution map of an SHS is a random symplectic map \(\varphi_\Delta\). SGFNN represents it locally by a stochastic generating function
\[
S_\Delta(P,q;\text{noise}) \equiv S(P,q,z),
\]
where \(z\sim\mathcal N(0,I)\) is a finite-dimensional latent representation of the stochastic forcing over \([t,t+\Delta]\). The paper does not derive an explicit analytic formula for \(S\); instead, \(S(P,q,z)\) is treated as an unknown function to be learned [2507.14467].

A common terminological confusion is to read “generating function” here as a probabilistic generating function. In SGFNN, the term refers to the symplectic-geometry generating function of a random map. This suggests that the model is fundamentally a structure-preserving discretization of stochastic Hamiltonian flow rather than a generic stochastic latent-variable network.

## 3. Autoencoder architecture and learning objective

For a fixed time step \(\Delta\), the training data are one-step pairs
\[
\mathcal{D} = \{(x_0^{(i)},x_1^{(i)})\}_{i=1}^M, \qquad
x_j^{(i)}=(p_j^{(i)T},q_j^{(i)T})^T \in \mathbb{R}^{2d}.
\]
SGFNN assumes that for each pair there exists a latent Gaussian variable \(z^{(i)}\) such that the pair is generated by an implicit symplectic map induced by a stochastic generating function [2507.14467].

The encoder is
\[
z^{(i)} = E_\Delta(x_0^{(i)},x_1^{(i)};\theta_1), \qquad z^{(i)}\in\mathbb R^{n_z}.
\]
The latent variable is trained to satisfy three conditions: it should be independent of \(x_0\), distributed as standard Gaussian, and have dimension \(n_z\) matching the number of effective stochastic drivers. For a batch \(B=\{z^{(i)}:i=1,\dots,K\}\), the distribution-matching loss is
\[
\mathcal{L}_D(B)=\mathcal{L}_{\text{distance}}(B)+\tau\,\mathcal{L}_{\text{moment}}(B),
\]
with
\[
\mathcal{L}_{\text{moment}}(B)=
\sum_{j=1}^6 \frac{1}{c_j}\left\|\widehat{\mu}^{(j)}(B)-\mu^{(j)}(P_{\text{normal}})\right\|_2^2
+ \frac{\nu}{V}\sum_{1\le j<k\le n_z}(\widehat{\rho}_{jk}(B))^2.
\]
The moment term matches central moments up to order \(6\) and penalizes cross-correlations among latent dimensions [2507.14467].

The decoder is the learned stochastic generating function
\[
S_{\theta_2}(p_1,q_0,z)=D_\Delta(p_1,q_0,z;\theta_2).
\]
For a one-step pair \((x_0^{(i)},x_1^{(i)})\), the generating-function relations are
\[
p_0 = p_1 + \frac{\partial S}{\partial q_0}^T(p_1,q_0,z), \qquad
q_1 = q_0 + \frac{\partial S}{\partial p_1}^T(p_1,q_0,z).
\]
The data-fitting loss over a batch \(B\) is
\[
\mathcal{L}_{\text{MSE}}(B)
= \frac{1}{K}\sum_{i=1}^K
\left(
\left\| p_1^{(i)} - p_0^{(i)} + \frac{\partial S_{\theta_2}}{\partial q_0^{(i)}}^T \right\|_2^2
+
\left\| q_1^{(i)} - q_0^{(i)} - \frac{\partial S_{\theta_2}}{\partial p_1^{(i)}}^T \right\|_2^2
\right),
\]
where the partial derivatives are computed by automatic differentiation at \((p_1^{(i)},q_0^{(i)},z^{(i)})\) [2507.14467].

The total objective is
\[
\mathcal{L}_{\text{SGFNN}}
= \frac{1}{N_B}\sum_{j=1}^{N_B}
\left[
\mathcal{L}_{\text{MSE}}(B_j)+\lambda\,\mathcal{L}_D(B_j)
\right].
\]
Minimizing this objective yields an encoder that outputs approximate \(z\sim\mathcal N(0,I)\), a decoder that approximates the stochastic generating function \(S(p_1,q_0,z)\), and a learned symplectic one-step map \(\tilde\varphi_\Delta\) [2507.14467].

## 4. Training data, optimization, and prediction

SGFNN requires only state observations sampled at equal time step \(\Delta\). In the numerical study, the training data are discrete trajectories
\[
\{x_0^{(i)},x_1^{(i)},\dots,x_L^{(i)}\}, \qquad i=1,\dots,N,
\]
and the effective training set is the collection of one-step pairs \(\{(x_j^{(i)},x_{j+1}^{(i)})\}\). The reported experiments use \(10{,}000\) trajectories generated numerically by the midpoint scheme with time step \(\Delta=0.01\). Both encoder and decoder are fully connected networks with \(3\) hidden layers, \(20\) neurons each, and ELU activation. Optimization uses Adam with learning rate \(10^{-3}\). The training configuration is \(N_B=1000\) batches of size \(K=10000\) [2507.14467].

The method adopts the sub-sampling strategy from sFML: for each batch, the initial states \(x_0^{(i)}\) are selected as nearest neighbors to a randomly chosen center, so that the empirical distribution of \(x_0\) in the batch is non-Gaussian and the independence of \(z\) from \(x_0\) becomes more identifiable. This batching rule is part of the latent-noise identification mechanism [2507.14467].

After training, prediction uses only the decoder. Given \(x_0=(p_0^T,q_0^T)^T\) and a new sample \(\omega\sim\mathcal N(0,I)\), the one-step map is implicit in \(p_1\):
\[
p_1 = p_0 - \frac{\partial S_{\theta_2}^T}{\partial q_0}(p_1,q_0,\omega).
\]
The paper solves this with a fixed-point iteration:
\[
p_1^{(0)} = p_0, \qquad
p_1^{(j+1)} = p_0 - \frac{\partial S_{\theta_2}^T}{\partial q}(p_1^{(j)},q_0,\omega),
\]
until
\[
\|p_1^{(j+1)}-p_1^{(j)}\|_2 \le \varepsilon,
\]
with \(\varepsilon=10^{-12}\). The predicted step is then
\[
\widetilde p_1 = p_1^{(C)}, \qquad
\widetilde q_1 = q_0 + \frac{\partial S_{\theta_2}^T}{\partial p}(\widetilde p_1,q_0,\omega).
\]
Multi-step prediction is obtained by iteration in time, drawing independent \(\omega\) at each step [2507.14467].

The symplecticity guarantee is architectural. For any fixed \(z\), the map defined by the generating-function relations is symplectic provided \(\frac{\partial (p_1^T q_0 + S)}{\partial p_1 \partial q_0}\) is invertible. Because the decoder parameterizes the stochastic generating function rather than an unconstrained flow map, the learned discrete-time dynamics are symplectic by construction [2507.14467].

## 5. Empirical behavior and comparison with stochastic flow map learning

The benchmark in the study is stochastic Flow Map Learning (sFML). sFML also uses an autoencoder, but its decoder learns a direct flow map
\[
x_1 = G_\Delta(x_0,z),
\]
with no structural constraint such as symplecticity. SGFNN instead learns the generating function \(S(p_1,q_0,z)\), and the one-step map is recovered through symplectic relations. The reported prediction metrics at final time \(T\) are
\[
e_T^{m} = \| \mathbb{E}(x_T) - \mathbb{E}(\tilde x_T) \|, \qquad
e_T^{std} = \| \mathrm{STD}(x_T) - \mathrm{STD}(\tilde x_T) \| .
\]
Across all reported systems, SGFNN achieves smaller errors than sFML, with the difference especially pronounced in long-term predictions [2507.14467].

| Example | \(e_T^m\) | \(e_T^{std}\) |
|---|---:|---:|
| Linear oscillator, \(T=50\) | sFML \(3.53\mathrm{e}{-01}\) → SGFNN \(2.88\mathrm{e}{-02}\) | sFML \(1.36\mathrm{e}{-01}\) → SGFNN \(3.53\mathrm{e}{-03}\) |
| Kubo oscillator, \(T=5\) | sFML \(3.68\mathrm{e}{-01}\) → SGFNN \(9.85\mathrm{e}{-02}\) | sFML \(1.51\mathrm{e}{-01}\) → SGFNN \(1.25\mathrm{e}{-01}\) |
| Non-separable SHS, \(T=7\) | sFML \(6.37\mathrm{e}{-02}\) → SGFNN \(1.46\mathrm{e}{-02}\) | sFML \(4.47\mathrm{e}{-01}\) → SGFNN \(7.86\mathrm{e}{-02}\) |
| Synchrotron oscillations, \(T=10\) | sFML \(1.08\mathrm{e}{+00}\) → SGFNN \(7.44\mathrm{e}{-02}\) | sFML \(3.73\mathrm{e}{-01}\) → SGFNN \(1.18\mathrm{e}{-02}\) |

The qualitative comparisons align with these metrics. For the linear stochastic oscillator,
\[
\mathbb{E}[p(t)^2+q(t)^2] = p_0^2 + q_0^2 + \sigma^2 t,
\]
and SGFNN reproduces the linear growth of the second moment up to \(t=50\), whereas sFML deviates. For the Kubo oscillator,
\[
H(p(t),q(t)) = p(t)^2 + q(t)^2 \equiv p_0^2 + q_0^2,
\]
and SGFNN phase plots remain circular and radius-conserving, while sFML trajectories drift away from circles. In the non-separable and synchrotron examples, SGFNN tracks mean and standard deviation more accurately over time and yields probability density functions closer to the reference solution. In all cases, the histograms of the learned latent variables \(z\) match standard normal densities, which is consistent with successful extraction of the stochastic drivers [2507.14467].

## 6. Relation to adjacent stochastic neural models

SGFNN belongs to a broader family of neural models that embed structural priors from stochastic dynamics, but its defining feature is the use of a learned stochastic generating function to enforce symplecticity. This distinguishes it from several nearby lines of work.

“Stochastic Generative Flow Networks” extend GFlowNets to stochastic environments by decomposing each transition into a policy-controlled deterministic step and an environment step, together with a learned dynamics model \(\hat P(s' \mid s,a)\) [2302.09465]. That framework addresses reward-proportional sampling in stochastic DAG environments rather than learning stochastic Hamiltonian flows. “Embedding stochastic differential equations into neural networks via dual processes” constructs networks for predicting expectations of SDEs by matching neural-network Taylor coefficients to the coefficients of a dual process, and explicitly avoids input-output datasets [2306.04847]. GFINNs encode the GENERIC formalism and obey symmetric degeneracy conditions for deterministic and stochastic dynamical systems [2109.00092]. Stochastic feedforward networks and Gaussian-process neurons study stochastic mappings, stochastic activations, or stochastic latent units, but not learned stochastic generating functions for random symplectic maps [1910.09763; 1704.03188; 1711.11059].

A second recurring misconception concerns the phrase “generating function.” In SGFNN it is not a probability-generating or moment-generating function. It is the first-kind generating function of symplectic geometry, made stochastic through latent random variables. This suggests that SGFNN is best interpreted as a structure-preserving model class specialized to stochastic Hamiltonian systems, not as a general-purpose stochastic sequence model.

## 7. Assumptions, limitations, and extensions

The method assumes that the underlying dynamics are genuinely stochastic Hamiltonian and that the effective stochastic driving can be summarized by a finite-dimensional Gaussian latent variable \(z\). If the true system is non-Hamiltonian, dissipative, or driven by noise that is strongly non-Gaussian or highly path-dependent, the structural prior is mis-specified. Training is based on pairwise one-step data and depends on the sub-sampling strategy inherited from sFML. At inference time, every step requires solving an implicit equation for \(p_1\) by fixed-point iteration, which may be heavier than an explicit flow-map evaluation. The reported experiments are confined to two-dimensional phase spaces [2507.14467].

The paper identifies several natural directions for extension. These include more advanced parameterizations of the generating function \(S\), such as SympNets-like constructions, theoretical analysis of generalization, extensions beyond Brownian-driven SHSs to Lévy noise or colored noise, integration with density-based approaches such as Fokker–Planck or normalizing-flow methods, and incorporation of additional physical structures such as symmetries and invariants [2507.14467]. A plausible implication is that future SGFNN variants may be organized around richer geometric priors rather than around larger unconstrained decoders.

Within its stated domain, SGFNN provides a direct synthesis of latent-noise identification, generating-function learning, and symplectic structure preservation. Its central claim is not merely that stochastic Hamiltonian systems can be approximated by neural networks, but that the approximation can be carried out through a learned random symplectic map whose discrete-time predictions remain symplectic by construction [2507.14467].

Source: https://www.emergentmind.com/topics/stochastic-generating-function-neural-network-sgfnn