In-Context Learning for System Identification: Probabilistic Formulation, Long-Sequence Handling, and Benchmark Validation
Authors: Matteo Rufolo, Dario Piga, Filippo Pura, Marco Forgione
Organizations: SUPSI, IDSIA - Dalle Molle Institute for Artificial Intelligence, Lugano, Switzerland · USI, Faculty of Informatics, Lugano, Switzerland
Traditional system identification typically involves two steps: initially, training data is processed to estimate a model of the system of interest; then, the model is used to predict outputs for new input queries. In contrast, recent in-context learning approaches learn a meta model that maps directly from training data and query inputs to outputs in a zero-shot fashion, bypassing explicit model estimation. This approach leverages a meta model trained offline, on large sets of synthetically generated data, to emulate the behavior of a system identification algorithm. In this work, we advance this meta-learning framework for system identification in three directions. First, we develop a unified probabilistic meta-identification architecture that combines a Transformer-based encoder-decoder with tailored mechanisms for handling long training sequences, enabling calibrated predictions over long horizons. Second, we show how a pre-trained meta model can act as an uncertainty-aware synthetic data generator for classical system identification, providing task-specific data that regularize parametric models when real data are scarce. Third, we systematically evaluate the framework on standard nonlinear system identification benchmarks and on a challenging out-of-distribution scenario, demonstrating competitive accuracy with state-of-the-art methods and strong generalization, including cases where input-only adaptation is sufficient to handle significant distribution shifts.
Figures & tables
Figure 1: Encoder-decoder Transformer for in-context system identification. The main differences with respect to the original Transformer architecture Vaswani et al. (2017) are highlighted in blue and pink. Additionally, an extra layer preceding the encoder backbone, referred to as recurrent patching neural network and highlighted in green, is incorporated to manage long context sequences.
Figure 2: Visual representation of the implemented patching approach. For clarity, a single-input ( nu=1 , blue) single-output ( ny=1 , red) system is depicted
Method
RMSE mean (std)
Inference time [s]
Patching
0.048 (0.044)
0.019
Ensembling
0.038 (0.050)
0.039
Table 1: In-distribution systems: Root Mean Square Error (RMSE) and inference time for patching-based and ensembling approach.
Figure 3: In-distribution test results obtained using the patching-based meta model. Top: aggregated prediction results over 320 WH systems, highlighting the consistency and stability of the predictions across many system realizations. Bottom: representative WH system showing the true output y , the predicted mean μ , the prediction error y−μ , and the uncertainty band μ±3σ . The narrow confidence intervals and low error illustrate accurate prediction.
Figure 4: Prediction results on the CED benchmark for the second output signal. Comparison between true output y (black) and meta model’s predicted mean μ (blue), along with simulation error y−μ (red) and uncertainty region μ±3σ (shaded blue area). Most predictions lie within the confidence bounds, demonstrating robust zero-shot generalization to real data.
Benchmark
Method
RMSE
Training/Meta- inference time
WH
In-context
0.0014
5.91 s
dynoNet Forgione and Piga (2021b)
0.0017
1-60 min
LSTM Champneys et al. (2024)
0.0015
1-24 hr
ARX Champneys et al. (2024)
0.0434
1-60 min
Cascaded Tanks
In-context
0.429
0.22 s
dynoNet Forgione and Piga (2021b)
0.421
1-60 min
Table 2: Benchmarks: RMSEs and inference time over the test datasets for multiple methods.
Setting
Zero-shot
Scenario 1
Scenario 2
RMSE
1.249
0.242
0.115
Table 3: CSTR case study: RMSE without and with fine-tuning where only the input class changes (Scenario 1) and where both input and system class change (Scenario 2) during fine-tuning.
Figure 5: Training and validation curves for the meta model trained from scratch on the CSTR system class. The plot shows the evolution of the negative log-likelihood loss over training iterations for both the training (blue) and validation (red) datasets. A divergence between the training and validation losses is observed after approximately 4000 iterations, indicating overfitting.
Figure 6: Performance comparison on the CED benchmark when training a dynoNet model with and without synthetic data generated by the pre-trained meta model. Boxplots report the distribution of the R2 index over 100 Monte Carlo runs for both benchmark outputs. Using only real data (left) leads to higher variance and lower median R2 , while augmenting the training set (right) with meta model-generated synthetic trajectories significantly improves accuracy.
Is it possible to understand the intricacies of a dynamical system not solely from its input/output pattern, but also by observing the behavior of other systems within the same class? This central question drives the study presented in this paper. In response to this query, we introduce a novel paradigm for system identification, addressing two primary tasks: one-step-ahead prediction and multi-step simulation. Unlike conventional methods, we do not directly estimate a model for the specific system. Instead, we learn a meta model that represents a class of dynamical systems. This meta model is trained on a potentially infinite stream of synthetic data, generated by simulators whose settings are randomly extracted from a probability distribution. When provided with a context from a new system-specifically, an input/output sequence-the meta model implicitly discerns its dynamics, enabling predictions of its behavior. The proposed approach harnesses the power of Transformers, renowned for their in-context learning capabilities. For one-step prediction, a GPT-like decoder-only architecture is utilized, whereas the simulation problem employs an encoder-decoder structure. Initial experimental results affirmatively answer our foundational question, opening doors to fresh research avenues in system identification.
Marco Forgione, Filippo Pura, Dario Piga
IDSIA Dalle Molle Institute for Artificial Intelligence USI-SUPSI, Via la Santa 1, CH-6962 Lugano-Viganello, Switzerland.
Deep learning has proven highly effective for nonlinear system identification, but heavily parameterized neural networks are prone to overfitting in low-data regimes and lack reliable uncertainty quantification. The recently developed manifold meta-learning framework addresses the data efficiency problem by restricting the model parameters to a meta-learned low-dimensional manifold. However, that method is purely deterministic. We propose a fully probabilistic extension of the manifold meta-learning framework, based on amortized Variational Inference, where a generative prior over the low-dimensional parameter manifold is learned. During task-specific adaptation, we combine Maximum A Posteriori estimation with the Laplace approximation to yield a mathematically grounded posterior approximation. Evaluated on a static regression task and the Bouc--Wen dynamical system benchmark, the proposed approach achieves predictive accuracy comparable to its deterministic counterpart while successfully providing calibrated uncertainty bounds in severely low-data regimes.
Matteo Rufolo, Dario Piga, Marco Forgione
SUPSI-DTI-IDSIA, Dalle Molle Institute for Artificial Intelligence, Lugano, Switzerland.
Identifying linear time-invariant (LTI) dynamical systems is challenging when trajectories are short, noisy, or high-dimensional. Traditional system identification typically treats each system independently and cannot exploit shared structure across related systems. We propose PBML-LTI, a PAC-Bayesian meta-learning framework for few-shot LTI system identification that learns a transferable prior over task-specific dynamics while preserving task heterogeneity. Each task corresponds to an unknown LTI system, and the meta-learner uses training trajectories to learn a data-dependent prior over transition matrices. For a new system with limited data, PBML-LTI performs Bayesian adaptation under this prior to obtain a task-specific posterior, providing accurate estimates and principled uncertainty quantification. A key challenge is temporal dependence, since LTI trajectories violate the i.i.d. assumptions underlying most PAC-Bayes meta-learning analyses. We address this with a martingale PAC-Bayes analysis for dependent trajectory losses and derive a support-query predictive-risk bound that motivates a fit-KL meta-training objective. The bound clarifies the roles of empirical fit, posterior complexity, and prior quality in few-shot adaptation under sequential dependence. We further derive corollaries for transition-matrix recovery and multi-step trajectory prediction, connecting uncertainty-aware meta-identification with finite-sample guarantees for dependent dynamical data.
Chenfeng Huang, George Michailidis
Department of Statistics & Data Science University of California, Los Angeles