MCPcopy Create free account
hub / github.com/CompVis/diff2flow / kl

Method kl

diff2flow/kl_autoencoder.py:60–72  ·  view source on GitHub ↗
(self, other=None)

Source from the content-addressed store, hash-verified

58 return x
59
60 def kl(self, other=None):
61 if self.deterministic:
62 return torch.Tensor([0.])
63 else:
64 if other is None:
65 return 0.5 * torch.sum(torch.pow(self.mean, 2)
66 + self.var - 1.0 - self.logvar,
67 dim=[1, 2, 3])
68 else:
69 return 0.5 * torch.sum(
70 torch.pow(self.mean - other.mean, 2) / other.var
71 + self.var / other.var - 1.0 - self.logvar + other.logvar,
72 dim=[1, 2, 3])
73
74 def nll(self, sample, dims=[1,2,3]):
75 if self.deterministic:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected