当前位置: 首页>>代码示例>>Python>>正文


Python distributions.TransformedDistribution方法代码示例

本文整理汇总了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 
开发者ID:tingiskhan,项目名称:pyfilter,代码行数:22,代码来源:module.py

示例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]) 
开发者ID:tingiskhan,项目名称:pyfilter,代码行数:11,代码来源:parameter.py

示例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)
    ) 
开发者ID:tingiskhan,项目名称:pyfilter,代码行数:10,代码来源:affine.py

示例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 
开发者ID:acids-ircam,项目名称:ddsp_pytorch,代码行数:36,代码来源:flow.py

示例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 
开发者ID:jhjacobsen,项目名称:invertible-resnet,代码行数:8,代码来源:conv_iResNet.py


注:本文中的torch.distributions.TransformedDistribution方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。