當前位置: 首頁>>代碼示例>>Python>>正文


Python distributions.Uniform方法代碼示例

本文整理匯總了Python中torch.distributions.Uniform方法的典型用法代碼示例。如果您正苦於以下問題:Python distributions.Uniform方法的具體用法?Python distributions.Uniform怎麽用?Python distributions.Uniform使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在torch.distributions的用法示例。


在下文中一共展示了distributions.Uniform方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_zdist

# 需要導入模塊: from torch import distributions [as 別名]
# 或者: from torch.distributions import Uniform [as 別名]
def get_zdist(dist_name, dim, device=None):
    # Get distribution
    if dist_name == 'uniform':
        low = -torch.ones(dim, device=device)
        high = torch.ones(dim, device=device)
        zdist = distributions.Uniform(low, high)
    elif dist_name == 'gauss':
        mu = torch.zeros(dim, device=device)
        scale = torch.ones(dim, device=device)
        zdist = distributions.Normal(mu, scale)
    else:
        raise NotImplementedError

    # Add dim attribute
    zdist.dim = dim

    return zdist 
開發者ID:akanazawa,項目名稱:vgan,代碼行數:19,代碼來源:distributions.py

示例2: __init__

# 需要導入模塊: from torch import distributions [as 別名]
# 或者: from torch.distributions import Uniform [as 別名]
def __init__(self, max_perc, hop_length=None, n_freq=201, fixed_rate=None):

        super(RandomTimeStretch, self).__init__(hop_length, n_freq, fixed_rate)
        self._dist = Uniform(1.-max_perc, 1+max_perc) 
開發者ID:ksanjeevan,項目名稱:crnn-audio-classification,代碼行數:6,代碼來源:audio.py

示例3: logistic_distribution

# 需要導入模塊: from torch import distributions [as 別名]
# 或者: from torch.distributions import Uniform [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

示例4: _sample_batch_from_proposal

# 需要導入模塊: from torch import distributions [as 別名]
# 或者: from torch.distributions import Uniform [as 別名]
def _sample_batch_from_proposal(self, batch_size,
                                    return_log_density_of_samples=False):
        # need to do n_samples passes through autoregressive net
        samples = torch.zeros(batch_size, self.autoregressive_net.input_dim)
        log_density_of_samples = torch.zeros(batch_size,
                                             self.autoregressive_net.input_dim)
        for dim in range(self.autoregressive_net.input_dim):
            # compute autoregressive outputs
            autoregressive_outputs = self.autoregressive_net(samples).reshape(-1,
                                                                              self.dim,
                                                                              self.autoregressive_net.output_dim_multiplier)

            # grab proposal params for dth dimensions
            proposal_params = autoregressive_outputs[..., dim, self.context_dim:]

            # make mixture coefficients, locs, and scales for proposal
            logits = proposal_params[...,
                     :self.n_proposal_mixture_components]  # [B, D, M]
            if logits.shape[0] == 1:
                logits = logits.reshape(self.dim, self.n_proposal_mixture_components)
            locs = proposal_params[...,
                   self.n_proposal_mixture_components:(
                           2 * self.n_proposal_mixture_components)]  # [B, D, M]
            scales = self.mixture_component_min_scale + self.scale_activation(
                proposal_params[...,
                (2 * self.n_proposal_mixture_components):])  # [B, D, M]

            # create proposal
            if self.Component is not None:
                mixture_distribution = distributions.OneHotCategorical(
                    logits=logits,
                    validate_args=True
                )
                components_distribution = self.Component(loc=locs, scale=scales)
                self.proposal = distributions_.MixtureSameFamily(
                    mixture_distribution=mixture_distribution,
                    components_distribution=components_distribution
                )
                proposal_samples = self.proposal.sample((1,))  # [S, B, D]

            else:
                self.proposal = distributions.Uniform(low=-4, high=4)
                proposal_samples = self.proposal.sample(
                    (1, batch_size, 1)
                )
            proposal_samples = proposal_samples.permute(1, 2, 0)  # [B, D, S]
            proposal_log_density = self.proposal.log_prob(proposal_samples)
            log_density_of_samples[:, dim] += proposal_log_density.reshape(-1).detach()
            samples[:, dim] += proposal_samples.reshape(-1).detach()

        if return_log_density_of_samples:
            return samples, torch.sum(log_density_of_samples, dim=-1)
        else:
            return samples 
開發者ID:conormdurkan,項目名稱:autoregressive-energy-machines,代碼行數:56,代碼來源:aem.py


注:本文中的torch.distributions.Uniform方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。