Skip to content

Commit 786271c

Browse files
authored
Merge pull request #1285 from taku-y/advi_doc
DOC Modify docstring in advi().
2 parents a53728e + 2136347 commit 786271c

File tree

1 file changed

+33
-7
lines changed

1 file changed

+33
-7
lines changed

pymc3/variational/advi.py

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11

22
'''
3-
Created on Mar 12, 2011
4-
5-
@author: johnsalvatier
3+
(c) 2016, John Salvatier & Taku Yoshioka
64
'''
75
import numpy as np
86
from ..blocking import DictToArrayBijection, ArrayOrdering
@@ -19,7 +17,7 @@
1917
from pymc3.sampling import NDArray
2018
from pymc3.backends.base import MultiTrace
2119

22-
__all__ = ['advi']
20+
__all__ = ['advi', 'sample_vp']
2321

2422
ADVIFit = namedtuple('ADVIFit', 'means, stds, elbo_vals')
2523

@@ -32,7 +30,29 @@ def check_discrete_rvs(vars):
3230

3331
def advi(vars=None, start=None, model=None, n=5000, accurate_elbo=False,
3432
learning_rate=.001, epsilon=.1, random_seed=20090425, verbose=1):
35-
"""Run ADVI.
33+
"""Perform automatic differentiation variational inference (ADVI).
34+
35+
This function implements the meanfield ADVI, where the variational
36+
posterior distribution is assumed to be spherical Gaussian without
37+
correlation of parameters and fit to the true posterior distribution.
38+
The means and standard deviations of the variational posterior are referred
39+
to as variational parameters.
40+
41+
The return value of this function is an :code:`ADVIfit` object, which has
42+
variational parameters. If you want to draw samples from the variational
43+
posterior, you need to pass the :code:`ADVIfit` object to
44+
:code:`pymc3.variational.sample_vp()`.
45+
46+
The variational parameters are defined on the transformed space, which is
47+
required to do ADVI on an unconstrained parameter space as described in
48+
[KTR+2016]. The parameters in the :code:`ADVIfit` object are in the
49+
transformed space, while traces returned by :code:`sample_vp()` are in
50+
the original space as obtained by MCMC sampling methods in PyMC3.
51+
52+
The variational parameters are optimized with a modified version of
53+
Adagrad, where only the last (n_window) gradient vectors are used to
54+
control the learning rate and older gradient vectors are ignored.
55+
n_window denotes the size of time window and fixed to 10.
3656
3757
Parameters
3858
----------
@@ -58,9 +78,15 @@ def advi(vars=None, start=None, model=None, n=5000, accurate_elbo=False,
5878
ADVIFit
5979
Named tuple, which includes 'means', 'stds', and 'elbo_vals'.
6080
61-
'means' and 'stds' include parameters of the variational posterior.
62-
"""
81+
'means' is the mean. 'stds' is log of the standard deviation.
82+
'elbo_vals' is the trace of ELBO values during optimizaiton.
6383
84+
References
85+
----------
86+
.. [KTR+2016] Kucukelbir, A., Tran, D., Ranganath, R., Gelman, A.,
87+
and Blei, D. M. (2016). Automatic Differentiation Variational Inference.
88+
arXiv preprint arXiv:1603.00788.
89+
"""
6490
model = modelcontext(model)
6591
if start is None:
6692
start = model.test_point

0 commit comments

Comments
 (0)