test_conjugate_gaussian_models.py 文件源码

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

项目:pyro 作者: uber 项目源码 文件源码
def setup_pyramid(self, N):
        # pyramid of normals with known covariances and latent means
        assert(N > 1)
        self.N = N  # number of layers in the pyramid
        lambdas = [1.1 * (k + 1) / N for k in range(N + 2)]
        self.lambdas = list(map(lambda x: Variable(torch.Tensor([x])), lambdas))
        # generate data
        self.data = []
        self.N_data = 3
        bottom_layer_size = 2 ** (N - 1)
        for i in range(bottom_layer_size):
            data_i = []
            for k in range(self.N_data):
                data_i.append(Variable(torch.Tensor([0.25]) +
                                       (0.1 + 0.4 * (i + 1) / bottom_layer_size) * torch.randn(1)))
            self.data.append(data_i)
        self.data_sums = [sum(self.data[i]) for i in range(bottom_layer_size)]
        self.N_data = Variable(torch.Tensor([self.N_data]))
        self.q_dag = self.construct_q_dag()
        # compute the order in which guide samples are generated
        self.q_topo_sort = list(networkx.topological_sort(self.q_dag))
        self.which_nodes_reparam = self.setup_reparam_mask(len(self.q_topo_sort))
        self.calculate_variational_targets()
        self.set_model_permutations()

    # for choosing which latents should be reparameterized
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号