1
1
2
2
'''
3
- Created on Mar 12, 2011
4
-
5
- @author: johnsalvatier
3
+ (c) 2016, John Salvatier & Taku Yoshioka
6
4
'''
7
5
import numpy as np
8
6
from ..blocking import DictToArrayBijection , ArrayOrdering
19
17
from pymc3 .sampling import NDArray
20
18
from pymc3 .backends .base import MultiTrace
21
19
22
- __all__ = ['advi' ]
20
+ __all__ = ['advi' , 'sample_vp' ]
23
21
24
22
ADVIFit = namedtuple ('ADVIFit' , 'means, stds, elbo_vals' )
25
23
@@ -32,7 +30,29 @@ def check_discrete_rvs(vars):
32
30
33
31
def advi (vars = None , start = None , model = None , n = 5000 , accurate_elbo = False ,
34
32
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.
36
56
37
57
Parameters
38
58
----------
@@ -58,9 +78,15 @@ def advi(vars=None, start=None, model=None, n=5000, accurate_elbo=False,
58
78
ADVIFit
59
79
Named tuple, which includes 'means', 'stds', and 'elbo_vals'.
60
80
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.
63
83
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
+ """
64
90
model = modelcontext (model )
65
91
if start is None :
66
92
start = model .test_point
0 commit comments