This is a repository for educational resources, examples, and utils related to Bayesian machine learning.
- python >= 3.5
- numpy >= 1.11
- scipy >= 0.19
- keras >= 2
- pytest and pytest_runner for tests
pip install git+ssh://git@192.168.0.235:10022/ml_library/bayesian.git
docs/bayesian-resources.ipynb: a Jupyter notebook with publications, tutorials and blog posts on Bayesian learningsrc/bayesian: a collection of utilssrc/bayesian/callbacks.py: Keras callback for testing MC dropout during trainingsrc/bayesian/metrics.py: 'some uncertainty metrics for bayesian models'src/bayesian/objectives.py: 'optimization objectives for heteroscedatic uncertainty'src/src/bayesian/droupout_bayesian_model.py: a class derived from Keras's Model with predict_stochastic method (MC droupout)src/bayesian/utils.py: various helper functionssrc/examples: training a bayesian model for univariate regression problem (bayesian-regr.ipynb) and MNIST classification (bayesian-classification.ipynb). Some simple usage examples, details in Examples sectiontests/pytest integral tests (runs examples with minimal parameters)
ModelTest is is a validation callback, can be used as a callback to Keras fit function to compare MC dropout predictions accuracy with regular predictions.
Can be used on a regular Keras model, but monkey-patches it to have predict_stochastic method (from BayesianDropoutModel)
Usage shown in python src/examples/callback.py
Selected prediction quality metrics for classification and regression
bayesian_mean_squared_errorfor regression tasks (from https://arxiv.org/pdf/1703.04977.pdf)bayesian_categorical_crossentropy_originalfor classification tasks (from https://arxiv.org/pdf/1703.04977.pdf)bayesian_categorical_crossentropy_elufor classification tasks (weighted metric from https://medium.com/towards-data-science/building-a-bayesian-deep-learning-classifier-ece1845bc09)
Keras Model subclass that automatically creates the predict_stochastic method if needed (for MC dropout).
Usage shown in scripts and notebooks in python src/examples/
Hint: every example has a built it help, type python examples/<script>.py -h.
Note that examples should be run as submodules, because the imported code is in bayesian directory
python3 -m src.examples.callback --epochs=100 -T=50 -vunivariate regression with epistemic uncertainty using MC dropoutpython3 -m src.examples.bayesian_regression_epistemic --epochs=100 -T=50 -vsame thing, but using BayesianDropoutModel instead of callback.python3 -m src.examples.bayesian_regression_heteroscedastic --epochs=100 -T=50 -valeatoric uncertainty using extra output for predicted variance (https://arxiv.org/pdf/1703.04977.pdf)python3 -m src.examples.bayesian_classification_heteroscedastic --epochs=5 -T=50 -valeatoric uncertainty for classification using extra output for predicted variance used to generate noise in logits space (https://arxiv.org/pdf/1703.04977.pdf)