當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。