Machine Learning Sandwich for Agent-Based Models

Automatic calibration and post-processing adjustment for ABMs

George G. Vega Yon, Ph.D.

The University of Utah

Motivation

Motivation: Agent-Based Models in Science and Policy

  • Agent-Based Models [ABMs] are an important tool for scientific research and policy-making:

    • For scenario modeling: “What if we do X?”
    • For forecasting: “How many cases will we have in the next week?”
  • Calibration can be time-consuming: grid search, Markov models, etc.

  • There’s no consensus on the best calibration approach.

  • ABMs (and models in general) are limited in their predictive power.

Schematic of compartmental and ABMs used by the US Centers for Disease and Control Prevention during a Measles Outbreak Response CDC (2024).

Machine Learning Sandwich for ABMs

Using ML for Calibration

Using ML for Calibration

Using ML for Calibration: A proposal

  1. Specify the model to be calibrated, for example, a SIR model. We will denote the model \(\mathcal{M}: \boldsymbol{\theta} \to \mathbf{Y}\).

  2. Identify the model parameters \(\boldsymbol{\theta}\) that will be calibrated. In the case of a SIR model, we may want to specify the contact, infection, and recovery rates.

  3. Simulate the model \(N\) times drawing \(\boldsymbol{\theta}\) from a prior distribution. The simulation procedure follows: For \(i \in \{1,\dots,N\}\) do

    • Draw \(\boldsymbol{\theta}_i \sim \Theta_{\mbox{prior}}\); with a uniform distribution when no prior information is available.
    • Draw \(y_i\) from \(\mathcal{M}(\boldsymbol{\theta}_i)\) and store it.
    • next simulation.

    We will have our training dataset \(T\equiv\left\{\boldsymbol{\theta}_i, y_i\right\}_{i=1}^N\).

  4. Finally, we can use the training set to generate the mapping \(\mathcal{C}: \boldsymbol{Y} \to \boldsymbol{\theta}\).

With the calibrated model \(\mathcal{C}\), we can answer the question “What parameters \(\theta\) better fit the observed data?”.

Mechanistic Machine Learning

Machine Learning is Broken

Mechanistic Machine Learning

Mechanistic Machine Learning [MechML]–a.k.a. theory-guided data science/machine learning: A hybrid between theory and data-driven prediction.

Mechanistic models

  • Inference-driven (causality).
  • Great for small datasets.
  • Knowledge beyond the observed data.

Machine Learning

  • Data-driven (prediction).
  • Great for big data.
  • Finds hidden knowledge in observed data.

ML can help explain what theory hasn’t… but we still need theory (Lazer et al. 2014)!

MechML: State-of-the-art

Warning

  1. Mechanistic Machine Learning is not domain-knowledge-aided feature engineering. You need a whole other model to complement the ML algorithm.

  2. This isn’t just an ML ensemble; you must have an ML and a Mech model.

How to MechML?

How to MechML: Correcting prediction errors

Train a model that predicts ABM forecast errors. The model takes the following form:

\[ Loss(\boldsymbol{\omega}): \left\{\mathcal{M}(\boldsymbol{\theta}), \boldsymbol{x}\right\} \to \widehat{\boldsymbol{\varepsilon}} \equiv \left\lVert \widehat{\boldsymbol{\varepsilon}} - f\left(\boldsymbol{\omega}, \mathcal{M}(\boldsymbol{\theta}), \boldsymbol{x}\right)\right\rVert{}_p, \]

where \(\widehat{\boldsymbol{\varepsilon}}\equiv \left(\mathcal{M}(\boldsymbol{\theta}) - y_{obs}\right)\) ABM forecast error, \(\boldsymbol{y}_{obs}\) is the observed data, \(f(\cdot)\) is a non-linear function, \(\boldsymbol{x}\) are additional features for the model, and \(\boldsymbol{\omega}\) is an array of weights associated with the ML o predict \(\boldsymbol{\varepsilon}\).

How to MechML: Predictions as feature

Use the ABM predictions as a feature in the ML model. The model takes the following form:

\[ Loss(\boldsymbol{\omega}) \equiv \left\lVert \boldsymbol{y}_{obs} - f\left(\boldsymbol{\omega}, \mathcal{M}(\boldsymbol{\theta}), \boldsymbol{x}\right)\right\rVert{}_p, \]

How to MechML: Mechanistic penalty

Use a mechanistic penalty in the ML loss function. The model takes the following form:

\[ Loss(\boldsymbol{\omega}) \equiv \left\lVert \boldsymbol{y}_{obs} - f\left(\boldsymbol{\omega}, \boldsymbol{x}\right)\right\rVert{}_p + \lambda \left\lVert f\left(\boldsymbol{\omega}, \boldsymbol{x}\right) - \mathcal{M}(\theta)\right\rVert{}_p, \]

where \(\lambda\) is a hyperparameter that controls the weight of the mechanistic penalty.

Preliminary results in calibration

Calibration

Susceptible-Infected Recovered model:

  • Agent Based Model with epiworldR.
  • Fully connected graph (everyone is connected to everyone).
  • We ran 20,000 simulations
  • Parameters of interest:
    • Initial state
    • Contact rate
    • Probability of transmission
    • Probability of recovery

We trained a convolutional neural network to build our calibrator:

\[ \mathcal{C}: \text{Epicurves} \to \boldsymbol{\theta} \]

Where \(\boldsymbol{\theta} = \left[\text{Init. state}\text{Contact Rate}, \text{P(transmit)}, \text{P(recover)}\right]\)

Calibration : CNN Architecture

Calibration : Model fit

Calibration : Example

Parameter Predicted Truth
Init. state 0.01 0.01
Contact Rate 6.29 8.00
P(transmit) 0.33 0.30
P(recover) 0.33 0.30
  • Simple model does an OK job recovering the parameters.
  • Non-unique solution, e.g., lower contact rate and higher transmission rate.
  • Model does not deal with important factors:
    • What if the number of agents is 1,000,000?
    • What if there’s a policy/behavior change?

Example results in prediction

Prediction: Model of gene functions (0/1)

Example model by speaker using mechanistic machine learning to improve accuracy in prediction of gene functions.

  • Used a mechanistic model of evolution of gene functions to predict presence/absence of them.
  • ML model: logistic regression featuring a large number of parameters.
  • MechML: use the mechanistic predictions as features in the logit.

Machine Learning Sandwich for ABMs (repeat)

Discussion

  • ABMs are a powerful tool for research and policy analysis.

  • Overall, calibration and prediction are challenging tasks; the latter, even for advanced ML models.

  • We propose a method that leverages the best of both worlds: mechanistic models and machine learning: Machine Learning Sandwich for ABM Models.

  • The calibration step leverages artifical data for training.

  • The forecasting step is addressed using Mechanistic Machine Learning [MechML]. At least three ways to apply it:

    • ML to correct for systematic biases.

    • Mech predictions as features in an ML algorithm.

    • A Mech penalty embedded in the ML Loss function.

  • Finally, we presented preliminary results on calibration of an SIR model and predictions using MechML for gene function prediction.

Thank you!

George G. Vega Yon, Ph.D.
The University of Utah
https://ggvy.cl

References

