Skip to content

Instantly share code, notes, and snippets.

@radiodario
Last active August 29, 2015 14:00
Show Gist options
  • Save radiodario/11171571 to your computer and use it in GitHub Desktop.
Save radiodario/11171571 to your computer and use it in GitHub Desktop.
Central Limit Theorem

Central limit theorem

In probability theory, the central limit theorem (CLT) states that, given certain conditions, the arithmetic mean of a sufficiently large number of iterates of independent random variables, each with a well-defined expected value and well-defined variance, will be approximately normally distributed.[1] That is, suppose that a sample is obtained containing a large number of observations, each observation being randomly generated in a way that does not depend on the values of the other observations, and that the arithmetic average of the observed values is computed. If this procedure is performed many times, the central limit theorem says that the computed values of the average will be distributed according to the normal distribution (commonly known as a "bell curve").

var TRIALSZ = 100;
var NTRIALS = 20000;
var THZ = 500;
var HZ = TRIALSZ * THZ;
var PTS = TRIALSZ * NTRIALS;
var TBATCH = 1 / THZ;
var $now = Date.now();
function flip() => (Math.random() > 0.5) ? 1 : -1;
emitter -hz HZ -limit PTS -start $now | pacer
| put toss=flip() | batch TBATCH
| collect time=now(), total=sum(toss), bucket = Math.round(total/2)
| batch 0.1
| collect* cnt=count(bucket) by bucket
| @chart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment