Code for Bayesian Adaptation for Covariate Shift (BACS)

### Model Training
See the folder training_scripts/ for scripts to run SWAG and save the models/posteriors 
to be finetuned for the test distrbituions.


### Adapting to new test distributions
To finetune single models on various datasets, see
- finetune_swag_cifar.py (CIFAR10/100-C)
- finetune_swag_digits.py (SVHN -> MNIST)
- finetune_swag_stl10.py (CIFAR10 -> STL10)
- finetune_swag_imagenet.py (ImageNet-C)

To compute results for BACS and other ensembled methods, see
- finetune_swa_ensmbles_cifar.py
- finetune_swa_ensmbles_digits.py
- finetune_swa_ensmbles_stl10.py

For BACS and other ensembled methods on ImageNet-C, we instead use
= compute_swag_imagenet_marginals.py
to aggregate predictions saved from running finetune_swag_imagenet.py over different models.

For online experiments, see
- finetune_swag_cifar_online.py 
- finetune_swag_imagenet_online.py
to finetune the model, collect statistics for the non-ensembled methods, and save the logits for use in computing the marginalized predictions.

After generating the logits from each model, see
- compute_swag_online_marginals.py (for CIFAR10/100-C online experiments)
- compute_swag_imagenet_online_marginals.py (for ImageNet-C online experiments)
to aggregate predictions and compute the marginalized predictions for BACS, ensembles, and ensembles with batchnorm adaptation.

To adapt models using BACS, set the use_swag_posterior flag to True and set swag_posterior_weight argument, and marginalize over different models. To adapt models with TENT, do not set the use_swag_posterior flag and instead set he adapt_bn_only flag.
