Skip to content

Commit 6cf4a7d

Browse files
Merge pull request #26 from samumbach/central-limit-theorem-convergence
Add post on central limit theorem
2 parents dd72d32 + 73a635c commit 6cf4a7d

File tree

2 files changed

+88
-1
lines changed

2 files changed

+88
-1
lines changed

site/db.edn

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,14 @@
4949
:image "https://avatars.githubusercontent.com/u/7443?v=4"
5050
:email "harold@techascent.com"
5151
:affiliation [:techascent]
52-
:links [{:icon "github" :text "GitHub" :href "https://github.com/harold"}]}]
52+
:links [{:icon "github" :text "GitHub" :href "https://github.com/harold"}]}
53+
{:id :samumbach
54+
:name "Sam Umbach"
55+
:url "https://github.com/samumbach"
56+
:image "https://avatars.githubusercontent.com/u/11580?v=4"
57+
:email "samumbach@gmail.com"
58+
:affiliation [:clojurecamp]
59+
:links [{:icon "github" :href "https://github.com/samumbach"}]}]
5360

5461
:affiliation
5562
[{:id :clojure.core
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
^{:kindly/hide-code true
2+
:clay {:title "Convergence of Random Events"
3+
:quarto {:author [:samumbach :timothypratley]
4+
:type :post
5+
:date "2025-06-25"
6+
:category :clojure
7+
:tags [:clojure.math]}}}
8+
(ns central-limit-theorem-convergence)
9+
10+
;; Life is full of random events.
11+
12+
;; We learn that multiple coin flips are "independent events" -- no matter whether the past flip was heads or tails, the next flip is 50/50.
13+
;; (So why do they show the last few results at the routlette table? Hint: Don't play routlette.)
14+
;; We learn that about half of babies are male and half female, so chances are 50/50 that your new little sibling will be a boy or a girl.
15+
16+
;; I found the answer to "Of my 8 children, what are the chances that 4 are girls and 4 are boys?" counterintuitive.
17+
;; The central limit theorem is crucial to intuition around this question.
18+
19+
;; When I initially encountered the Monte Hall problem, the correct answer wasn't obvious or intuitive, but the mathemetical explanation is surprisingly understandable. We'll try here to make the central limit theorem more understandable as well.
20+
21+
22+
;; Start with a single random event -- value drawn from [0.0, 1.0)
23+
(rand)
24+
25+
;; One way to combine random events is to take the average:
26+
(defn avg [nums]
27+
(/ (reduce + nums) (count nums)))
28+
29+
(avg [0.0 1.0])
30+
31+
;; Let's try taking the average of several events together:
32+
33+
(avg [(rand) (rand)])
34+
(avg [(rand) (rand) (rand)])
35+
36+
;; This is getting repetitive. We can make the computer repeat for us:
37+
38+
(avg (repeatedly 3 rand))
39+
40+
41+
;; The more events that you average, the closer the result comes to 0.5:
42+
43+
(avg (repeatedly 30 rand))
44+
(avg (repeatedly 300 rand))
45+
46+
47+
;; Let's try taking several events together:
48+
49+
(defn event []
50+
(rand))
51+
52+
(event)
53+
54+
(defn combined-event [number-of-events]
55+
(avg (repeatedly number-of-events event)))
56+
57+
(combined-event 1)
58+
(combined-event 2)
59+
(combined-event 5)
60+
61+
62+
;; Let's look at a series of multiple of these combined event
63+
64+
(repeatedly 5 #(combined-event 2))
65+
66+
(repeatedly 5 #(combined-event 5))
67+
68+
(repeatedly 5 #(combined-event 10))
69+
70+
71+
;; As we combine a larger number of events, the values cluster more closely to the middle of the original distribution.
72+
73+
;; And regardless of the shape of the original event distribution, the result of combining more and more events
74+
;; will approach the normal distribution -- it's a unique function toward which these combinations always
75+
;; converge.
76+
77+
;; This is true for both continuous variables (like `(rand)`) or discrete variables (like dice `(rand-nth [1 2 3 4 5 6])`),
78+
;; and it's true even for oddly shaped distributions. When you combine enough of them, they take on the character of the bell-shaped curve.
79+
80+
;; Learn More at [3Blue1Brown - But what is the Central Limit Theorem?](https://www.youtube.com/watch?v=zeJD6dqJ5lo)

0 commit comments

Comments
 (0)