This zip file contains the code for Variational Inference with Gaussian Score Matching paper. 

## Requirements
The code is in python and has following requirements (we give version numbers it has been tested with, anything higher should be compatible):
numpy 1.23.1
matplotlib 3.6.1
tensorflow 2.10.0
tensorflow_probability 0.18.0

--------------------------------
## Code structure:
We describe content of both folders here.

1) src
Folder src/ has the source code. Relevant files are:
Our implementation of BBVI is in src/bbvi.py
Our implementation of GSM is in src/gsm.py

Other files have auxillary functions for measuring divergences to monitor and utility functions for plotting. 

2) scripts
Folder scripts/ has scripts to run experiments. We provide scripts to replicate results of our synethetic experiments with 2 differences:
a) the scripts run only 1 experiment instead of running 10 runs and taking averages. 
b) the scripts run experiment only for one parameter setting, but it can be run for different settings with command line arguments. Please see arguments for each file in the code or with help. 

The output i.e. the fit distribution, divergence metrics monitored in the run are saved in created folder './scripts/tmp/<foldername>/'
where <foldername> is determined in folder-path.py based on experimental setup, algorithm setup and seed. 

For convenience, the code prints path of diagnostic figures of interest.

--------------------------------
## Running experiments

tl;dr-- execute main.py with
>> python -u main.py


## Details on individual experiemnts

Experiment in Fig. 2 is replicated with scripts/frgaussian.py 
-- relevant command line arguments to setup the experiment are: -D (the dimensionality), -r (rank of covariance matrix, in the paper we show results for r=D so this needs to be set), --noise (we show results in the paper for default noise =0.01)

Experiment in Fig. 3 is replicated with scripts/illcondfrg.py 
-- relevant command line arguments to setup the experiment are: -D (the dimensionality), -c (condition number of the covariance matrix), --noise (we show results in the paper for default noise =0.01)

Experiment in Fig. 4 is replicated with scripts/nongaussian.py 
-- relevant command line arguments to setup the experiment are: -D (the dimensionality), -skewness (skewness of the transformation), --tailw (weight in the tails of the transformed distribution)


Figure 5 and 6
--- at the moment, we have been unable to provide executable scripts for these as they rely on external codebase such as Stan, Bridgestan; compiling and setting paths for these and interfacing them with tensorflow.