Poisson

class Poisson[source]

Bases: DiscreteDistribution

Sampling from and properties of the Poisson distribution.

The Poisson distribution is a discrete probability distribution used to express the probability of a given number of events, \(k\), occurring in a fixed amount of time, given an expected number of events, \(\lambda\).

Parameters

\(\lambda \in \mathbb{R}_+^*\), rate

Support

\(k \in \mathbb{N}_0\), count

classmethod cdf(support: Tensor | float, rate: Tensor | float) Tensor[source]

Computes the cumulative distribution function.

\[P(K \leq k; \lambda) = \frac{\Gamma (\lfloor k + 1 \rfloor, \lambda)}{\Gamma (\lambda)}\]
Parameters:
Returns:

resulting cumulative probabilities.

Return type:

torch.Tensor

classmethod logcdf(support: Tensor | float, rate: Tensor | float) Tensor[source]

Computes the natural logarithm of the cumulative distribution function.

\[\log P(K \leq k; \lambda) = \log \frac{\Gamma (\lfloor k + 1 \rfloor, \lambda)}{\Gamma (\lambda)}\]
Parameters:
Returns:

log of the resulting cumulative probabilities.

Return type:

torch.Tensor

classmethod logpmf(support: Tensor | float, rate: Tensor | float) Tensor[source]

Computes the natural logarithm of the probability mass function.

\[\log P(K=k; \lambda) = k \log \lambda - \lambda - \log(k!)\]
Parameters:
Returns:

log of the resulting point probabilities.

Return type:

torch.Tensor

classmethod mean(rate: Tensor | float) Tensor[source]

Computes the expected value of the distribution.

\[\text{E}[K \mid K \sim \text{Poisson}(\lambda)] = \lambda\]
Parameters:

rate (torch.Tensor | float) – expected rate of occurrences, \(\lambda\).

Returns:

mean of the distribution with given parameters.

Return type:

torch.Tensor

classmethod pmf(support: Tensor | float, rate: Tensor | float) Tensor[source]

Computes the probability mass function.

\[P(K=k; \lambda) = \frac{\lambda^k e^{-k}}{k!}\]
Parameters:
Returns:

resulting point probabilities.

Return type:

torch.Tensor

classmethod sample(rate: Tensor | float, generator: Generator | None = None) Tensor[source]

Samples random variates from a Poisson distribution.

\[K \sim \text{Poisson}(\lambda)\]
Parameters:
  • rate (torch.Tensor | float) – expected rate of occurrences, \(\lambda\).

  • generator (torch.Generator | None, optional) – pseudorandom number generator to use for sampling. Defaults to None.

Returns:

resulting random variates, \(K\).

Return type:

torch.Tensor

Caution

This calls torch.poisson() which as of PyTorch 2.1 does not support computation on Metal Performance Shaders. Compensate accordingly.

classmethod validate(rate: Tensor | float | None = None, support: Tensor | float | None = None) dict[str, bool | None][source]

Tests if the arguments are valid for a Poisson distribution.

Parameters:
  • rate (torch.Tensor | float | None, optional) – expected rate of occurrences, \(\lambda\). Defaults to None.

  • support (torch.Tensor | float | None, optional) – number of occurrences, \(k\). Defaults to None.

Returns:

argument name and if it is valid, returned as a tensor of dtype torch.bool if a non-scalar tensor is given, None if not given.

Return type:

dict[str, torch.Tensor | bool | None]

Note

This considers a rate of zero valid, although strictly not true for Poisson distributions. A Poisson distribution with zero rate is the degenerate distribution.

classmethod variance(rate: Tensor | float) Tensor[source]

Computes the variance of the distribution.

\[\text{Var}[K \mid K \sim \text{Poisson}(\lambda)] = \lambda\]
Parameters:

rate (torch.Tensor | float) – expected rate of occurrences, \(\lambda\).

Returns:

variance of the distribution with given parameters.

Return type:

torch.Tensor