本文整理匯總了Python中torch.distributions.TransformedDistribution方法的典型用法代碼示例。如果您正苦於以下問題:Python distributions.TransformedDistribution方法的具體用法?Python distributions.TransformedDistribution怎麽用?Python distributions.TransformedDistribution使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類torch.distributions
的用法示例。
在下文中一共展示了distributions.TransformedDistribution方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _iterate_distribution
# 需要導入模塊: from torch import distributions [as 別名]
# 或者: from torch.distributions import TransformedDistribution [as 別名]
def _iterate_distribution(d: Distribution) -> Tuple[Distribution, ...]:
"""
Helper method for iterating over distributions.
:param d: The distribution
"""
res = tuple()
if not isinstance(d, TransformedDistribution):
res += tuple(_find_types(d, torch.Tensor).values())
for sd in _find_types(d, Distribution).values():
res += _iterate_distribution(sd)
else:
res += _iterate_distribution(d.base_dist)
for t in d.transforms:
res += tuple(_find_types(t, torch.Tensor).values())
return res
示例2: transformed_dist
# 需要導入模塊: from torch import distributions [as 別名]
# 或者: from torch.distributions import TransformedDistribution [as 別名]
def transformed_dist(self):
"""
Returns the unconstrained distribution.
"""
if not self.trainable:
raise ValueError('Is not of `Distribution` instance!')
return TransformedDistribution(self._prior, [self.bijection.inv])
示例3: _define_transdist
# 需要導入模塊: from torch import distributions [as 別名]
# 或者: from torch.distributions import TransformedDistribution [as 別名]
def _define_transdist(loc: torch.Tensor, scale: torch.Tensor, inc_dist: Distribution, ndim: int):
loc, scale = torch.broadcast_tensors(loc, scale)
shape = loc.shape[:-ndim] if ndim > 0 else loc.shape
return TransformedDistribution(
inc_dist.expand(shape), AffineTransform(loc, scale, event_dim=ndim)
)
示例4: __init__
# 需要導入模塊: from torch import distributions [as 別名]
# 或者: from torch.distributions import TransformedDistribution [as 別名]
def __init__(self, dim, blocks, flow_length, final_block=None, density=None, amortized='none'):
""" Initialize normalizing flow """
super().__init__()
biject = []
self.n_params = []
# Start density (z0)
if density is None:
density = MultivariateNormal(torch.zeros(dim), torch.eye(dim))
self.base_density = density
for f in range(flow_length-1):
for b_flow in blocks:
cur_block = b_flow(dim, amortized=amortized)
self.n_params.append(cur_block.n_parameters())
biject.append(cur_block)
# Add only first block last
cur_block = blocks[0](dim, amortized=amortized)
self.n_params.append(cur_block.n_parameters())
biject.append(cur_block)
if (final_block is not None):
cur_block = final_block
self.n_params.append(cur_block.n_parameters())
biject.append(cur_block)
# Full set of transforms
self.transforms = transform.ComposeTransform(biject)
self.bijectors = nn.ModuleList(biject)
# Final density (zK) defined as transformed distribution
self.final_density = distrib.TransformedDistribution(density, self.transforms)
self.amortized = amortized
# Handle different amortizations
if amortized in ('self', 'input'):
self.amortized_seed = torch.ones(1, dim).detach()
self.amortized_params = self.parameters_network(dim, self.n_parameters())
self.log_det = []
self.dim = dim
示例5: logistic_distribution
# 需要導入模塊: from torch import distributions [as 別名]
# 或者: from torch.distributions import TransformedDistribution [as 別名]
def logistic_distribution(loc, log_scale):
scale = torch.exp(log_scale) + 1e-5
base_distribution = distributions.Uniform(torch.zeros_like(loc), torch.ones_like(loc))
transforms = [LogisticTransform(), distributions.AffineTransform(loc=loc, scale=scale)]
logistic = distributions.TransformedDistribution(base_distribution, transforms)
return logistic