# ApproximateVI.jl

## What's this package for?

Use this package to approximate a posterior distribution with a Gaussian^{[1]}.

## Basic use

Currently, the main function of interest this package exposes is `VI`

. At the very minimum, the user needs to provide a function that codes the (unnormalised) log-posterior function.

Let's consider the following toy example:

```
using ApproximateVI
logp = exampleproblem1() # target log-posterior to approximate
x₀ = randn(2) # random initial mean for approximating Gaussian
q, logev = VI(logp, randn(2), S = 100, iterations = 10_000, show_every = 50)
# Plot target posterior, not log-posterior!
using Plots # must be indepedently installed.
x = -3:0.02:3
contour(x, x, map(x -> exp(logp(collect(x))), Iterators.product(x, x))', fill=true, c=:blues)
# Plot Gaussian approximation on top using red colour
contour!(x, x, map(x -> pdf(q,(collect(x))), Iterators.product(x, x))', color="red", alpha=0.2)
```

A plot similar to the one below should appear.

Options `S`

above specifies the number of samples to use in order to approximate the variational lower bound, i.e. the objective that which minimised produces the best Gaussian approximation. The higher `S`

is set the better, however, at a higher computational cost. The lower `S`

the faster the method, but the riskier to produce a biased solution, see Technical description.