Skip to content

Commit

Permalink
🩹 Fix null Jacobian caused by tanh
Browse files Browse the repository at this point in the history
  • Loading branch information
francois-rozet committed May 28, 2022
1 parent 81a22d3 commit 50e53c7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lampe/distributions/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def __init__(
self.eps = eps

def _call(self, x: Tensor) -> Tensor:
return self.f(self.bound * torch.tanh(x / self.bound))
return self.f(x / torch.sqrt(1 + (x / self.bound)**2))

def _inverse(self, y: Tensor) -> Tensor:
a = torch.full_like(y, -self.bound)
Expand All @@ -290,7 +290,7 @@ def _inverse(self, y: Tensor) -> Tensor:

x = (a + b) / 2

return self.bound * torch.atanh(x / self.bound)
return x / torch.sqrt(1 - (x / self.bound)**2)

def log_abs_det_jacobian(self, x: Tensor, y: Tensor) -> Tensor:
return torch.log(torch.autograd.functional.jacobian(
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

setuptools.setup(
name='lampe',
version='0.4.3',
version='0.4.4',
packages=setuptools.find_packages(),
description='Likelihood-free AMortized Posterior Estimation with PyTorch',
keywords='parameter inference bayes posterior amortized likelihood ratio mcmc torch',
Expand Down

0 comments on commit 50e53c7

Please sign in to comment.