r""" Creates a Exponential distribution parameterized by :attr:`rate`. This is a EXPERIMENTAL module that may be subject to change and/or deletion. Args: rate (float or Tensor): rate = 1 / scale of the distribution
| 8 | |
| 9 | |
| 10 | class Exponential(Distribution): |
| 11 | r""" |
| 12 | Creates a Exponential distribution parameterized by :attr:`rate`. |
| 13 | |
| 14 | This is a EXPERIMENTAL module that may be subject to change and/or deletion. |
| 15 | |
| 16 | Args: |
| 17 | rate (float or Tensor): rate = 1 / scale of the distribution |
| 18 | """ |
| 19 | |
| 20 | def __init__(self, rate: Union[Tensor, float]): |
| 21 | self.rate = Tensor(rate) |
| 22 | batch_shape = () if isinstance(rate, Number) else rate.shape |
| 23 | super().__init__(batch_shape=batch_shape) |
| 24 | |
| 25 | @property |
| 26 | def mean(self) -> Tensor: |
| 27 | return 1.0 / self.rate |
| 28 | |
| 29 | @property |
| 30 | def stddev(self) -> Tensor: |
| 31 | return 1.0 / self.rate |
| 32 | |
| 33 | @property |
| 34 | def variance(self) -> Tensor: |
| 35 | return F.pow(self.rate, -2) |
| 36 | |
| 37 | def sample(self, sample_shape: Optional[Iterable[int]] = ()) -> Tensor: |
| 38 | return exponential(self.rate, sample_shape) |
| 39 | |
| 40 | def log_prob(self, value): |
| 41 | return F.log(self.rate) - self.rate * value |
| 42 | |
| 43 | def cdf(self, value): |
| 44 | return 1.0 - F.exp(-self.rate * value) |
| 45 | |
| 46 | def icdf(self, value): |
| 47 | return -F.log1p(-value) / self.rate |
| 48 | |
| 49 | @property |
| 50 | def _natural_params(self): |
| 51 | return (self.rate,) |
| 52 | |
| 53 | def _log_normalizer(self, x): |
| 54 | return -F.log(-x) |
no outgoing calls