简体   繁体   中英

How to find the mean and the variance of the normal distribution obtained using the advi method in PyMC?

I am using the advi method to find the posterior distribution. How can I find the mean and the std of the normal posterior distribution that we get using the advi and not that of the samples obtained using advi in PyMC?

You can call approx.mean.eval() , approx.std.eval() , and then reference approx.ordering to map index-slices to parameters of Your model.

Using pymc==4.1.6, and having defined a pm.Model called model , I can do the following:

with model:
    approx = pm.fit(method="advi")
    
approx_mu = approx.mean.eval()
approx_mu_dict = {
    param: approx_mu[slice_]
    for (param, (_, slice_, _, _))
    in approx.ordering.items()}

approx_std = approx.std.eval()
approx_std_dict = {
    param: approx_std[slice_]
    for (param, (_, slice_, _, _))
    in approx.ordering.items()}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM