mades.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:maf 作者: gpapamak 项目源码 文件源码
def gen(self, x, n_samples=1, u=None):
        """
        Generate samples from made conditioned on x. Requires as many evaluations as number of outputs.
        :param x: input vector
        :param n_samples: number of samples
        :param u: random numbers to use in generating samples; if None, new random numbers are drawn
        :return: samples
        """

        y = np.zeros([n_samples, self.n_outputs], dtype=dtype)
        u = rng.randn(n_samples, self.n_outputs).astype(dtype) if u is None else u

        xy = (np.tile(x, [n_samples, 1]), y)

        for i in xrange(1, self.n_outputs + 1):
            m, logp, loga = self.eval_comps(xy)
            idx = np.argwhere(self.output_order == i)[0, 0]
            for n in xrange(n_samples):
                z = util.discrete_sample(np.exp(loga[n, idx]))[0]
                y[n, idx] = m[n, idx, z] + np.exp(np.minimum(-0.5 * logp[n, idx, z], 10.0)) * u[n, idx]

        return y
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号