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


Python pyro.distributions方法代码示例

本文整理汇总了Python中pyro.distributions方法的典型用法代码示例。如果您正苦于以下问题:Python pyro.distributions方法的具体用法?Python pyro.distributions怎么用?Python pyro.distributions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyro的用法示例。


在下文中一共展示了pyro.distributions方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: model

# 需要导入模块: import pyro [as 别名]
# 或者: from pyro import distributions [as 别名]
def model(x, y):
    fc1_weight_prior = pyro.distributions.Normal(loc=torch.zeros_like(det_net.fc1.weight), scale=torch.ones_like(det_net.fc1.weight))
    fc1_bias_prior = pyro.distributions.Normal(loc=torch.zeros_like(det_net.fc1.bias), scale=torch.ones_like(det_net.fc1.bias))

    fc2_weight_prior = pyro.distributions.Normal(loc=torch.zeros_like(det_net.fc2.weight), scale=torch.ones_like(det_net.fc2.weight))
    fc2_bias_prior = pyro.distributions.Normal(loc=torch.zeros_like(det_net.fc2.bias), scale=torch.ones_like(det_net.fc2.bias))

    fc3_weight_prior = pyro.distributions.Normal(loc=torch.zeros_like(det_net.fc3.weight), scale=torch.ones_like(det_net.fc3.weight))
    fc3_bias_prior = pyro.distributions.Normal(loc=torch.zeros_like(det_net.fc3.bias), scale=torch.ones_like(det_net.fc3.bias))

    priors = {"fc1.weight": fc1_weight_prior, "fc1.bias": fc1_bias_prior,
              "fc2.weight": fc2_weight_prior, "fc2.bias": fc2_bias_prior,
              "fc3.weight": fc3_weight_prior, "fc3.bias": fc3_bias_prior}

    lifted_module = pyro.random_module("module", det_net, priors)

    sampled_reg_model = lifted_module()

    logits = sampled_reg_model(x)

    return pyro.sample("obs", pyro.distributions.Categorical(logits=logits), obs=y) 
开发者ID:fregu856,项目名称:evaluating_bdl,代码行数:23,代码来源:model_pyro.py

示例2: __init__

# 需要导入模块: import pyro [as 别名]
# 或者: from pyro import distributions [as 别名]
def __init__(self, x_dim=p.NUM_PIXELS, y_dim=p.NUM_LABELS, z_dim=p.NUM_STYLE, h_dims=p.NUM_HIDDEN,
                 eps=p.EPS, enum_discrete=True, aux_loss=True, aux_loss_multiplier=300,
                 use_cuda=False, batch_size=100, init_lr=0.001, continue_from=None,
                 *args, **kwargs):
        super().__init__()

        # initialize the class with all arguments provided to the constructor
        self.x_dim = x_dim
        self.y_dim = y_dim

        self.use_cuda = use_cuda
        self.batch_size = batch_size
        self.init_lr = init_lr
        self.epoch = 1

        if continue_from is None:
            self.z_dim = z_dim
            self.h_dims = h_dims
            self.eps = eps
            self.enum_discrete = enum_discrete
            self.aux_loss = aux_loss
            self.aux_loss_multiplier = aux_loss_multiplier
            # define and instantiate the neural networks representing
            # the paramters of various distributions in the model
            self.__setup_networks()
        else:
            self.load(continue_from)

        # using GPUs for faster training of the networks
        if self.use_cuda:
            self.cuda() 
开发者ID:jinserk,项目名称:pytorch-asr,代码行数:33,代码来源:model.py

示例3: _pyro_noncentered_model

# 需要导入模块: import pyro [as 别名]
# 或者: from pyro import distributions [as 别名]
def _pyro_noncentered_model(J, sigma, y=None):
    import pyro
    import pyro.distributions as dist

    mu = pyro.sample("mu", dist.Normal(0, 5))
    tau = pyro.sample("tau", dist.HalfCauchy(5))
    with pyro.plate("J", J):
        eta = pyro.sample("eta", dist.Normal(0, 1))
        theta = mu + tau * eta
        return pyro.sample("obs", dist.Normal(theta, sigma), obs=y) 
开发者ID:arviz-devs,项目名称:arviz,代码行数:12,代码来源:helpers.py

示例4: _numpyro_noncentered_model

# 需要导入模块: import pyro [as 别名]
# 或者: from pyro import distributions [as 别名]
def _numpyro_noncentered_model(J, sigma, y=None):
    import numpyro
    import numpyro.distributions as dist

    mu = numpyro.sample("mu", dist.Normal(0, 5))
    tau = numpyro.sample("tau", dist.HalfCauchy(5))
    with numpyro.plate("J", J):
        eta = numpyro.sample("eta", dist.Normal(0, 1))
        theta = mu + tau * eta
        return numpyro.sample("obs", dist.Normal(theta, sigma), obs=y) 
开发者ID:arviz-devs,项目名称:arviz,代码行数:12,代码来源:helpers.py

示例5: model

