Skip to main content

Predicting how complex systems will respond to interventions.

Project description

🌀 Interfere

PyPI Version License: MIT

A Python package for modeling and predicting the response of complex dynamic systems to interventions.

Overview

Interfere is a research-oriented Python package that addresses a fundamental question in complex systems: When can we predict how complex systems will respond to interventions? This package provides tools for:

  • Modeling dynamic nonlinear multivariate stochastic systems.
  • Simulating and analyzing how such systems respond to interventions.
  • Generating complex dynamic counterfactuals.
  • Studying causal relationships in complex systems.

Interfere Benchmark Dataset (Download)

Sixty dynamic systems and intervention responses.

The image above depicts the uninterrupted trajectories of sixty dynamic models in blue and their response to a particular intervention in red. This data is available for download as the Interfere Benchmark 1.1.1. It can be used to benchmark a forecasting method's ability to predict the response of a dynamic system to interventions.

Installation

From GitHub

pip install git+https://github.com/djpasseyjr/interfere

From Local Clone

git clone https://github.com/djpasseyjr/interfere.git
cd interfere
pip install .

Quick Start

The Interfere package is designed around three main tasks: counterfactual simulation, predictive method optimization, and prediction. Here's a complete example using the SINDy (Sparse Identification of Nonlinear Dynamics) method:

1. Counterfactual Simulation

First, let's create and simulate a dynamic model:

import numpy as np
import interfere
import optuna

# Set up simulation parameters
initial_cond = np.random.rand(3)
t_train = np.arange(0, 10, 0.05)
dynamics = interfere.dynamics.Belozyorov3DQuad(sigma=0.5)

# Generate trajectory
sim_states = dynamics.simulate(t_train, initial_cond)

Original System Trajectory

2. Applying an Intervention

Next, we'll apply an intervention to one component of the system:

# Time points for the intervention simulation
test_t = np.arange(t_train[-1], 15, 0.05)

# Intervention initialization
intervention = interfere.SignalIntervention(iv_idxs=1, signals=np.sin)

# Simulate intervention
interv_states = dynamics.simulate(
    test_t,
    prior_states=sim_states,
    intervention=intervention,
)

System Trajectory with Intervention

3. Model Optimization and Prediction

Using the generated data, we can run hyperparameter optimization with a forecasting method. All forecasting methods come with reasonable hyperparameter ranges built in.

# Select the SINDy method for hyperparameter optimization.
method_type = interfere.SINDy

# Create an objective function that aims to minimize cross validation error
# over different hyper parameter configurations for SINDy
cv_obj = interfere.CrossValObjective(
    method_type=method_type,
    data=sim_states,
    times=t_train,
    train_window_percent=0.3,
    num_folds=5,
    exog_idxs=intervention.iv_idxs,
)

# Run the study using optuna.
study = optuna.create_study()
study.optimize(cv_obj, n_trials=25)

# Collect the best hyperparameters into a dictionary.
best_param_dict = study.best_params

4. Intervention Response Prediction

Using the best parameters found, we can fit the forecasting method to pre-intervention data and then make a prediction about how the system will respond to the intervention.

# Initialize SINDy with the best perfoming parameters.
method = interfere.SINDy(**study.best_params)

# Use an intervention helper function to split the pre-intervention data
# into endogenous and exogenous columns.
Y_endog, Y_exog = intervention.split_exog(sim_states)

# Fit SINDy to the pre-intervention data.
method.fit(t_train, Y_endog, Y_exog)

# Use the inherited interfere.ForecastingMethod.simulate() method
# To simulate intervention response using SINDy
pred_traj = method.simulate(
    test_t, prior_states=sim_states, intervention=intervention
)

Predicted vs Actual Intervention Response

The SINDy method identifies the underlying dynamics of the system using sparse regression techniques, making it particularly effective for discovering interpretable mathematical models of complex systems.

Dependencies

Core dependencies:

  • matplotlib
  • networkx
  • numpy
  • optuna
  • pyclustering
  • pysindy
  • scikit-learn
  • statsmodels
  • typing_extensions

Optional dependencies for additional methods:

  • neuralforecast
  • statsforecast
  • sktime

Example

The package can be used to simulate and analyze how systems respond to interventions. For example, it can model the effect of stochasticity on intervention response forecasting:

Stochastic vs Deterministic Systems

Documentation

For a more detailed explanation of the purpose of the package refer to paper.pdf.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Citation

If you use this software in your research, please cite:

@article{passey2024interfere,
  title={Interfere: Intervention Response Simulation and Prediction for Stochastic Nonlinear Dynamics},
  author={Passey, D. J. and Mucha, Peter J.},
  journal={arXiv preprint},
  year={2025}
}

Contact

  • Author: DJ Passey (djpassey@unc.edu)
  • Institution: University of North Carolina at Chapel Hill

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

interfere-1.0.1.tar.gz (90.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

interfere-1.0.1-py3-none-any.whl (110.9 kB view details)

Uploaded Python 3

File details

Details for the file interfere-1.0.1.tar.gz.

File metadata

  • Download URL: interfere-1.0.1.tar.gz
  • Upload date:
  • Size: 90.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.6

File hashes

Hashes for interfere-1.0.1.tar.gz
Algorithm Hash digest
SHA256 179c2110ad7f9e9c00b55c3fb7a23e2b115dc95a42a992e4ddd9a463876a151c
MD5 d37273a1738802c3cbb6a023334ecc72
BLAKE2b-256 7e3e7687fccf11b9bb716efc454855feddfa353b2a615942845366c5ddd074bd

See more details on using hashes here.

File details

Details for the file interfere-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: interfere-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 110.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.6

File hashes

Hashes for interfere-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a79e2982b05d8054a2536a52d24389008423fe00b8e8e5e369deb8dbbe54ecdb
MD5 8fb8b1fc820e0e09f2faae45192b607e
BLAKE2b-256 5b209e80fe11da54183d6788d55559f37f32227a1f22c5bbf0d5a88b25e19d33

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page