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