Skip to content
class

Poisson

extendsExponentialFamily
Poisson(rate: Tensor | float, validate_args: bool | None = None)

Poisson distribution over the non-negative integers.

Models the number of events occurring in a fixed interval when events happen independently at a constant mean rate λ\lambda. The Poisson distribution is the limiting case of a Binomial as n→∞n \to \infty and p→0p \to 0 with np=λnp = \lambda fixed.

Parameters

rateTensor | float
Mean rate λ≥0\lambda \geq 0. Determines both the mean and the variance of the distribution.
validate_argsbool | None= None
If True, validate parameter constraints at construction time.

Attributes

rateTensor
The mean rate parameter λ\lambda.

Notes

PMF (probability mass function):

P(X=k)=λke−λk!,k∈{0,1,2,…}P(X = k) = \frac{\lambda^k e^{-\lambda}}{k!}, \quad k \in \{0, 1, 2, \ldots\}

Moments:

  • Mean: E[X]=λE[X] = \lambda
  • Variance: Var⁡[X]=λ\operatorname{Var}[X] = \lambda
  • Mode: ⌊λ⌋\lfloor \lambda \rfloor

The log-probability is computed as klog⁡λ−λ−log⁡Γ(k+1)k \log \lambda - \lambda - \log\Gamma(k+1), which is numerically stable via the lgamma function.

The Poisson has no closed-form entropy (it is an infinite sum over all non-negative integers), so entropy raises NotImplementedError.

Examples

>>> import lucid
>>> from lucid.distributions import Poisson
>>> dist = Poisson(rate=3.5)
>>> samples = dist.sample((100,))
>>> samples.shape
(100,)
>>> # log-probability at k=4
>>> dist.log_prob(lucid.tensor(4.0))
tensor(-1.667)

Used by 3

Constructors

1
dunder

__init__

→None
__init__(rate: Tensor | float, validate_args: bool | None = None)

Initialise a Poisson distribution.

Parameters

rateTensor | float
Mean rate parameter λ≥0\lambda \geq 0. Determines both the mean and the variance.
validate_argsbool | None= None
If True, validate parameter constraints at construction time.

Properties

3
prop

mean

→Tensor
mean: Tensor

Mean of the Poisson distribution: E[X]=λE[X] = \lambda.

Returns

Tensor

Mean values equal to rate, shape batch_shape.

prop

mode

→Tensor
mode: Tensor

Mode of the Poisson distribution: ⌊λ⌋\lfloor \lambda \rfloor.

When λ\lambda is an integer, both λ\lambda and λ−1\lambda - 1 are modes; this property returns ⌊λ⌋\lfloor \lambda \rfloor.

Returns

Tensor

Mode values of shape batch_shape.

prop

variance

→Tensor
variance: Tensor

Variance of the Poisson distribution: Var⁡[X]=λ\operatorname{Var}[X] = \lambda.

Returns

Tensor

Variance values equal to rate, shape batch_shape.

Instance methods

4
fn

entropy

→Tensor
entropy()

Entropy of the Poisson distribution (not available in closed form).

The Poisson entropy is an infinite sum over all non-negative integers and has no simple closed form.

Raises

NotImplementedError
Always — use numerical approximation if needed.
fn

expand

→Self
expand(batch_shape: Sequence[int], _instance: Self | None = None)

Return a new Poisson instance with parameters expanded to batch_shape.

fn

log_prob

→Tensor
log_prob(value: Tensor)

Log-probability of the given counts under the Poisson distribution.

log⁡P(X=k)=klog⁡λ−λ−log⁡Γ(k+1)\log P(X = k) = k \log \lambda - \lambda - \log\Gamma(k + 1)

klog⁡λk \log \lambda is taken as 0 at k=0k = 0, so a zero rate scores a zero count as log⁡1=0\log 1 = 0 rather than 0 · (-inf) = NaN.

Parameters

valueTensor
Non-negative integer counts k≥0k \geq 0.

Returns

Tensor

Log-probability values of the same shape as value.

fn

sample

→Tensor
sample(sample_shape: tuple[int, ...] = ())

Draw samples from the Poisson distribution.

Delegates to lucid.poisson, which is exact for every λ\lambda (inversion below 10, PTRS transformed rejection above).

Parameters

sample_shapetuple[int, ...]= ()
Leading shape of the output sample batch.

Returns

Tensor

Counts of shape (*sample_shape, *batch_shape) held in rate's floating dtype.