Normal
ExponentialFamilyNormal(loc: Tensor | float, scale: Tensor | float, validate_args: bool | None = None)Univariate Gaussian (Normal) distribution .
The Normal distribution is arguably the most important distribution in probability and statistics. Its probability density function is the iconic bell curve:
where is the location (mean) and is the scale (standard deviation).
Parameters
locTensor or floatscaleTensor or floatloc.validate_argsbool or None= NoneNone.Attributes
locTensorscaleTensorNotes
Location-scale family
The Normal distribution is closed under linear transformations: if then . In particular the standard Normal satisfies .
Central Limit Theorem
By the CLT, the (rescaled) sum of i.i.d. random variables with finite mean and variance converges in distribution to a Normal. This explains why the Normal appears naturally across virtually all domains of science and engineering.
Reparameterisation
has_rsample = True — samples are drawn via the standard-Normal
reparameterisation trick:
so gradients flow through and .
Exponential family
The Normal is an exponential-family distribution with natural parameters , and sufficient statistics .
Examples
>>> import lucid.distributions as dist
>>> d = dist.Normal(loc=0.0, scale=1.0)
>>> d.mean
Tensor(0.)
>>> d.variance
Tensor(1.)
>>> x = d.rsample((5,)) # 5 standard-Normal draws
>>> lp = d.log_prob(x) # evaluate log-density at those pointsMethods (10)
__init__
→None__init__(loc: Tensor | float, scale: Tensor | float, validate_args: bool | None = None)Construct a Normal distribution.
Parameters
locTensor or floatscaleTensor or floatvalidate_argsbool or None= Nonemean
→Tensormean: TensorMean of the Normal distribution.
For ,
Returns
TensorThe loc parameter tensor (shape batch_shape).
mode
→Tensormode: TensorMode of the Normal distribution.
The Normal density is symmetric and unimodal; its unique maximum is at .
Returns
TensorThe loc parameter tensor (shape batch_shape).
variance
→Tensorvariance: TensorVariance of the Normal distribution.
Returns
TensorElement-wise square of scale (shape batch_shape).
stddev
→Tensorstddev: TensorStandard deviation of the Normal distribution.
Overrides the base-class default (which would compute
variance.sqrt()) for a cheaper, exact result.
Returns
TensorThe scale parameter tensor (shape batch_shape).
rsample
→Tensorrsample(sample_shape: tuple[int, ...] = ())Draw reparameterised samples via the location-scale trick.
Samples are generated as
Because the stochasticity is isolated in
(which does not depend on the parameters), gradients flow back
through both loc () and scale
().
Parameters
sample_shapetuple[int, ...]= ()Returns
TensorSamples of shape sample_shape + batch_shape, attached
to the autograd graph.
log_prob
→Tensorlog_prob(value: Tensor)Log-probability density of the Normal distribution.
This is computed in a numerically stable form using
log_scale rather than squaring and dividing.
Parameters
valueTensorReturns
TensorLog-density at value, shape
broadcast(value, batch_shape).
cdf
→Tensorcdf(value: Tensor)Cumulative distribution function of the Normal distribution.
Expressed in terms of the Gauss error function:
Parameters
valueTensorReturns
TensorProbabilities in .
icdf
→Tensoricdf(value: Tensor)Inverse CDF (quantile function / probit function) of the Normal.
Parameters
valueTensorReturns
TensorCorresponding quantiles .
entropy
→Tensorentropy()Shannon differential entropy of the Normal distribution.
The Normal maximises entropy among all distributions with fixed mean and variance. The closed-form entropy is
Measured in nats.
Returns
TensorEntropy values of shape batch_shape.