This Repo contains the Numerics of our paper "Statistical guarantees for stochastic Metropolis-Hastings".
This includes an implementation of a stochastic Metropolis Adjusted Langevin Algorithm (MALA) drawing auxiliary variables from a Bernoulli distribution
For a simple 1D Regression example
at function parameters
We propose adapting the loss to
which ensures sampling from a marginal invariant distribution with reduced inverse temperature of
src/MALA.py
defines our MALA implementation and can by used in exchange for your usual PyTorch Optimizersrc/util
contains the risk implementations, including our corrected risk term, as well as the model definitionsrc/datasets
contains toy data und Bernoulli-sampling Dataloadersrc/uncertimators
contains wrappers around MALA and propabilistic training for easier use
Minimal working examples of the data generation, Neural Network definition and weight sampling with MALA are provided in the first half ofStochasticMH.ipynb
. The second half of the Notebook contains the plotting scripts for the figures displayed in the paper.
To generate the weight samples requiered for plotting StochasticMH.py
and StochasticMH_Adam_baseline.py
need to be executed for different
-
folder
: Path to the directory where the data is loaded from (if existent) and samples are saved. -
n_points
: Number of data points$n$ . -
rho
: Batchsize$\rho$ . -
lambda_factor
: Temperature parameter as specified in the paper. -
sigma_data
: Standard deviation of Gaussian noise added to the data in$y$ -direction. -
num_dataloader_workers
: Number of threats used for dataloading.default=0
For more details, we refer to the paper
@unpublished{bieringer2023statistical,
title={Statistical guarantees for stochastic {M}etropolis-{H}astings},
author={Bieringer, Sebastian and Kasieczka, Gregor and Steffen, Maximilian F and Trabs, Mathias},
eprint = "2310.09335",
archivePrefix = "arXiv",
primaryClass = "stat.ML",
month={10},
year={2023},
}.
Building on this work we developed AdamMCMC. An MCMC tool for weight sampling in Neural Networks leveraging the advantages of the Adam optimizer.