Why LSTM Works and How It Mitigates Vanishing Gradients: A Numerical Integration Perspective

    In recurrent network design and physics-based modeling, three questions often arise: why does LSTM work, how is vanishing gradient mitigated, and how does LSTM differ from ODEs and numerical integration? This article answers them through the lens of numerical integration. It explains that a recurrent network can be viewed as a data-driven state-evolution model that, at each time step, learns how the current state changes with the current input and the historical state. It shows why the analogy to continuous dynamics holds in the simplified linear form (A ≈ W − I), how residual-style cell-state updates and gating ease long-range gradient propagation, and where the analogy breaks down. Readers will find a comparison between LSTM and numerical integration, practical guidance for physical and semi-physical time series, a selection checklist, and an engineering workflow covering open-loop baselines, closed-loop fine-tuning, long-range backtesting, and drift monitoring.

    1. Restating the problem: starting from three common questions

    In recurrent network and physics-based modeling work, people often ask: Why does LSTM work? How is vanishing gradient mitigated? How does LSTM differ from ODEs and numerical integration? Answering only with “it can remember long-range dependencies” stays at the surface level. A more actionable explanation is this: a recurrent network can be viewed as a data-driven model of state evolution, where at each time step the network learns how the current state changes based on the current input and the historical state. From a numerical integration perspective, this evolution resembles an implicit regression over state increments, and LSTM’s gating structure makes this long-range evolution easier to optimize during training.

    2. Recurrent networks: heuristic numerical integrators, not strict solvers

    Numerical integration deals with differential-equation-style problems. Given a continuous system:

    1. dx/dt = f(x, u)

    In engineering practice, discrete methods are commonly used to advance the state step by step. Taking forward Euler as an example:

    1. x_{n+1} = x_n + dt * f(x_n, u_n)

    The similarity between a recurrent network and this framework is that both advance time through “current state + input + incremental update.” If we write a simplified linear RNN as:

    1. # Simplified linear recurrent update
    2. dh = (W - I) @ h_prev + U @ x_t + b
    3. h_t = h_prev + dh

    it can be rearranged as:

    1. Δh = (W - I) h_{t-1} + U x_t + b

    If we compare this with the linear state equation:

    1. dx/dt = A x + B u

    then the more reasonable correspondence is:

    1. A ≈ W - I
    2. B ≈ U

    In other words, in the simplified linear form, the matrix corresponding to the continuous dynamics is closer to W - I rather than directly equal to W. This distinction matters. If we further introduce nonlinear structures such as activation functions, gating, biases, normalization, residual scaling, and input embeddings, the recurrent network can only be seen as a heuristic analogy: it borrows the form of state evolution and numerical integration, but it is not equivalent to strictly solving some fixed ODE. For models with gating or strong nonlinearity, one cannot simply claim that it is a certain class of numerical integration algorithm.

    3. State-space perspective: mapping between continuous models and discrete sequences

    In engineering and physics modeling, a common state-space form is:

    1. X' = A X + B U
    2. Y = K X

    where X represents the internal state of the system, U represents the input or external excitation, A describes the self-evolution of the state, B describes how the input affects the state, Y represents the observation or output, and K is the observation matrix or output mapping. Many control systems, mechanical systems, thermal systems, and power systems can be approximated in a similar form near their operating points.

    What time-series modeling needs to learn is: given historical states or observations, how to predict the next step. The next step can usually be understood as “current value + an increment.” From a numerical integration perspective, this increment carries derivative information; from a machine learning perspective, the network learns a conditional regression of the state increment.

    There are several assumption differences between learning a continuous ODE and a discrete sequence: whether the sampling interval is small enough, whether observation noise exists, whether system parameters vary over time, whether the discretization method introduces error, and whether multi-timescale coupling exists. Discretization methods such as forward Euler, Runge-Kutta, and linear multistep methods each have their own accuracy and stability limits. The recurrence learned by a recurrent network may approach a certain numerical integrator, or it may simply be an empirical predictor; this needs to be validated against the data and the task.

    4. Residual structure and gradient propagation: the identity term helps, but is not a universal guarantee

    When an ordinary recurrent structure backpropagates through time, the gradient is typically a product of several Jacobian matrices:

    1. ∂L/∂h_0 = ∂L/∂h_T ∏ J_t

    If the spectral radius of each step’s Jacobian is systematically less than 1, the gradient decays exponentially; if it is systematically greater than 1, the gradient tends to explode. This is one of the core sources of vanishing and exploding gradients in long-sequence training.

    The residual or integral-style update:

    1. h_t = h_{t-1} + f(h_{t-1}, x_t)

    has the Jacobian:

    1. I + ∂f/∂h

    where the identity term I provides a smoother gradient pathway, similar to the identity mapping in residual networks. This can mitigate gradient decay, but it cannot unconditionally guarantee gradient stability. The actual effect depends on:

    • The Lipschitz constant of the residual branch f;
    • The spectral radius of the Jacobian matrix;
    • Whether the activation function saturates;
    • Whether the step size or residual weight is too large;
    • Whether the initialization is reasonable;
    • Whether techniques such as gradient clipping, normalization, and stable optimizers are used;
    • The level of input noise and label noise.

    Therefore, a more accurate statement is: residual-style state updates generally help improve gradient propagation, but this must be confirmed through training diagnostics and ablation studies.

    5. How LSTM mitigates vanishing gradients: an additive backbone and gated pathways

    The key design of LSTM lies in the cell state. A common update form is:

    1. c_t = forget_t ⊙ c_{t-1} + input_t ⊙ g_t
    2. h_t = output_t ⊙ tanh(c_t)

    where c_t is the cell state, h_t is the hidden state, and the final model output y_t is usually obtained from h_t through an output layer. These three should not be conflated. The cell state c_t uses an additive update, which is more likely to preserve a long-range information pathway compared with repeated multiplicative compression. The forget gate forget_t can adaptively control the proportion of history retained; when the forget gate approaches 1, gradients can propagate along the cell state for a relatively long time. This mechanism is often called the “constant error carousel,” and its role is similar to the identity mapping in residual networks.

    But gating is not an absolute guarantee. If the input gate, forget gate, or output gate is poorly trained, or if saturation occurs over long time steps, or if task noise is too large, or if the learning rate is inappropriate, gradients can still decay or explode. Common engineering mitigations include:

    • Reasonable initialization of the forget gate bias;
    • Using gradient clipping;
    • Using orthogonal initialization or initialization suitable for recurrent networks;
    • Controlling the learning rate and optimizer state;
    • Using stabilization techniques such as layer normalization or batch normalization;
    • Training long sequences in chunks;
    • Carefully designing training objectives for closed-loop prediction scenarios.

    In addition, it is worth emphasizing that strong constraints, low degrees of freedom, or fixed explicit integration step sizes may limit the model’s expressive capacity, which in turn makes gradients harder to propagate. But this does not mean that all strict physical models will fail at gradients; this should be verified through boundary conditions, step sizes, constraint strength, initialization, and numerical experiments.

    6. Differences between LSTM and ODEs / numerical integration

    LSTM shares similarities with the numerical integration framework, but there are also clear differences:

    1. Different learning targets: numerical integration typically solves known equations; LSTM learns state increments or output mappings from data.
    2. Different meaning of time steps: the numerical integration step size is determined by accuracy and stability; the LSTM time step is usually determined by the data sampling frequency.
    3. Different constraint strength: strict physical equations impose stronger constraints, which may improve interpretability and extrapolation but also reduce degrees of freedom; LSTM is more flexible but relies more on the data distribution.
    4. Different validation targets: numerical integration focuses on convergence, stability, and error order; LSTM focuses on prediction accuracy, generalization, robustness, and training stability.
    5. Different equivalence to a fixed integrator: only in the linear simplified form can one intuitively establish the analogy A ≈ W - I; after adding activations and gating, it should be treated as a heuristic correspondence.

    7. Practical recommendations for real physical processes

    For time-series data from physical or semi-physical processes, the following judgments can be made:

    1. When data closely matches the real physical process, LSTM often has some advantages. This is because it may implicitly learn the underlying dynamics behind the data. But whether the advantage is pronounced depends on the data volume, noise, sampling frequency, system complexity, and task objectives; it should not be understood as a universal conclusion.

    2. If domain knowledge is strong, try “mechanistic ODE + network correction.” For example, first approximately derive X' = A X + B U, then use a network to learn the residual or unknown disturbances. This approach may improve generalization in out-of-distribution or extrapolation scenarios, but the premise is that the assumptions are verifiable, the parameters are identifiable, the residual model is interpretable, and out-of-distribution tests on the training data are performed.

    3. Closed-loop autoregression usually helps improve the consistency between training and inference. In closed-loop mode, the model’s previous-step output is used to predict the next step, which is closer to the real deployment state and is beneficial for long-range backtesting. But closed loop also has risks: error accumulation, mismatch between training and inference input distributions, long-range drift, and amplification of anomalous inputs. It is recommended to first establish an open-loop baseline, then perform closed-loop fine-tuning, and use long-range rolling backtests to verify stability.

    8. Selection checklist

    Scenario characteristics Options to consider Notes
    Physical mechanism is relatively clear, high extrapolation requirement Mechanistic ODE, mechanism + network correction Validate assumptions, parameter identification, residual stability
    Sufficient data, unclear dynamics LSTM/GRU, Transformer, etc. Control overfitting, validate long-range dependencies
    High real-time requirement, limited compute Lightweight recurrent models, state-space models Focus on inference latency and memory
    High noise, mediocre label quality Robust losses, denoising, mechanistic constraints Avoid overfitting to noise
    Non-stationary or multiple operating conditions Partitioned modeling, hybrid models, adaptive gating Monitor condition switching and distribution drift

    9. Engineering implementation steps

    1. Define variables clearly: distinguish the cell state, hidden state, observation, output, and exogenous inputs.
    2. Establish an open-loop baseline: first use historical true inputs for single-step or multi-step prediction.
    3. Choose the update structure: first try residual-style state updates, then evaluate the necessity of gating mechanisms.
    4. Validate gradient stability: observe gradient norms, loss curves, and long-sequence performance.
    5. Closed-loop fine-tuning: after open-loop performance is stable, gradually introduce the model’s own outputs into the recurrence.
    6. Long-range backtesting: focus on evaluating multi-step prediction, rolling windows, and performance under anomalous conditions.
    7. Post-launch monitoring: track prediction errors, input distributions, state drift, sensor anomalies, and data delays.

    10. Conclusion

    From a numerical integration perspective, LSTM works not because it is strictly equivalent to a certain numerical integration algorithm, but because it learns the evolution of the state over time in a data-driven way and improves long-range gradient propagation through residual-style cell-state updates and gating mechanisms. This perspective helps explain why recurrent structures are suited to sequence modeling, and it also reminds us that the analogy between LSTM and ODEs has boundaries, and that physics-based modeling and data-driven methods each have their advantages. In practice, model selection should be based on physical priors, extrapolation needs, data scale, and deployment constraints, and the model’s true reliability should be validated through open-loop baselines, closed-loop fine-tuning, long-range backtesting, and drift monitoring.