예제 #1
0
    def generate(self, num_to_sample: int = 1):
        cuda_device = self._get_prediction_device()
        prior_mean = nn_util.move_to_device(
            torch.zeros((num_to_sample, self._latent_dim)), cuda_device)
        prior_stddev = torch.ones_like(prior_mean)
        prior = Normal(prior_mean, prior_stddev)
        latent = prior.sample()
        generated = self._decoder.generate(latent)

        return self.decode(generated)
예제 #2
0
파일: test_mask.py 프로젝트: www3cam/pyro
def test_mask_type(mask):
    p = Normal(torch.randn(2, 2), torch.randn(2, 2).exp())
    p_masked = p.mask(mask)
    if isinstance(mask, bool):
        mask = torch.tensor(mask)

    x = p.sample()
    actual = p_masked.log_prob(x)
    expected = p.log_prob(x) * mask.float()
    assert_equal(actual, expected)

    actual = p_masked.score_parts(x)
    expected = p.score_parts(x)
    for a, e in zip(actual, expected):
        if isinstance(e, torch.Tensor):
            e = e * mask.float()
        assert_equal(a, e)