Skip to content

example: add surrogate modeling demonstration with scikit-learn#308

Open
Nithurshen wants to merge 5 commits intomesa:mainfrom
Nithurshen:feat/surrogate-modeling
Open

example: add surrogate modeling demonstration with scikit-learn#308
Nithurshen wants to merge 5 commits intomesa:mainfrom
Nithurshen:feat/surrogate-modeling

Conversation

@Nithurshen
Copy link

Summary

This PR adds a new example, surrogate_modeling, which demonstrates how to integrate Mesa with Scikit-learn to create an emulator (surrogate model). This allows users to approximate the behavior of a complex Agent-Based Model (ABM) across a high-dimensional parameter space using only a small number of actual simulation runs.

Motive

Computational expense is a common bottleneck in ABM research, especially during calibration or sensitivity analysis. This PR offloads these concerns to Scikit-learn and Scipy to provide users with a robust workflow for efficient experimentation.

Implementation

  • The example is self-contained in examples/surrogate_modeling/ to demonstrate integration without modifying the core library.
  • Avoided batch_run and DataCollector in favor of manual Python loops to align with Mesa 4.0 roadmap.

Usage Examples

Users can run the entire pipeline from sampling to prediction with a single command:

python -m examples.surrogate_modeling.analysis
Running simulations for training data...
Surrogate model trained.

Prediction for {'n': 65, 'width': 22, 'height': 22}:
Approximated Gini: 0.6262

Additional Notes

  • Added a new optional dependency group surrogate in pyproject.toml including scikit-learn.

Copy link
Member

@EwoutH EwoutH left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool applications. Clearly shows something new.

@quaquel do you have an opinion on surrogate modelling for ABMs? Has its place in high SNR-models with stable and continuous outcome landscapes, but tricky and used with caution?

Maybe best used as an evaluation tool. With the quality of the surrogate model fit as the main outcome.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be nice as a Jupyter notebook, with maybe a few visualisations (but don't overdo it)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added analysis.ipynb

This example requires the `latest` version of Mesa and additional machine learning dependencies:

```bash
pip install mesa scikit-learn scipy pandas
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scipy and pandas are already dependencies of mesa

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need the pyproject.toml the readme already list the dependencies.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@tpike3
Copy link
Member

tpike3 commented Jan 29, 2026

This is really cool @Nithurshen thanks! Could you add a brief description to the repo readme in other examples

@Nithurshen Nithurshen requested review from EwoutH and tpike3 January 30, 2026 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants