MCPcopy Create free account
hub / github.com/OpenDriveLab/ReSim / kl

Method kl

sat/vae_modules/regularizers.py:28–45  ·  view source on GitHub ↗
(self, other=None)

Source from the content-addressed store, hash-verified

26 return x
27
28 def kl(self, other=None):
29 if self.deterministic:
30 return torch.Tensor([0.0])
31 else:
32 if other is None:
33 return 0.5 * torch.sum(
34 torch.pow(self.mean, 2) + self.var - 1.0 - self.logvar,
35 dim=[1, 2, 3],
36 )
37 else:
38 return 0.5 * torch.sum(
39 torch.pow(self.mean - other.mean, 2) / other.var
40 + self.var / other.var
41 - 1.0
42 - self.logvar
43 + other.logvar,
44 dim=[1, 2, 3],
45 )
46
47 def nll(self, sample, dims=[1, 2, 3]):
48 if self.deterministic:

Callers 1

forwardMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected