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


Python constraints.real方法代码示例

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


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

示例1: test_constraints

# 需要导入模块: from torch.distributions import constraints [as 别名]
# 或者: from torch.distributions.constraints import real [as 别名]
def test_constraints(backend, jit):
    data = torch.tensor(0.5)

    def model():
        locs = pyro.param("locs", torch.randn(3), constraint=constraints.real)
        scales = pyro.param("scales", torch.randn(3).exp(), constraint=constraints.positive)
        p = torch.tensor([0.5, 0.3, 0.2])
        x = pyro.sample("x", dist.Categorical(p))
        pyro.sample("obs", dist.Normal(locs[x], scales[x]), obs=data)

    def guide():
        q = pyro.param("q", torch.randn(3).exp(), constraint=constraints.simplex)
        pyro.sample("x", dist.Categorical(q))

    with pyro_backend(backend):
        Elbo = infer.JitTrace_ELBO if jit else infer.Trace_ELBO
        elbo = Elbo(ignore_jit_warnings=True)
        assert_ok(model, guide, elbo) 
开发者ID:pyro-ppl,项目名称:funsor,代码行数:20,代码来源:test_minipyro.py

示例2: __init__

# 需要导入模块: from torch.distributions import constraints [as 别名]
# 或者: from torch.distributions.constraints import real [as 别名]
def __init__(self, funsor_dist, batch_shape=torch.Size(), event_shape=torch.Size(),
                 dtype="real", validate_args=None):
        assert isinstance(funsor_dist, Funsor)
        assert isinstance(batch_shape, tuple)
        assert isinstance(event_shape, tuple)
        assert "value" in funsor_dist.inputs
        super(FunsorDistribution, self).__init__(batch_shape, event_shape, validate_args)
        self.funsor_dist = funsor_dist
        self.dtype = dtype 
开发者ID:pyro-ppl,项目名称:funsor,代码行数:11,代码来源:distribution.py

示例3: support

# 需要导入模块: from torch.distributions import constraints [as 别名]
# 或者: from torch.distributions.constraints import real [as 别名]
def support(self):
        if self.dtype == "real":
            return constraints.real
        else:
            return constraints.integer_interval(0, self.dtype - 1) 
开发者ID:pyro-ppl,项目名称:funsor,代码行数:7,代码来源:distribution.py


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