MCPcopy Create free account
hub / github.com/LTH14/mar / kl

Method kl

models/vae.py:418–435  ·  view source on GitHub ↗
(self, other=None)

Source from the content-addressed store, hash-verified

416 return x
417
418 def kl(self, other=None):
419 if self.deterministic:
420 return torch.Tensor([0.0])
421 else:
422 if other is None:
423 return 0.5 * torch.sum(
424 torch.pow(self.mean, 2) + self.var - 1.0 - self.logvar,
425 dim=[1, 2, 3],
426 )
427 else:
428 return 0.5 * torch.sum(
429 torch.pow(self.mean - other.mean, 2) / other.var
430 + self.var / other.var
431 - 1.0
432 - self.logvar
433 + other.logvar,
434 dim=[1, 2, 3],
435 )
436
437 def nll(self, sample, dims=[1, 2, 3]):
438 if self.deterministic:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected