📚 Central Limit Theorem: Randomness, Simulation and Computer Science | 中心极限定理:随机性、模拟与计算机科学
The central limit theorem (CLT) is often introduced as a pure statistics result, but in computer science it quietly supports simulation, performance testing, randomised algorithms, data analytics and machine learning. Whenever a system measures the average of many independent random events – request delays, benchmark runs, Monte Carlo samples or mini-batch gradients – the CLT explains why that average tends to follow a normal distribution.
中心极限定理(CLT)通常作为纯统计结论出现,但在计算机科学中,它默默支撑着模拟、性能测试、随机化算法、数据分析和机器学习。每当系统对许多独立随机事件取平均值时——例如请求延迟、基准测试运行、蒙特卡洛样本或小批量梯度——中心极限定理就解释了为什么这个平均值往往服从正态分布。
1. Why the CLT Belongs in Computer Science | 为什么中心极限定理属于计算机科学
Computer systems rarely behave in a purely deterministic way. Network packets arrive with jitter, disk I/O times vary, cache hits occur randomly, and user requests arrive in bursts. When we measure average behaviour – mean latency, mean throughput, mean reward in a reinforcement learning environment – we often add up many small random effects. The CLT gives a simple, powerful model for the resulting uncertainty.
计算机系统很少以完全确定的方式运行。网络数据包到达时带有抖动,磁盘 I/O 时间各不相同,缓存命中随机发生,用户请求会突发到达。当我们测量平均行为时——平均延迟、平均吞吐量、强化学习环境中的平均奖励——我们通常把许多微小的随机效应叠加起来。中心极限定理为由此产生的不确定性提供了一个简单而强大的模型。
2. Intuition: Adding Many Independent Random Effects | 直觉:叠加许多独立随机效应
Imagine summing the latencies of 200 independent HTTP requests. A single request might be very fast or very slow, so its histogram can be highly skewed. However, the total or average of 200 requests cannot be extreme unless most of them are extreme at the same time. This balancing effect makes the distribution of the average become more bell-shaped as the number of observations increases.
想象把 200 次独立 HTTP 请求的延迟相加。单次请求可能非常快或非常慢,因此它的直方图可能高度偏斜。然而,除非大多数请求同时极端,否则 200 次请求的总和或平均值不会极端。这种平衡效应使得随着观测数量的增加,平均值的分布变得更加钟形。
In computing terms, this is why a benchmark that averages many runs is more stable than a single run, and why a load test needs enough independent samples before its average response time is meaningful.
从计算角度看,这就是为什么多次运行取平均的基准测试比单次运行更稳定,也是为什么负载测试需要足够多的独立样本,平均响应时间才有意义。
3. Formal Statement of the CLT | 中心极限定理的正式表述
Let X₁, X₂, …, Xₙ be independent and identically distributed random variables with mean μ and finite variance σ². The sample mean is:
设 X₁、X₂、……、Xₙ 为独立同分布的随机变量,其均值为 μ,方差 σ² 有限。样本均值为:
X̄ = (X₁ + X₂ + … + Xₙ) ÷ n
The CLT states that the standardised sample mean approaches a standard normal distribution as n increases:
中心极限定理指出,随着 n 增大,标准化后的样本均值趋近标准正态分布:
Z = (X̄ − μ) ÷ (σ ÷ √n) → N(0, 1) as n → ∞
Equivalently, for large n, the sample mean is approximately normal with mean μ and variance σ²/n.
等价地,当 n 较大时,样本均值近似服从均值为 μ、方差为 σ²/n 的正态分布。
Key conditions: the observations must be independent, identically distributed, and have finite variance. Mild departures can still work in practice, but strong dependence or infinite variance can break the approximation.
关键条件:观测值必须独立、同分布,并且方差有限。轻微偏离在实践中仍可能成立,但强相关性或无限方差可能破坏近似。
4. Simulating the CLT with Pseudocode | 用伪代码模拟中心极限定理
A simple computational experiment can demonstrate the CLT. Suppose we generate values from a highly skewed distribution, such as an exponential delay or a discrete die-roll penalty, and repeatedly compute means of samples of size n. We then plot the distribution of those means.
一个简单的计算实验可以演示中心极限定理。假设我们从一个高度偏斜的分布中生成数值,例如指数延迟或离散的骰子惩罚,并反复计算样本量为 n 的样本均值,然后绘制这些均值的分布。
for trial = 1 to 5000:
total = 0
for i = 1 to n:
Published by TutorHao | A-Level Computer Science Revision Series | aleveler.com
更多咨询请联系16621398022(同微信)
屏轩国际教育cambridge primary/secondary checkpoint, cat4, ukiset,ukcat,igcse,alevel,PAT,STEP,MAT, ibdp,ap,ssat,sat,sat2课程辅导,国外大学本科硕士研究生博士课程论文辅导