In-Context Estimation and Prediction for Parametric ODEs

Abdullah Ahmed, Yun YangarXiv 2026 · arXiv

TL;DR

This paper demonstrates that Transformers can perform in-context parameter estimation and trajectory prediction for parametric Ordinary Differential Equations (ODEs), even when the underlying inverse problem is non-convex. By theoretically constructing a Transformer that emulates a two-stage maximum likelihood procedure (coarse search followed by gradient descent), the authors provide rigorous guarantees for how these models can adapt to new physical systems without any weight updates at inference time.

What Problem Does This Paper Address?

Ordinary Differential Equations (ODEs) are the bedrock of scientific modeling, describing everything from chemical reactions to planetary motion. While the general form of these equations is often known from physical laws, the specific parameters (like reaction rates or friction coefficients) vary across different experiments.

Traditionally, scientists estimate these parameters using Maximum Likelihood Estimation (MLE), which involves solving a computationally expensive, non-convex optimization problem for every new dataset. Recently, In-Context Learning (ICL) has emerged as a way to "amortize" this cost: a model is pretrained on many different ODE tasks so that, at test time, it can look at a few noisy observations from a new system and immediately predict its parameters or future states.

However, most existing theory for ICL focuses on simple convex problems (like linear regression). This paper tackles the much harder challenge of non-convex inverse problems inherent in nonlinear dynamical systems.

Methods

The authors bridge the gap between deep learning theory and dynamical systems through three main contributions:

  1. The Two-Stage Emulation: They prove that a Transformer can be constructed to implement a two-stage estimation algorithm. First, it performs a "coarse search" over the parameter space to find a good starting point. Second, it uses gradient descent to refine that estimate. This allows the model to handle non-convexity by ensuring it starts in a "locally convex" region near the true parameters.
  2. Joint Architecture: They show that a single Transformer can perform both parameter estimation and trajectory prediction simultaneously by sharing internal computations. The model first "infers" the system parameters and then "simulates" the ODE solution map.
  3. Theoretical Guarantees: The authors derive "oracle inequalities" that decompose the prediction error into three distinct sources:
  4. Finite pretraining data: Errors from not seeing enough different ODE tasks during training.
  5. Finite context length: Errors from having too few observations of the current system.
  6. Approximation error: Errors from the finite size (depth/width) of the Transformer itself.

Datasets

The researchers evaluated their approach on four distinct parametric ODE families, each chosen to test a specific challenge:

  • Forced Linear (FL): A convex system used for large-scale studies of how error scales with data.
  • Logistic Growth (LG): A classic nonlinear, non-convex estimation problem.
  • Birth-Death (BD): A non-identifiable system where multiple parameter sets produce the same trajectory, testing the model's ability to find identifiable combinations.
  • Stuart-Landau (SL): A higher-dimensional (2D state, 4D parameters) system with oscillatory dynamics and limit cycles.

Key Insights and Ideas

  • Transformers as Statisticians: The model doesn't just memorize trajectories; it effectively learns the "prior" distribution of parameters during pretraining. This allows it to outperform classical MLE when observations are extremely sparse (e.g., estimating 3 parameters from only 2 data points).
  • Zero-Shot Refinement: A key "aha moment" is that a pretrained Transformer can benefit from longer contexts at inference time than it saw during training. If you train on 128 observations but give it 512 at test time, the error continues to drop without any further training.
  • Structural Exploitation: Unlike "black-box" sequence models, the proposed construction explicitly uses the structure of the inverse problem. By emulating a numerical solver (like an Euler method) within the Transformer layers, the model maintains physical consistency.

Key Results

  • Performance: In the Forced Linear case, the Transformer closely matches the Posterior Mean (the theoretical Bayesian optimum) and significantly outperforms standard Gradient Descent and MLE when noise is high or data is limited.
  • Scaling: The authors empirically verified that the test loss follows a power-law decay relative to the number of pretraining tasks ($M$), confirming their theoretical error decomposition.
  • Efficiency: The joint model (estimating parameters + predicting state) achieves nearly identical accuracy to specialized models while maintaining the same order of model complexity.

Limitations and Future Work

  • The Curse of Dimensionality: The "coarse search" initialization strategy requires a parameter net that grows exponentially with the number of parameters ($p$). Developing more efficient in-context initialization for high-dimensional systems remains an open challenge.
  • Theoretical Gap in Generalization: While experiments show the model generalizes to longer context lengths, the current pretraining theory is established for a fixed number of observations ($n$).
  • Beyond Parametric Forms: The current work assumes the functional form of the ODE is known. Future research could explore in-context learning for non-parametric system discovery, where the model must infer the equations themselves from scratch.

Summary updated

Abstract

Transformers have demonstrated the ability to perform in-context learning, that is, to adapt to new tasks from a few examples without updating their parameters. Existing theory has largely focused on emulating gradient-based algorithms for convex statistical problems or establishing general function approximation guarantees without exploiting the underlying statistical structure. We study in-context parameter estimation and trajectory prediction for parametric ordinary differential equations (ODEs), where estimation is generally nonconvex. Under suitable identifiability and regularity conditions, we construct a transformer that estimates unknown system parameters from noisy trajectory observations through a two-stage approximate maximum likelihood procedure: a coarse search provides an initialization within a locally strongly convex region, followed by gradient descent with local linear contraction. For prediction, we compose this estimator with a neural approximation of the ODE solution map. We further show that, through parameter sharing, a single transformer can perform both parameter estimation and trajectory prediction simultaneously. For these constructions, we establish nonasymptotic guarantees and finite-pretraining oracle inequalities that separate errors due to finite pretraining data, finite context length, and finite-sized transformer approximation. Numerical experiments on linear and nonlinear ODEs further show that pretrained transformers can benefit from longer inference contexts without updating their weights.
BibTeX
@misc{ahmed2026context,
  author = {Abdullah Ahmed and Yun Yang},
  title = {{In-Context Estimation and Prediction for Parametric ODEs}},
  year = {2026},
  eprint = {2611.21268},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2611.21268},
}
Figure