Project: ReducedVarianceReparamGradients Author: andymiller File: bbvi_base.py (license) View Source Project

def __init__(self, lnpdf, D, glnpdf=None, lnpdf_is_vectorized=False):
        """ Black Box Variational Inference using stochastic gradients"""
        if lnpdf_is_vectorized:
            self.lnpdf = lnpdf
            if glnpdf is None:
                self.glnpdf = elementwise_grad(lnpdf)
        else:
            # create vectorized version
            self.glnpdf_single = grad(lnpdf)
            self.glnpdf = lambda z: np.array([self.glnpdf_single(zi)
                                              for zi in np.atleast_2d(z)])
            self.lnpdf = lambda z: np.array([lnpdf(zi)
                                             for zi in np.atleast_2d(z)])
            #if glnpdf is None:
            #    self.glnpdf = grad(lnpdf)

        # hessian and elementwise_grad of glnpdf
        self.gglnpdf   = elementwise_grad(self.glnpdf)
        self.hlnpdf    = hessian(self.lnpdf)
        self.hvplnpdf  = hessian_vector_product(self.lnpdf)

        # this function creates a generator of Hessian-vector product functions
        #  - make hvp = hvp_maker(lnpdf)(z)
        #  - now  hvp(v) = hessian(lnpdf)(z) v
        self.hvplnpdf_maker = make_hvp(self.lnpdf)

    #################################################
    # BBVI exposes these gradient functions         #
    #################################################
  • python

    Python (发音:[ paiθ(ə)n; (US) paiθɔn ]n. 蟒蛇,巨蛇 ),是一种面向对象的解释性的计算机程序设计语言,也是一种功能强大而完善的通用型语言,已经具有十多年的发…

    7952 引用 • 22 回帖 • 2 关注
  • numpy

    NumPy 是一个基础科学的计算包,包含: 一个强大的 N 维数组对象 sophisticated (broadcasting) functions tools for integrating C/C++ and Fortran code 有用的线性代数…

    1115 引用 • 1 关注
感谢    赞同    分享    收藏    关注    反对    举报    ...