Beta
ExponentialFamilyBeta(concentration1: Tensor | float, concentration0: Tensor | float, validate_args: bool | None = None)Beta distribution on the open interval .
Two-parameter continuous distribution that is the conjugate prior
of the lucid.distributions.Bernoulli / Binomial likelihoods.
When it reduces to a Uniform on
; for large it concentrates
around .
Parameters
concentration1Tensor or floatconcentration0Tensor or floatvalidate_argsbool= NoneTrue, validate parameter constraints at construction time.Notes
Probability density on :
where .
Moments:
Mode: for .
Special cases / shapes:
- → .
- → symmetric around .
- with fixed mean → concentrates as a Gaussian about the mean.
- Bimodal (U-shaped) when both .
Conjugacy: observing successes out of
Bernoulli trials updates Beta(α, β) → Beta(α + k, β + n - k).
Sampling uses the ratio-of-Gammas method: with independent , . Since the underlying Gamma sampler is rejection-based, samples are detached.
Examples
>>> import lucid
>>> from lucid.distributions import Beta
>>> d = Beta(concentration1=2.0, concentration0=5.0)
>>> d.mean # 2/(2+5) ≈ 0.2857
Tensor(0.2857)
>>> d.sample((4,))
Tensor([...])
>>> d.log_prob(lucid.tensor(0.3))
Tensor(...)Methods (6)
__init__
→None__init__(concentration1: Tensor | float, concentration0: Tensor | float, validate_args: bool | None = None)Construct a Beta distribution.
Parameters
concentration1Tensor | floatconcentration1). Controls how much mass is near 1.concentration0Tensor | floatconcentration0). Controls how much mass is near 0.validate_argsbool | None= NoneTrue, validate parameter constraints at construction time.Notes
The Beta distribution has PDF:
where .
Sampling uses the ratio-of-Gammas method: where .
Examples
>>> from lucid.distributions import Beta
>>> d = Beta(concentration1=2.0, concentration0=5.0)
>>> d.mean # α/(α+β) = 2/7 ≈ 0.286
Tensor(0.2857)mean
→Tensormean: TensorExpected value of the Beta distribution.
Returns
TensorMean , shape batch_shape.
Examples
>>> Beta(concentration1=1.0, concentration0=1.0).mean
Tensor(0.5)variance
→Tensorvariance: TensorVariance of the Beta distribution.
Returns
TensorVariance, shape batch_shape.
Examples
>>> Beta(concentration1=2.0, concentration0=2.0).variance
Tensor(0.05)sample
→Tensorsample(sample_shape: tuple[int, ...] = ())Draw samples from the Beta distribution.
Uses the ratio-of-independent-Gamma-samples identity:
The result is detached since the underlying Gamma sampler is rejection-based and does not support reparameterisation.
Parameters
sample_shapetuple[int, ...]= ()().Returns
TensorSamples in of shape sample_shape + batch_shape.
Examples
>>> d = Beta(concentration1=2.0, concentration0=5.0)
>>> x = d.sample((500,))
>>> x.mean() # approximately 2/7 ≈ 0.286log_prob
→Tensorlog_prob(value: Tensor)Log-density of value under the Beta distribution.
Parameters
valueTensorReturns
TensorElement-wise log-densities, shape batch_shape.
entropy
→Tensorentropy()Shannon entropy of the Beta distribution (in nats).
where is the digamma function and .
Returns
TensorEntropy in nats, shape batch_shape.