def logProb(self, samples, device='cpu', dtype=cuda_dtype): mix_a = Normal(self.mu_a, self.sd_a).log_prob(samples) + torch.log( torch.tensor([self.p_a], dtype=dtype).to(device)) mix_b = Normal(self.mu_b, self.sd_b).log_prob(samples) + torch.log( torch.tensor([1 - self.p_a], dtype=dtype).to(device)) return torch.logsumexp(torch.cat( [mix_a.view(-1, 1), mix_b.view(-1, 1)], dim=1), dim=1)
def score(self, c, x): scores = Normal(self.mu(c), self.sigma(c)).log_prob(x) return scores.view(scores.size(0), -1).sum(dim=1)