# 需要导入模块: import pyro [as 别名]
# 或者: from pyro import distributions [as 别名]
def model(x, y):
    fc1_mean_weight_prior = pyro.distributions.Normal(loc=torch.zeros_like(det_net.fc1_mean.weight), scale=torch.ones_like(det_net.fc1_mean.weight))
    fc1_mean_bias_prior = pyro.distributions.Normal(loc=torch.zeros_like(det_net.fc1_mean.bias), scale=torch.ones_like(det_net.fc1_mean.bias))

    fc2_mean_weight_prior = pyro.distributions.Normal(loc=torch.zeros_like(det_net.fc2_mean.weight), scale=torch.ones_like(det_net.fc2_mean.weight))
    fc2_mean_bias_prior = pyro.distributions.Normal(loc=torch.zeros_like(det_net.fc2_mean.bias), scale=torch.ones_like(det_net.fc2_mean.bias))

    fc3_mean_weight_prior = pyro.distributions.Normal(loc=torch.zeros_like(det_net.fc3_mean.weight), scale=torch.ones_like(det_net.fc3_mean.weight))
    fc3_mean_bias_prior = pyro.distributions.Normal(loc=torch.zeros_like(det_net.fc3_mean.bias), scale=torch.ones_like(det_net.fc3_mean.bias))

    fc1_var_weight_prior = pyro.distributions.Normal(loc=torch.zeros_like(det_net.fc1_var.weight), scale=torch.ones_like(det_net.fc1_var.weight))
    fc1_var_bias_prior = pyro.distributions.Normal(loc=torch.zeros_like(det_net.fc1_var.bias), scale=torch.ones_like(det_net.fc1_var.bias))

    fc2_var_weight_prior = pyro.distributions.Normal(loc=torch.zeros_like(det_net.fc2_var.weight), scale=torch.ones_like(det_net.fc2_var.weight))
    fc2_var_bias_prior = pyro.distributions.Normal(loc=torch.zeros_like(det_net.fc2_var.bias), scale=torch.ones_like(det_net.fc2_var.bias))

    fc3_var_weight_prior = pyro.distributions.Normal(loc=torch.zeros_like(det_net.fc3_var.weight), scale=torch.ones_like(det_net.fc3_var.weight))
    fc3_var_bias_prior = pyro.distributions.Normal(loc=torch.zeros_like(det_net.fc3_var.bias), scale=torch.ones_like(det_net.fc3_var.bias))

    priors = {"fc1_mean.weight": fc1_mean_weight_prior, "fc1_mean.bias": fc1_mean_bias_prior,
              "fc2_mean.weight": fc2_mean_weight_prior, "fc2_mean.bias": fc2_mean_bias_prior,
              "fc3_mean.weight": fc3_mean_weight_prior, "fc3_mean.bias": fc3_mean_bias_prior,
              "fc1_var.weight": fc1_var_weight_prior, "fc1_var.bias": fc1_var_bias_prior,
              "fc2_var.weight": fc2_var_weight_prior, "fc2_var.bias": fc2_var_bias_prior,
              "fc3_var.weight": fc3_var_weight_prior, "fc3_var.bias": fc3_var_bias_prior}

    lifted_module = pyro.random_module("module", det_net, priors)

    sampled_reg_model = lifted_module()

    mu, log_sigma_2 = sampled_reg_model(x)

    sigma = torch.sqrt(torch.exp(log_sigma_2))

    return pyro.sample("obs", pyro.distributions.Normal(mu, sigma), obs=y) 
开发者ID:fregu856,项目名称:evaluating_bdl,代码行数:37,代码来源:model_pyro.py

示例6: calculate_discounted_reward

# 需要导入模块: import pyro [as 别名]
# 或者: from pyro import distributions [as 别名]
def calculate_discounted_reward(self, state_batch_tensor, done_batch, reward_batch, actions_batch_tensor):
        # calculate the predicted value firstly...
        predicted_value = self.critic_net(state_batch_tensor)
        # calculate the returns and advantages firstly...
        predicted_value = predicted_value.detach()

        returns = torch.Tensor(len(done_batch), 1)
        advantages = torch.Tensor(len(done_batch), 1)
        deltas = torch.Tensor(len(done_batch), 1)

        previous_returns = 0
        previous_advantages = 0
        previous_value = 0
        # use gae here...
        for idx in reversed(range(len(done_batch))):
            if done_batch[idx]:
                returns[idx, 0] = reward_batch[idx]
                #deltas[idx, 0] = reward_batch[idx] - predicted_value.data[idx, 0]
                #advantages[idx, 0] = deltas[idx, 0]
                advantages[idx, 0] = returns[idx, 0] - predicted_value.data[idx, 0]
            else:
                returns[idx, 0] = reward_batch[idx] + self.args.gamma * previous_returns
                #deltas[idx, 0] = reward_batch[idx] + self.args.gamma * previous_value - predicted_value.data[idx, 0]
                #advantages[idx, 0] = deltas[idx, 0] + self.args.gamma * self.args.tau * previous_advantages
                advantages[idx, 0] = returns[idx, 0] - predicted_value.data[idx, 0]

            previous_returns = returns[idx, 0]
            previous_value = predicted_value.data[idx, 0]
            previous_advantages = advantages[idx, 0]

        # normalize the advantages...
        advantages = (advantages - advantages.mean()) / advantages.std()
        # calculate the old action probabilities...
        action_alpha, action_beta = self.actor_net(state_batch_tensor)
        old_beta_dist = dist.Beta(action_alpha, action_beta)
        old_action_prob = old_beta_dist.batch_log_pdf(actions_batch_tensor)
        old_action_prob = old_action_prob.detach()
        
        return returns, advantages, old_action_prob 

    # sample actions from the beta distributions.... 
开发者ID:TianhongDai,项目名称:distributed-ppo,代码行数:43,代码来源:dppo_agent.py


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