13 Creates a half-normal distribution parameterized by `scale` where:: 16 Y = |X| ~ HalfNormal(scale) 20 >>> m = HalfNormal(torch.tensor([1.0])) 21 >>> m.sample() # half-normal distributed with scale=1 25 scale (float or Tensor): scale of the full Normal distribution 27 arg_constraints = {
'scale': constraints.positive}
28 support = constraints.positive
31 def __init__(self, scale, validate_args=None):
32 base_dist =
Normal(0, scale)
33 super(HalfNormal, self).__init__(base_dist,
AbsTransform(),
34 validate_args=validate_args)
36 def expand(self, batch_shape, _instance=None):
38 return super(HalfNormal, self).expand(batch_shape, _instance=new)
42 return self.base_dist.scale
46 return self.
scale * math.sqrt(2 / math.pi)
50 return self.scale.pow(2) * (1 - 2 / math.pi)
52 def log_prob(self, value):
53 log_prob = self.base_dist.log_prob(value) + math.log(2)
54 log_prob[value.expand(log_prob.shape) < 0] = -inf
58 return 2 * self.base_dist.cdf(value) - 1
61 return self.base_dist.icdf((prob + 1) / 2)
64 return self.base_dist.entropy() - math.log(2)
def _get_checked_instance(self, cls, _instance=None)