Runoob Tutorial ArchiveEnglish

Continuous Random Variables and Common Distributions

Continuous Random Variables and Common Distributions

The value of a continuous random variable can be any value on the real number line. The normal (Gaussian) distribution is the most important distribution in AI, without exception.


Concept Analysis

PDF: Probability Density Function

The PDF is not the probability itself; the area is the probability. The PDF value f(x) at a certain point has no meaning—the probability that a continuous variable equals a specific value is exactly 0. However, the integral of the PDF over an interval = the probability that X falls within that interval.

Normal Distribution N(μ, σ²)

[ f(x) = \frac{1}{\sigma\sqrt{2\pi}} \exp\left(-\frac{(x-\mu)^2}{2\sigma^2}\right) ]

Determined by the mean $\mu$ (position) and standard deviation $\sigma$ (width). Approximately 68% of data falls within $\mu\pm\sigma$, and approximately 95% falls within $\mu\pm2\sigma$.

Central Limit Theorem

The superposition of many independent factors $\rightarrow$ the result tends towards a normal distribution. This explains why the normal distribution is ubiquitous in nature and AI.

Neural network weight initialization, Batch Normalization, VAE latent space, and the denoising process of diffusion models all rely on the normal distribution.


Real-life examples

Human height: 170.1, 170.12, 170.128 cm—height can take any value within a continuous range, and the overall distribution follows a normal distribution.

Most people's heights are close to the average, and extremely tall or short people are the minority—this is the bell curve.


Hands-on practice with Python

Instance

import

numpy

as

np

samples

=

np.

random

.

normal

(

0

,

1

,

10000

)

print

(

f

"N(0,1) sampling: Mean={samples.mean():.3f}, Standard Deviation={samples.std():.3f}"

)

68-95-99.7 rule

for

k

in

[

1

,

2

,

3

]

:

within

=

np.

mean

(

np.

abs

(

samples

)

<

k

)

theory

=

{

1

:

0.6827

,

2

:

0.9545

,

3

:

0.9973

}

[

k

]

   

print

(

f

"μ±{k}σ: {within:.4f} (theoretical {theory:.4f})"

)

Central Limit Theorem: 12 dice and ≈ normal

dice

=

np.

random

.

randint

(

1

,

7

,

(

100000

,

12

)

)

.

sum

(

axis

=

1

)

print

(

f

"\n12 dice and: mean={dice.mean():.1f}(theoretical 42), close to normal"

)

Running output:

Original prompt (Chinese, left untranslated)



N(0,1) 采样: 均值=-0.002, 标准差=1.001

μ±1σ: 0.6827 (理论 0.6827)

μ±2σ: 0.9545 (理论 0.9545)

μ±3σ: 0.9973 (理论 0.9973)



12个骰子和: 均值=42.0(理论42), 接近正态

Normal distribution histogram


Application Scenarios in AI

Weight Initialization

Neural network weights are usually initialized randomly from a normal or uniform distribution. Kaiming initialization (for ReLU networks): ( W \sim N(0, \sqrt{2/n_{in}}) ); Xavier initialization: ( W \sim U(-\sqrt{6/(n_{in}+n_{out})}, \sqrt{6/(n_{in}+n_{out})}) ). Carefully chosen variance ensures stable signal propagation during forward and backward propagation, preventing explosion or vanishing.

Batch Normalization

BN assumes that the activation values of each layer are approximately normally distributed, standardizing them to N(0,1) by subtracting the mean and dividing by the standard deviation, and then scaling and shifting them through learnable parameters (\gamma) and (\beta). This accelerates training, allows for larger learning rates, and reduces sensitivity to initialization. BN is one of the most important training techniques in the history of deep learning.

Latent Space Assumption of VAE

Variational Autoencoders assume that the latent variable z follows a standard normal distribution N(0, I). The encoder outputs $\mu$ and $\log(\sigma^2)$, and the decoder samples z from N($\mu, \sigma^2$) to reconstruct the input. The KL divergence loss constrains N($\mu, \sigma^2$) to be close to the prior N(0, I), preventing the encoder from collapsing to a Dirac distribution.

Noise Addition and Denoising in Diffusion Models

The forward process of diffusion models (DDPM) gradually adds Gaussian noise $\epsilon \sim N(0, I)$ to the data until it becomes pure noise. The reverse process trains a neural network to predict the noise added at each step, gradually denoising from pure noise to generate images. Stable Diffusion and DALL·E are both based on this principle.