Geometric
DistributionGeometric(probs: Tensor | float | None = None, logits: Tensor | float | None = None, validate_args: bool | None = None)Geometric distribution: number of failures before the first success.
Models the number of failed Bernoulli trials preceding the first success in an unbounded sequence of independent trials with success probability . This is the shifted convention (counting failures); the alternative convention counts trials including the success and starts at .
Parameters
Notes
Probability mass function:
Moments:
Memoryless property — the Geometric is the only discrete distribution with the memoryless property:
Continuous analogue: lucid.distributions.Exponential
(the only continuous memoryless distribution).
The expected number of trials (including the success) is ; entropy grows without bound as and is zero at .
Examples
>>> import lucid
>>> from lucid.distributions import Geometric
>>> d = Geometric(probs=0.25)
>>> d.mean # (1 - p)/p = 3.0
tensor(3.)
>>> d.sample((4,)).shape
(4,)
>>> d.log_prob(lucid.tensor(2.0)) # 2 log(0.75) + log(0.25)
tensor(-1.962)Used by 2
Constructors
1__init__
→None__init__(probs: Tensor | float | None = None, logits: Tensor | float | None = None, validate_args: bool | None = None)Construct a Geometric distribution.
Exactly one of probs or logits must be provided. The one
given is stored; the other is derived from it on access.
Parameters
Raises
ValueErrorprobs / logits are provided.Notes
The support is representing the number of failures before the first success. The PMF is:
Examples
>>> from lucid.distributions import Geometric
>>> d = Geometric(probs=0.25)
>>> d.mean # E[X] = (1-p)/p = 3
tensor(3.)Properties
2Instance methods
5Shannon entropy of the Geometric distribution (in nats).
The entropy grows without bound as (more uncertainty over many possible outcomes) and is zero at (certain success on first trial).
Returns
TensorEntropy in nats, shape batch_shape.
Examples
>>> Geometric(probs=0.5).entropy() # 2 log(2)
tensor(1.386)Log-odds — as given, or derived on access.
Derived from probs clamped one epsilon inside , as
the reference framework derives it.
Success probability — as given, or sigmoid(logits) on access.
Draw samples from the Geometric distribution.
Uses the inverse-CDF trick: if ,
A small epsilon clamp guards against which would produce . The returned tensor is detached since the Geometric is discrete.
Parameters
sample_shapetuple[int, ...]= ()sample_shape + batch_shape. Default is ().Returns
TensorNon-negative integer samples of shape sample_shape + batch_shape.
Examples
>>> lucid.manual_seed(0)
>>> d = Geometric(probs=0.5)
>>> x = d.sample((1000,))
>>> x.shape
(1000,)
>>> bool((x.mean() - 1.0).abs() < 0.2) # the sample mean approaches (1-p)/p
True