smart_predict_optimize is a Python implementation of the "Smart, Predict then Optimize" (Elmachtoub and Grigas, 2021) framework that aims to compare the computational efficiency and performance of optimizing a linear SPO model with a Linear Program versus Stochastic Gradient Descent.
All packages that are used can be found in requirements.txt. To install all packages, run the following:
pip install requirements.txt
Contains the majority of the code. Contains functions and classes to:
- Generate synthetic data and formulate it into a Shortest Path problem.
- Compute SPO and SPO+ loss.
- Solve a shortest path problem
- Fit a linear model to predict the parameters of a shortest path problem with the SPO+ loss function via a Linear Program
- Fit a linear model to predict the parameters of a shortest path problem with the SPO+ loss function via Gradient Descent
Generates data and runs experiments using functions and classes from HelperFunction.py. Generates a .pkl file (SPOresultsAllVars.pkl) of the experiment output.
Visualizes the results of the experiments generated from Experiments.py. Reads SPOresultsAllVars.pkl and writes output plots to the "plots" directory.
To reproduce the plots, follow the steps below:
- Generate experiment data. Note that running this code will take a significant amount of time (20+ hours) on standard consumer hardware.
python Experiments.py
- Generate plots by running each cell in ResultsAnalysis.ipynb.
Alternatively plots can be recreated by using the SPOresultsAllVars.pkl file that is in this repository.
This project is completed and not actively being worked on.