本文整理匯總了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)
示例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
示例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)