3 from numbers
import Number
13 Samples from a Cauchy (Lorentz) distribution. The distribution of the ratio of 14 independent normally distributed random variables with means `0` follows a 19 >>> m = Cauchy(torch.tensor([0.0]), torch.tensor([1.0])) 20 >>> m.sample() # sample from a Cauchy distribution with loc=0 and scale=1 24 loc (float or Tensor): mode or median of the distribution. 25 scale (float or Tensor): half width at half maximum. 27 arg_constraints = {
'loc': constraints.real,
'scale': constraints.positive}
28 support = constraints.real
31 def __init__(self, loc, scale, validate_args=None):
32 self.loc, self.
scale = broadcast_all(loc, scale)
33 if isinstance(loc, Number)
and isinstance(scale, Number):
34 batch_shape = torch.Size()
36 batch_shape = self.loc.size()
37 super(Cauchy, self).__init__(batch_shape, validate_args=validate_args)
39 def expand(self, batch_shape, _instance=None):
41 batch_shape = torch.Size(batch_shape)
42 new.loc = self.loc.expand(batch_shape)
43 new.scale = self.scale.expand(batch_shape)
44 super(Cauchy, new).__init__(batch_shape, validate_args=
False)
56 def rsample(self, sample_shape=torch.Size()):
58 eps = self.loc.new(shape).cauchy_()
59 return self.loc + eps * self.
scale 61 def log_prob(self, value):
64 return -math.log(math.pi) - self.scale.log() - (1 + ((value - self.loc) / self.
scale)**2).log()
69 return torch.atan((value - self.loc) / self.
scale) / math.pi + 0.5
71 def icdf(self, value):
74 return torch.tan(math.pi * (value - 0.5)) * self.
scale + self.loc
77 return math.log(4 * math.pi) + self.scale.log()
def _get_checked_instance(self, cls, _instance=None)
def _extended_shape(self, sample_shape=torch.Size())
def _validate_sample(self, value)