Al taweraqi, Nada, and Ross D. King. 2022. “Improved Prediction of Gene Expression Through Integrating Cell Signalling Models with Machine Learning.” BMC Bioinformatics 23 (1): 323. https://doi.org/10.1186/s12859-022-04787-8.
Baker, Ruth E., Jose-Maria Peña, Jayaratnam Jayamohan, and Antoine Jérusalem. 2018. “Mechanistic Models Versus Machine Learning, a Fight Worth Fighting for the Biological Community?” Biology Letters 14 (5): 20170660. https://doi.org/10.1098/rsbl.2017.0660.
CDC. 2024. “Behind the Model: How Disease Modeling Supported Decision-Making in a Local Measles Outbreak Response.” Behind the Model. July 2, 2024. https://www.cdc.gov/cfa-behind-the-model/php/data-research/local-measles-disease-modeling/index.html.
Compagni, Riccardo Delli, Zhao Cheng, Stefania Russo, and Thomas P. Van Boeckel. 2022. “A Hybrid Neural Network-SEIR Model for Forecasting Intensive Care Occupancy in Switzerland During COVID-19 Epidemics.” PLOS ONE 17 (3): e0263789. https://doi.org/10.1371/journal.pone.0263789.
Gaw, Nathan, Andrea Hawkins-Daarud, Leland S. Hu, Hyunsoo Yoon, Lujia Wang, Yanzhe Xu, Pamela R. Jackson, et al. 2019. “Integration of Machine Learning and Mechanistic Models Accurately Predicts Variation in Cell Density of Glioblastoma Using Multiparametric MRI.” Scientific Reports 9 (1): 10063. https://doi.org/10.1038/s41598-019-46296-4.
Ginsberg, Jeremy, Matthew H. Mohebbi, Rajan S. Patel, Lynnette Brammer, Mark S. Smolinski, and Larry Brilliant. 2009. “Detecting Influenza Epidemics Using Search Engine Query Data.” Nature 457 (7232): 1012–14. https://doi.org/10.1038/nature07634.
Jia, Xiaowei, Jared Willard, Anuj Karpatne, Jordan S. Read, Jacob A. Zwart, Michael Steinbach, and Vipin Kumar. 2021. “Physics-Guided Machine Learning for Scientific Discovery: An Application in Simulating Lake Temperature Profiles.” ACM/IMS Transactions on Data Science 2 (3): 1–26. https://doi.org/10.1145/3447814.
Jorner, Kjell, Tore Brinck, Per-Ola Norrby, and David Buttar. 2021. “Machine Learning Meets Mechanistic Modelling for Accurate Prediction of Experimental Activation Energies.” Chemical Science 12 (3): 1163–75. https://doi.org/10.1039/D0SC04896H.
Kandula, Sasikiran, and Jeffrey Shaman. 2019. “Reappraising the Utility of Google Flu Trends.” PLOS Computational Biology 15 (8): e1007258. https://doi.org/10.1371/journal.pcbi.1007258.
Lazer, David, Ryan Kennedy, Gary King, and Alessandro Vespignani. 2014. “The Parable of Google Flu: Traps in Big Data Analysis.” Science 343 (6176): 1203–5. https://doi.org/10.1126/science.1248506.
Pearl, Judea. 2019. “The Seven Tools of Causal Inference, with Reflections on Machine Learning.” Communications of the ACM 62 (3): 54–60. https://doi.org/10.1145/3241036.
von Rueden, Laura, Sebastian Mayer, Katharina Beckh, Bogdan Georgiev, Sven Giesselbach, Raoul Heese, Birgit Kirsch, et al. 2023. “Informed Machine Learning A Taxonomy and Survey of Integrating Prior Knowledge into Learning Systems.” IEEE Transactions on Knowledge and Data Engineering 35 (1): 614–33. https://doi.org/10.1109/TKDE.2021.3079836.
Wang, Lijing, Jiangzhuo Chen, and Madhav Marathe. 2020. TDEFSI: Theory-guided Deep Learning-based Epidemic Forecasting with Synthetic Information.” ACM Transactions on Spatial Algorithms and Systems 6 (3): 15:1–39. https://doi.org/10.1145/3380971.
Willard, Jared, Xiaowei Jia, Shaoming Xu, Michael Steinbach, and Vipin Kumar. 2022. “Integrating Scientific Knowledge with Machine Learning for Engineering and Environmental Systems.” ACM Computing Surveys, March, 3514228. https://doi.org/10.1145/3514228.
Zampieri, Guido, Supreeta Vijayakumar, Elisabeth Yaneske, and Claudio Angione. 2019. “Machine and Deep Learning Meet Genome-Scale Metabolic Modeling.” PLOS Computational Biology 15 (7): e1007084. https://doi.org/10.1371/journal.pcbi.1007084.