-
-
Notifications
You must be signed in to change notification settings - Fork 986
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add UnitLowerCholeskyTransform; change default parameterization for A…
…utoMultivariateNormal (#2972)
- Loading branch information
1 parent
3c6a591
commit f9b7d3d
Showing
6 changed files
with
66 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Copyright Contributors to the Pyro project. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import torch | ||
from torch.distributions import constraints | ||
from torch.distributions.transforms import Transform | ||
|
||
from pyro.distributions.constraints import unit_lower_cholesky | ||
|
||
|
||
class UnitLowerCholeskyTransform(Transform): | ||
""" | ||
Transform from unconstrained matrices to lower-triangular matrices with | ||
all ones diagonals. | ||
""" | ||
|
||
domain = constraints.independent(constraints.real, 2) | ||
codomain = unit_lower_cholesky | ||
|
||
def __eq__(self, other): | ||
return isinstance(other, UnitLowerCholeskyTransform) | ||
|
||
def _call(self, x): | ||
return x.tril(-1) + torch.eye(x.size(-1), device=x.device, dtype=x.dtype) | ||
|
||
def _inverse(self, y): | ||
return y | ||
|
||
|
||
__all__ = [ | ||
"UnitLowerCholeskyTransform", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters