Counterexample-guided techniques to provably enforce and train a neural network with monotonicity constraints.
Installation | Onboarding a Neural Network | Monotonicity Verification · Monotonic Envelope Predictions · Training with Monotonicity Constraints | Paper · License (MIT)
- Install
python
>= 3.8.3, Installpip
>= 20.1.1
-
Setup a Virtual Environment
pip3 install virtualenv && python3 -m venv comet && source comet/bin/activate
-
Install Packages
pip install matplotlib pandas pillow tensorflow scikit-learn sexpdata tensorflow
-
Install Solvers
pip install z3-solver
Download optimathsat (http://optimathsat.disi.unitn.it/pages/download-js.html) and add it to your environment path. Check the installation by runningoptimathsat -version
To run on example networks skip ahead. To onboard your neural network
-
You need a trained baseline ReLU neural network model (model.h5), weights, and bias as csv files.
-
cp templates/template.txt configurations/<dataset_name>.txt
and configure COMET for your dataset. -
cp templates/DeepModel_Template.py src/Models/DeepModel_<dataset_name>.py
and fill in the code blocks (#TODO: CODE BLOCK) inmake_data
function for COMET to interact with your model.
Once you have set up your neural network, you can verify if it is monotonic using:
python src/COMET.py configurations/<config_file>.txt --mode verifier
.
This could take a while depending on the size of the network.
If you are interested in using the monotonic envelope for predictions, set up the configuration file, fill in the code blocks in DeepModel_<dataset_name>.py and run:
python src/COMET.py configurations/<config_file>.txt --mode envelope --test_file <path to test data csv>
To carry out counterexample-guided training, set up the configuration file, fill in the code blocks in DeepModel_<dataset_name>.py and run:
python src/COMET.py configurations/<config_file>.txt --mode learner
CLICK for an example
-
You can find pre-trained model, test/train.csv and weight/bias files in examples/Auto-MPG/
-
You can find the configured file in configurations/auto-mpg.txt
-
You can find the DeepModel_AutoMPG.py in src/Models/
-
The output after running
python src/COMET.py configurations/auto-mpg.txt --mode verifier
is:
- The output after running
python src/COMET.py configurations/auto-mpg.txt --mode envelope --test_file ./examples/Auto-MPG/test.csv
is:
- The output after running
python src/COMET.py configurations/auto-mpg.txt --mode learner
is: