(self, parameters, deterministic=False)
| 398 | |
| 399 | class DiagonalGaussianDistribution(object): |
| 400 | def __init__(self, parameters, deterministic=False): |
| 401 | self.parameters = parameters |
| 402 | self.mean, self.logvar = torch.chunk(parameters, 2, dim=1) |
| 403 | self.logvar = torch.clamp(self.logvar, -30.0, 20.0) |
| 404 | self.deterministic = deterministic |
| 405 | self.std = torch.exp(0.5 * self.logvar) |
| 406 | self.var = torch.exp(self.logvar) |
| 407 | if self.deterministic: |
| 408 | self.var = self.std = torch.zeros_like(self.mean).to( |
| 409 | device=self.parameters.device |
| 410 | ) |
| 411 | |
| 412 | def sample(self): |
| 413 | x = self.mean + self.std * torch.randn(self.mean.shape).to( |
nothing calls this directly
no outgoing calls
no test coverage detected