Git Product home page Git Product logo

dropoutuncertaintyexps's Introduction

This is the code used for the uncertainty experiments in the paper "Dropout as a Bayesian Approximation: Representing Model Uncertainty in Deep Learning" (2015), with a few adaptions following recent (2018) feedback from the community (many thanks to @capybaralet for spotting some bugs, and @omegafragger for restructuring the code). This code is based on the code by José Miguel Hernández-Lobato used for his paper "Probabilistic Backpropagation for Scalable Learning of Bayesian Neural Networks". The datasets supplied here are taken from the UCI machine learning repository. Note the data splits used in these experiments (which are identical to the ones used in Hernández-Lobato's code). Because of the small size of the data, if you split the data yourself you will most likely get different and non-comparable results to the ones here.

Update (2018) We replaced the Bayesian optimisation implementation (which was used to find hypers) with a grid-search over the hypers. This is following feedback from @capybaralet who spotted test-set contamination (some train-set points, used to tune hypers which were shared across all splits, were used as test-set points in later splits). The new implementation iterates over the 20 splits, and for each train-test split it creates a new train-val split to tune hypers. These hypers are discarded between different train-test splits.

Below we report the new results using grid-search (new, with code in this updated repo) vs. results obtained from a re-run of the original code used in the paper which used Bayesian optimisation (paper, code in previous commit). Note that we report slightly different numbers for paper than in the previous commit, due to differences in package versions and hardware from 3 years ago. Further note the improved results in new on some datasets (mostly LL) due to proper grid-search (cases where BayesOpt failed). The other results agree with paper within standard error. If you used the code from the previous commits we advise you evaluate your method again following the stream-lined implementation here.

The experiments were run with Theano 0.8.2 and Keras 2.2.0. The baseline experiment (paper) was to simply run the previous "10x epochs one layer" code (can be found here) with the new versions of Theano and Keras. The new code (new) uses 10x training epochs and one layer as well, and trains models on the same 20 randomly generated train-test splits of the data. Each training set is further divided into an 80-20 train-validation split to find best hyperparameters, dropout rate and tau value through grid search. Finally, a network is trained on the whole training set using the best hyperparameters and is then tested on the test set. To run an experiment:

THEANO_FLAGS='allow_gc=False,device=gpu,floatX=float32' python experiment.py --dir <UCI Dataset directory> --epochx <Epoch multiplier> --hidden <number of hidden layers>

A summary of the results is reported below (lower RMSE is better, higher test log likelihood (LL) is better; note the ±X reported is standard error and not standard deviation).

Dataset BayesOpt RMSE (paper) Grid Search RMSE (new) BayesOpt LL (paper) Grid Search LL (new)
Boston Housing 2.83 ± 0.17 2.90 ± 0.18 -2.40 ± 0.04 -2.40 ± 0.04
Concrete Strength 4.93 ± 0.14 4.82 ± 0.16 -2.97 ± 0.02 -2.93 ± 0.02
Energy Efficiency 1.08 ± 0.03 0.54 ± 0.06 -1.72 ± 0.01 -1.21 ± 0.01
Kin8nm 0.09 ± 0.00 0.08 ± 0.00 0.97 ± 0.00 1.14 ± 0.01
Naval Propulsion 0.00 ± 0.00 0.00 ± 0.00 3.91 ± 0.01 4.45 ± 0.00
Power Plant 4.00 ± 0.04 4.01 ± 0.04 -2.79 ± 0.01 -2.80 ± 0.01
Protein Structure 4.27 ± 0.01 4.27 ± 0.02 -2.87 ± 0.00 -2.87 ± 0.00
Wine Quality Red 0.61 ± 0.01 0.62 ± 0.01 -0.92 ± 0.01 -0.93 ± 0.01
Yacht Hydrodynamics 0.70 ± 0.05 0.67 ± 0.05 -1.38 ± 0.01 -1.25 ± 0.01

dropoutuncertaintyexps's People

Contributors

omegafragger avatar yaringal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dropoutuncertaintyexps's Issues

Calculation of Predictive Variance?

Hello Yarin,

It looks like that the description of the outputs in your predict method of the net class does not match to the actual output.

def predict(self, X_test, y_test):
"""
Function for making predictions with the Bayesian neural network.
@param X_test The matrix of features for the test data
@return m The predictive mean for the test target variables.
@return v The predictive variance for the test target
variables.
@return v_noise The estimated variance for the additive noise.
"""

According to your publication, the predictive variance should be the sample variance of T stochastic forward passes plus the inverse model precision tau. (In your case, because the output y is a scalar, the variance are also scalars.) But it looks like that you did not add the inverse of tau when you are calculating the predictive "rmse". In addition, what is the estimate variance with additive noise?

Thank you very much.

Best,

Lei

Interpretation of the Predictive Uncertainty(Variance)

Hello Yarin,
Is there any way to interpret the obtained Predictive Uncertainty(Variance)? After computing the predictive variance i.e. the sample variance of T stochastic forward passes is there any way to calculate any threshold or cutoff value so that if the predictive variance is above that value we can say that the model is uncertain or below which it is certain about its prediction?
Uncertain if (predictive variance>=threshold) || Certain if (predictive variance<threshold)
something like this!
Thanks!

Different dropout rate between training and testing?

Any suggestions on how to implement the stochastic predictor with a different dropout rate than that which was used in training? I have tried to modify the layer attributes (.rate), but this does not change the output of the stochastic predictor function (built on the keras backend function).

How is the test log likelihood calculated?

I don't quite understand the calculation of the log-likelihood

# We compute the test log-likelihood
ll = (logsumexp(-0.5 * self.tau * (y_test[None] - Yt_hat)**2., 0) - np.log(T) 
    - 0.5*np.log(2*np.pi) + 0.5*np.log(self.tau))
test_ll = np.mean(ll)

why is the logsumexp used? and why are the predictive variances not used?

I tried to calculate the test log likelihood like this:

from scipy.stats import norm
pred_var = np.var(Yt_hat, axis = 0) + 1 / self.tau
ll = []
for i in range(y_test.shape[0]):
    ll.append(norm.logpdf(y_test[i][0], MC_pred[i][0], np.sqrt(pred_var[i][0])))
new_test_ll = np.mean(ll)

And it usually generates slightly worse log likelihood. For example, using the concrete dataset, with split id set to 19, the log likelihood given by the original code is -3.17, while the log likelihood given by the above code is -3.25.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.