1 from numbers
import Number
11 Creates a Poisson distribution parameterized by :attr:`rate`, the rate parameter. 13 Samples are nonnegative integers, with a pmf given by 16 \mathrm{rate}^k \frac{e^{-\mathrm{rate}}}{k!} 20 >>> m = Poisson(torch.tensor([4])) 25 rate (Number, Tensor): the rate parameter 27 arg_constraints = {
'rate': constraints.positive}
28 support = constraints.nonnegative_integer
38 def __init__(self, rate, validate_args=None):
39 self.rate, = broadcast_all(rate)
40 if isinstance(rate, Number):
41 batch_shape = torch.Size()
43 batch_shape = self.rate.size()
44 super(Poisson, self).__init__(batch_shape, validate_args=validate_args)
46 def expand(self, batch_shape, _instance=None):
48 batch_shape = torch.Size(batch_shape)
49 new.rate = self.rate.expand(batch_shape)
50 super(Poisson, new).__init__(batch_shape, validate_args=
False)
54 def sample(self, sample_shape=torch.Size()):
57 return torch.poisson(self.rate.expand(shape))
59 def log_prob(self, value):
62 rate, value = broadcast_all(self.rate, value)
63 return (rate.log() * value) - rate - (value + 1).lgamma()
66 def _natural_params(self):
67 return (torch.log(self.rate), )
69 def _log_normalizer(self, x):
def _get_checked_instance(self, cls, _instance=None)
def _extended_shape(self, sample_shape=torch.Size())
def _validate_sample(self, value)