1
1
2
2
'''
3
- Created on Mar 12, 2011
3
+ Created on 2016
4
4
5
5
@author: johnsalvatier
6
6
'''
19
19
from pymc3 .sampling import NDArray
20
20
from pymc3 .backends .base import MultiTrace
21
21
22
- __all__ = ['advi' ]
22
+ __all__ = ['advi' , 'sample_vp' ]
23
23
24
24
ADVIFit = namedtuple ('ADVIFit' , 'means, stds, elbo_vals' )
25
25
@@ -32,7 +32,29 @@ def check_discrete_rvs(vars):
32
32
33
33
def advi (vars = None , start = None , model = None , n = 5000 , accurate_elbo = False ,
34
34
learning_rate = .001 , epsilon = .1 , random_seed = 20090425 , verbose = 1 ):
35
- """Run ADVI.
35
+ """Performe automatic differentiation variational inference (ADVI).
36
+
37
+ This function implements the meanfield ADVI, where the variational
38
+ posterior distribution is assumed to spherical Gaussian without
39
+ correlation of parameters and fit to the true posterior distribution.
40
+ The means and standard deviations of the variational posterior are referred
41
+ to as variational parameters.
42
+
43
+ The return value of this function is an :code:`ADVIfit` object, which has
44
+ variational parameters. If you want to draw samples from the variational
45
+ posterior, you need to pass the :code:`ADVIfit` object to
46
+ :code:`pymc3.variational.sample_vp()`.
47
+
48
+ The variational parameters are defined on the transformed space, which is
49
+ required to do ADVI on an unconstrained parameter space as described in
50
+ [KTR+2016]. The parameters in the :code:`ADVIfit` object are in the
51
+ transformed space, while traces returned by :code:`sample_vp()` are in
52
+ the original space as obtained by MCMC sampling methods in PyMC3.
53
+
54
+ The variational parameters are optimized with a modified version of
55
+ Adagrad, where only the last (n_window) gradient vectors are used to
56
+ control the learning rate and older gradient vectors are ignored.
57
+ n_window denotes the size of time window and fixed to 10.
36
58
37
59
Parameters
38
60
----------
@@ -58,9 +80,15 @@ def advi(vars=None, start=None, model=None, n=5000, accurate_elbo=False,
58
80
ADVIFit
59
81
Named tuple, which includes 'means', 'stds', and 'elbo_vals'.
60
82
61
- 'means' and 'stds' include parameters of the variational posterior.
62
- """
83
+ 'means' is the mean. 'stds' is log of the standard deviation.
84
+ 'elbo_vals' is the trace of ELBO values during optimizaiton.
63
85
86
+ References
87
+ ----------
88
+ .. [KTR+2016] Kucukelbir, A., Tran, D., Ranganath, R., Gelman, A.,
89
+ and Blei, D. M. (2016). Automatic Differentiation Variational Inference.
90
+ arXiv preprint arXiv:1603.00788.
91
+ """
64
92
model = modelcontext (model )
65
93
if start is None :
66
94
start = model .test_point
0 commit comments