math
Get Notion free
Page icon

math

description
concept
memoryless, waiting
geometric, exponential
trials with success & failure
Bernoulli, binomial
large sample, average
CLT, approximately Gaussian
bound given only mean / variance
Markov / Chebyshev inequalities
estimating parameter from data
MLE, MAP, Bayesian update
update belief from evidence
Bayes rule
function of a RV
Jensen’s inequality
expected count of things
linearity + indicators
expected hitting time / return probability
first-step analysis, solve recurrence
Markov property (future depends only on present)
first-step analysis

Distributions

discrete
continuous
counting
binomial: how many successes in nn trials?
Poisson: how many events in fixed window?
waiting
geometric: how many trials until first success?
exponential: how long until first event?

Discrete

Bernoulli

bernoulli RV XBernoulli(p)X\sim\operatorname{Bernoulli}(p) models a single trial with pp probability of success
compact PMF form
E[X]=p\mathbb E[X]=p, Var[X]=p(1p)\text{Var}[X]=p(1-p)
proof
E[X]=1p+0(1p)=p\mathbb E[X]=1\cdot p+0\cdot (1-p)=p
E[X2]=12p+02(1p)=p\mathbb E[X^2]=1^2\cdot p+0^2\cdot (1-p)=p
Var[X]=E[X2]E[X]2=pp2=p(1p)\operatorname{Var}[X]=\mathbb E[X^2]-\mathbb E[X]^2=p-p^2=p(1-p)
categorial RV generalizes Bernoulli from 2 to kk outcomes
each item ii is Bernoulli(pi)\operatorname{Bernoulli}(p_i), so E[Xi]=pi\mathbb E[X_i]=p_i and Var(Xi)=pi(1pi)\operatorname{Var}(X_i)=p_i(1-p_i)
handy techniques
indicator squaring: for any binary variable X{0,1}X\in\{0,1\}, X2=XX^2=X so E[X2]=E[X]\mathbb E[X^2]=\mathbb E[X]

Binomial

binomial RV XBinomial(n,p)X\sim\operatorname{Binomial}(n,p) is the sum of nn independent Bernoulli(p)\text{Bernoulli}(p) trials
X=i=1nXiX=\sum_{i=1}^n X_i where XiBernoulli(p)X_i\sim\operatorname{Bernoulli}(p)
every sequence with kk successes has the same probability pk(1p)nkp^k(1-p)^{n-k}, and there are (nk)\binom nk such sequences
Binomial theorem
we can verify that kP(X=k)=1\sum_k P(X=k)=1
E[X]=np\mathbb E[X]=np, Var[X]=np(1p)\text{Var}[X]=np(1-p)
proof
E[X]=E[i=1nXi]=i=1nE[Xi]=np\mathbb E[X]=\mathbb E\left[\sum_{i=1}^n X_i\right]=\sum_{i=1}^n\mathbb E[X_i]=np
Var[X]=Var[i=1nXi]=i=1nVar[Xi]=np(1p)\operatorname{Var}[X]=\operatorname{Var}[\sum_{i=1}^nX_i]=\sum_{i=1}^n\operatorname{Var}[X_i]=np(1-p) (second equality follows because the XiX_i are independent)
handy techniques
decompose into Bernoulli and use linearity of expectation
decompose X2X^2 into cross-terms
this makes computing expectation easy (using the fact that Xi2=XiX_i^2=X_i for indicator variables)

Poisson

Poisson RV XPoisson(λ)X\sim\operatorname{Poisson}(\lambda) models the number of events in a fixed interval when they occur independently at an average rate of λ\lambda over that interval
the number of events in interval of length tt distributed as N(t)Poisson(λt)N(t)\sim\operatorname{Poisson}(\lambda t)
derivation using binomial limit: divide the fixed interval into nn tiny time intervals, assuming it is small enough that at most one event occurs in each interval
then the total count is Binomial(n,p)\operatorname{Binomial}(n,p) with np=λnp=\lambda
E[X]=Var[X]=λ\mathbb E[X]=\text{Var}[X]=\lambda
E[X]=λ\mathbb E[X]=\lambda is basically the definition of rate λ\lambda
sums of independent Poisson are Poisson, with rates that add
can be derived using MGF uniqueness

Geometric

geometric RV XGeometric(p)X\sim\operatorname{Geometric}(p) models the number of Bernoulli trials XX until first success (inclusive), where each trial has pp probability of success
the tail probability is a pure power of (1p)(1-p)
memoryless: P(X>m+nX>m)=P(X>n)P(X>m+n\mid X>m)=P(X>n)
the fact that you’ve failed mm times already is irrelevant
the geometric distribution is the only memoryless distribution on the positive integers     \iff any discrete waiting-time distribution that is memoryless must be geometric
the geometric series looks like k=0rk\sum_{k=0}^\infty r^k
converges for r<1\lvert r\rvert <1 to 11r\frac{1}{1-r}, diverges otherwise
can try to remember this by checking that for r=2r=2, k=01/2k2\sum_{k=0}^\infty 1/2^k\to2
sanity check: PMF sums to 1
expected wait time E[X]=1/p\mathbb E[X]=1/p
direct solution: X=kX=k means k1k-1 failures
a little tricky to solve but gives E[X]=1/p\mathbb E[X]=1/p
solution based on first-step analysis: on the first flip, we succeed with probability pp (X=1X=1) and fail with probability 1p1-p, in which case we’re back to where we started (X=1+E[X]X=1+\mathbb E[X])
algebra then produces E[X]=1p\mathbb E[X]=\frac 1p
intuition: every trial has pp change of ending the process, so on average we need 1/p1/p attempts
Var(X)=1pp2\operatorname{Var}(X)=\frac{1-p}{p^2}
as p0p\to 0, both mean and variance blow up
rare successes have high variability in waiting time
handy techniques
first-step analysis
re-index using i=k1i=k-1, turning k=1\sum_{k=1}^\infty to i=0\sum_{i=0}^\infty

Continuous

Uniform

uniform RV XUniform(a,b)X\sim\operatorname{Uniform}(a,b) on [a,b][a,b] means XX is equally likely to be anywhere on the interval [a,b][a,b]
E[X]=a+b2\mathbb E[X]=\frac{a+b}{2}
Var(X)=(ba)212\operatorname{Var}(X)=\frac{(b-a)^2}{12}
PDF
CDF
difference between two uniform distributions is triangular
the n+1n+1 gaps between nn uniform points are distributed the same way

Exponential

exponential RV XExp(λ)X\sim\operatorname{Exp}(\lambda) with rate λ\lambda models waiting time until the next event, where events happen at an average rate of λ\lambda per unit time
equivalently, waiting time until first event in a Poisson process with rate λ\lambda
tail formula (aka survival function)
memoryless: P(X>s+tX>s)=P(X>t)P(X>s+t\mid X>s)=P(X>t)
the fact that you’ve waited for ss units of time already is irrelevant
the exponential is the only continuous distribution on [0,][0,\infty] that is memoryless
continuous analog to the geometric: waiting time in continuous time
E[X]=1λ\mathbb E[X]=\frac 1\lambda, Var(X)=1λ2\operatorname{Var}(X)=\frac{1}{\lambda^2}
if events happen at rate λ\lambda/unit time on average, then on average you need to wait 1/λ1/\lambda units of time between events
relation between Poisson and exponential
two equivalent statements
number of events in unit interval is Poisson(λ)\operatorname{Poisson}(\lambda)
inter-event time is Exp(λ)\operatorname{Exp}(\lambda)
how many events in the next hour? → Poisson
how long until the next event? → exponential
minimum of exponentials: if X1Exp(λ1)X_1\sim\operatorname{Exp}(\lambda_1) and X2Exp(λ2)X_2\sim\operatorname{Exp}(\lambda_2) are independent, then
intuition: if emails arrive at rate λ1\lambda_1 and texts at rate λ2\lambda_2, then the waiting time for “either an email or a text” is exponential with rate λ1+λ2\lambda_1+\lambda_2
proof
which is the tail function of Exp(λ1+λ2)\operatorname{Exp}(\lambda_1+\lambda_2)

Gaussian

Gaussian RV XN(μ,σ2)X\sim \mathcal N(\mu,\sigma^2) with mean μ\mu and variance σ2\sigma^2
relationship between general and standard normal RV
subtract the mean to shift to 0, divideå by standard dev to rescale to unit variance
example: if heights are normally distributed with μ=70\mu=70 and σ=3\sigma=3, what fraction of people are taller than 76 inches?
the percentile zαz_\alpha is the value such that
i.e., zαz_\alpha is the point on the axis with probability mass α\alpha to the left
symmetry: z1α=zαz_{1-\alpha}=-z_\alpha
2-sided intervals: P(Zz1α/2)=1α    P(Z>z1α/2)=αP(\lvert Z\rvert\leq z_{1-\alpha/2})=1-\alpha\iff P(\lvert Z\rvert > z_{1-\alpha/2})=\alpha
a (1α)(1-\alpha) confidence interval uses zα/2z_{\alpha/2} and z1α/2z_{1-\alpha/2} as endpoints
stated as bounds: P(Zc)1α    cz1α/2P(\lvert Z\rvert\leq c)\geq 1-\alpha\iff c\geq z_{1-\alpha/2}
this also means that for XN(μ,σ2)X\sim\mathcal N(\mu,\sigma^2), the α\alpha-percentile is xα=μ+σzαx_\alpha=\mu+\sigma\cdot z_\alpha
sum of independent Gaussians is Gaussian: if X1N(μ1,σ12)X_1\sim \mathcal N(\mu_1,\sigma_1^2) and X2N(μ2,σ22)X_2\sim \mathcal N(\mu_2,\sigma_2^2), then

Expectations & variance

expectation
expectation of a function over XX
tail formula for non-negative RVs
variance
linearity of expectation (regardless of independence)
for independent XX and YY
if XX and YY are independent, then

Zoo of functions

probability mass function (PMF) of discrete RVs
properties
p(k)0p(k)\geq 0
kp(k)=1\sum_k p(k)=1
probability density function (PDF) of continuous RVs
differentiate CDF to get PDF: f(x)=F(x)f(x)=F'(x)
cumulative distribution function (CDF) for both discrete and continuous RVs
for discrete: F(x)=kxp(k)F(x)=\sum_{k\leq x} p(k)
for continuous: F(x)=xf(x)dxF(x)=\int_{-\infty}^x f(x)\, dx
note P(axb)=F(b)F(a)P(a\leq x\leq b)=F(b)-F(a)

Inequalities

Markov’s inequality: for any non-negative RV XX and a>0a>0,
intuitively, E[X]\mathbb E[X] cannot be smaller than the contribution of values greater than aa
proof
Chebyshev’s inequality: for any RV XX with mean μ\mu and variance σ2\sigma^2
at least 11/k21-1/k^2 of the distribution lies within kk standard deviations of the mean
e.g., 75% of probability mass sits within 2 standard deviations
proof: apply Markov to (Xμ)2(X-\mu)^2
another form, by substituting ϵ=kσ\epsilon=k\sigma
Jensen’s inequality describes how expectations interact with convex/concave transformations
to remember, use φ(x)=x2\varphi(x)=x^2 (convex) with X{1,+1}X\in\{-1,+1\}
φ(E[X])=φ(0)=0\varphi(\mathbb E[X])=\varphi(0)=0
E[φ(X)]=1\mathbb E[\varphi(X)]=1
convex functions have φ0\varphi^{\prime\prime}\geq0 everywhere (slope is increasing)
x2x^2, x4x^4, … (xnx^n for any even nn)
x\lvert x\rvert
axa^x (for a>1a>1)
1/x1/x (for x>0x>0)
max(x1,x2,)\max(x_1,x_2,…)
concave functions have φ0\varphi^{\prime\prime}\leq 0 everywhere (slope is decreasing)
x\sqrt{x}
logx\log x
xpx^p for 0<p<10<p<1
min(x1,x2,)\min(x_1,x_2,…)
linear functions are both convex and concave
worth memorizing: logE[X]E[logX]\log\mathbb E[X]\geq\mathbb E[\log X]
AM-GM inequality (arithmetic mean, geometric mean): arithmetic mean always \geq geometric mean
proof: take log of both sides, apply Jensen’s inequality (using the fact that log is concave), then exponentiate both sides
Cauchy-Schwarz inequality
another form
union bound

Conditional probabilities

suppose we have two random variables, XX and YY
joint distribution: P(X=x,Y=y)P(X=x,Y=y)
marginal distribution: P(X=x)=yP(X=x,Y=y)P(X=x)=\sum_y P(X=x,Y=y)
conditional distribution: P(X=xY=y)P(X=x\mid Y=y)
Bayes rule
P(A)P(A) is the prior (what we believed before seeing BB)
P(AB)P(A\mid B) is the posterior (what we believed after seeing BB)
calculate P(B)P(B) with law of total probability
law of total expectation (also known as the tower property)
can also be stated as E[X]=EY[E[XY]]\mathbb E[X]=\mathbb E_Y[\mathbb E[X\mid Y]]
note that in this statement, E[XY]\mathbb E[X\mid Y] is itself RV expressed in terms of YY
law of total probability

Limit theorems

central limit theorem: mean of nn iid RVs XiX_i with mean μ\mu and variance σ2\sigma^2 is Gaussian, no matter what the XiX_i look like
derivation of variance
standard error is the standard deviation of Xˉn\bar X_n, which is σ/n\sigma/\sqrt n
what it means: error shrinks like n\sqrt n, need 100x samples to reduce error 10x
(1α)(1-\alpha) confidence interval is given by
law of large numbers: mean of nn iid RVs XiX_i with mean μ\mu converges to the true average
proof from Chebyshev’s (substitute ϵ=kσ\epsilon=k\sigma)

Some problem types

First-step analysis

what’s the expected number of coin flips to get two heads in a row?
let
E0E_0 = expected flips to finish after just flipping tails (or just started)
E1E_1 = expected flips after just flipping heads
then solve system of linear equations to get E0=6E_0=6
Callout icon
first-step analysis trick: focus on the first step of the process, and express the expectations we want to solve for in terms of themselves. then solve system of linear equations.

Counting in expectation

how many things are expected to satisfy some property?
define Xi=1[item i has property]X_i=\mathbb 1[\text{item }i\text{ has property}]
define a sum of indicator random variables N=iXiN=\sum_i X_i
compute E[Xi]=P(Xi)\mathbb E[X_i]=P(X_i) for each ii (use symmetry)
apply linearity of expectation: E[N]=iP(Xi)\mathbb E[N]=\sum_i P(X_i)
examples: expected number of fixed points in a random permutation
by symmetry, position ii equally likely to have any item, so P(Xi=1)=1/nP(X_i=1)=1/n

Max/min of nn RVs

if X1,,XnX_1,…,X_n are iid with common CDF FXF_X
for the max M=maxiXiM=\max_i X_i,
for the min m=miniXim=\min_i X_i,
two different approaches to calculate expectation of min or max
3-step recipe: CDF → PDF → integrate
for non-negative RVs, can use tail formula directly E[X]=0P(X>x)dx\mathbb E[X]=\int_{0}^\infty P(X>x)\,dx
let’s do this for XiUniform[0,1]X_i\sim\operatorname{Uniform}[0,1]
max M=maxiXiM=\max_i X_i
CDF: FM(x)=i=1nP(Xix)=xnF_M(x)=\prod_{i=1}^n P(X_i\leq x)=x^n
PDF: fM(x)=ddxxn=nxn1f_M(x)=\frac{d}{dx}x^n=nx^{n-1}
expectation: E[M]=01xnxn1dx=n01xndx=nn+1\mathbb E[M]=\int_0^1 x\cdot nx^{n-1}\,dx=n\int_0^1 x^n\,dx=\frac{n}{n+1}
intuition: nn uniform points XiX_i split the segment into n+1n+1 segments which are all equivalently distributed (by symmetry), so each must have mean length 1/(n+1)1/(n+1)
alternatively with tail formula: E[M]=01(1xn)dx=xxn+1n+101=nn+1\mathbb E[M]=\int_0^1 (1-x^n)\,dx=x-\frac{x^{n+1}}{n+1}\rvert ^1_0=\frac{n}{n+1}
min m=miniXim=\min_i X_i
P(m>x)=(1x)nP(m>x)=(1-x)^n
CDF: Fm(x)=P(mx)=1P(mx)=1(1x)nF_m(x)=P(m\leq x)=1-P(m\geq x)=1-(1-x)^n
PDF: fm(x)=ddxFm(x)=n(1x)n1f_m(x)=\frac{d}{dx} F_m(x)=n(1-x)^{n-1}
expectation: E[m]=01xn(1x)n1dx=1n+1\mathbb E[m]=\int_0^1 x\cdot n(1-x)^{n-1}\,dx=\frac{1}{n+1}
for XiExponential(λ)X_i\sim\operatorname{Exponential}(\lambda)
min
P(m>x)=[P(Xi>x)]n=enλxP(m>x)=[P(X_i>x)]^n=e^{-n\lambda x}
E[m]=0enλxdx=1nλ\mathbb E[m]=\int_0^\infty e^{-n\lambda x}\,dx =\frac{1}{n\lambda}
max is a lot more complicated, but good to know that it grows logarithmically with nn
for XiN(0,1)X_i\sim\mathcal N(0,1), E[maxiXi]2lnn\mathbb E[\max_iX_i]\approx\sqrt{2\ln n} (this is pretty difficult to derive)

Combinatorics

combination: choosing kk items from nn, order doesn’t matter
the relation to permutation: every set of kk items can be arranged in k!k! orders, and combinations collapse the orderings into one
permutation: arranging kk items from nn, order matters
number of ways to arrange nn objects when there are n1n_1 of type 1, n2n_2 of type 2, …
permute all nn objects, the divide out the rearrangements of items within each type
a derangement is a permutation with no fixed points
combination with replacement: choosing kk items from nn types with replacement
this is the stars and bars argument: each choice can be represented as a sequence of stars and bars, where there are kk stars and n1n-1 bars → this is choosing kk placements of stars from n+k1n+k-1 positions
how many ways are there to write non-negative integer nn has sum of kk non-negative integers?
visualize nn stars with k1k-1 bars among them
order matters?
replacement?
count
yes
no
n!(nk)!\frac{n!}{(n-k)!} (permutations)
no
no
(nk)\binom nk (combinations)
yes
yes
nkn^k
no
yes
(n+k1k)\binom{n+k-1}{k} (stars and bars)
inclusion-exclusion principle
as counts

Markov chains

Markov chain is a sequence of RVs X0,X1,X2,X_0,X_1,X_2,… taking values in some state space SS satisfying the Markov property: the future depends only on the present
for finite state spaces, the chain is described by the transition matrix PP where Pij=P(Xt+1=jXt=i)P_{ij}=P(X_{t+1}=j\mid X_t=i)
rows sum to 1 and are probability distributions over next-states
if πt\pi_t is the distribution over states at time tt, then πt+1=πtP\pi_{t+1}=\pi_t P
a stationary distribution satisfies π=πP\pi=\pi P
under mild conditions, the chain has a unique stationary distribution and πtπ\pi_t\to\pi regardless of where we started
the expected return time is the reciprocal of its stationary probability
general principle to solve for expected absorption time
use first-step analysis to express the recurrence
expected time hjh_j to absorption from state jj
hA=0h_A=0 for target absorbing state AA
probability of absorption qjq_j from state jj
qA=1q_A=1 for desired absorbing state AA, and qB=0q_B=0 for all other absorbing states BB
solve recurrence
for small chains, can just solve the linear system
for chains with structure, guess a closed form and verify
to make an educated guess, compute the answer for small cases and try to generalize
think about what makes sense in terms of function shape
fit boundary conditions
handy techniques
symmetry can allow you to collapse equivalent states
for a random walk on a circle, easier to reparameterize hih_i to be expected hitting time from a particular distance rather than from a particular state
use stationary distribution to provide shortcuts for expected hitting time
on a graph where every node looks the same (cycles, complete graphs, etc.), expected hitting time hh between adjacent vertices is always n1n-1 where nn is the number of nodes
this is because E[return to self]=n\mathbb E[\text{return to self}]=n (since stationary distribution has 1/n1/n everywhere)
and E[return to self]=1+h\mathbb E[\text{return to self}]=1+h because each of the dd adjacent nodes contributes 1dh\frac1dh

Puzzles

Birthday problem

how many people nn does it take so that the probability of two people having the same birthday exceeds 50%?
P(collision)=1P(all unique birthdays)P(\text{collision}) = 1 - P(\text{all unique birthdays})
let dd be number of days in the year and nn the number of people

Gambler’s ruin

you start with $aa dollars
win $1 with probability pp and lose $1 with probability 1p1-p
stop when you reach $NN (you win) or $0 (you’re ruined)
probability you reach $NN?
let PiP_i be probability of reaching NN starting from ii
boundary conditions: P0=0,PN=1P_0=0,P_N=1
for any starting amount 0<i<N0<i<N,
second-order linear recurrence
when the game is fair, the probability of hitting NN when starting at aa is simply a/Na/N
approach 1: express expected value at stopping time in two different ways
let TT be the stop time, and WTW_T be the wealth at time TT
we know E[WT]=a\mathbb E[W_T]=a (no drift)
we also know WTW_T is either 00 or NN, so
combining these, we get qa=a/Nq_a=a/N
approach 2: solve recurrence
all consecutive differences are equal → qiq_i is a linear function of ii
with qi=0q_i=0 and qN=1q_N=1, we get qi=i/Nq_i=i/N
this is a random walk with absorbing barriers at 00 and NN
in general, a martingale is a sequence of RVs M1,...,MnM_1,...,M_n such that E[M1]==E[Mn]\mathbb E[M_1]=\cdots=\mathbb E[M_n]
the expected absorption time hih_i is i(Ni)i(N-i)
this is tricky to derive, but easy to verify by making sure it satisfies the recursive relationships given by first-step analysis

Random walk

simple symmetric random walk: let Sn=X1++XnS_n=X_1+\cdots +X_n where each Xi=±1X_i=\pm 1 with equal probability
obviously E[Sn]=E[Xi]=0\mathbb E[S_n]=\mathbb E[X_i]=0
each Xi=±1X_i=\pm 1 has variance E[Xi2](E[Xi])2=10=1\mathbb E[X_i^2]-(\mathbb E[X_i])^2=1-0=1
typical distance from origin (generally measured by standard deviation) grows like n\sqrt n
in the biased case (Xi=1X_i=1 with pp, else Xi=1X_i=-1)

Coupon collector

nn different types of coupons. every time you buy a cereal box, you get one coupon uniformly at random. in expectation, how much time does it take to collect all nn coupons?
let phase kk denote the phase in which we have kk types
each phase XkGeom((nk)/n)X_k\sim\operatorname{Geom}((n-k)/n)
the expected length of phase kk is
total expected time
where Hn=1+1/2+1/3++1/nH_n=1+1/2+1/3+\cdots+1/n is the nn-th harmonic number
final phase takes nn boxes in expectation!

Information-theoretic puzzles

count the information
if we need to distinguish kk possibilities and each test has mm outcomes, then we need at least logmk\lceil\log_m k\rceil tests
this is a lower bound
whether tests exist to achieve this bound depends on the constraints of the problem
9 coins, one is heavier, 2 weighings
divide into 3 groups of 3
left side heavy → counterfeit on left side
right side heavy → counterfeit on right side
balanced → counterfeit in the left-out set
then weigh 2 of the remaining 3

Reservoir sampling

we receive a stream of items: x1,x2,x3,x_1,x_2,x_3,… at the end of the stream, return a single item uniformly at random from all the items seen (length nn of stream is not known ahead of time)
the algorithm
keep the first item: s=x1s=x_1
for n=2,3,4,n=2,3,4,…
with probability 1/n1/n, replace ss with xnx_n
proof of correctness by induction
claim: after processing nn items, each of x1,,xnx_1,…,x_n is stored in ss with probability 1/n1/n
base case (n=1)(n=1): trivially, s=x1s=x_1 with probability 1=1/11=1/1
inductive step: after processing xnx_n, there are two possible outcomes
s=xns=x_n (replace): this happens with probability 1/n1/n
s=xks=x_k for some k<nk<n (keep): this requires (1) s=xks=x_k after step n1n-1, which has probability 1/(n1)1/(n-1) by induction, and that (2) we rejected xnx_n, which has probability (n1)/n(n-1)/n
thus every xkx_k is in the reservoir with probability 1/n1/n after nn steps

Secretary problem

problem: nn candidates interviewed in random order, after each interview, decide immediately to hire or reject that candidate. our goal is to maximize probability of hiring the best candidate. we use the strategy: reject the first kk candidates, then hire the next candidate better than all the first kk (if no such candidate appears, hire the last one). what is the optimal kk?
let P(k)=P(k)= probability that strategy with threshold kk hires the best candidate, let bb be the position of the best candidate
for the strategy to succeed:
b>kb>k: best candidate appears after the first kk
the best candidate among positions 1,,b11,…,b-1 is in 1,,k1,…,k (otherwise we hire someone before getting to bb)
taking the derivative, we see ddrrlogr=logr1-\frac{d}{dr}r\log r=-\log r-1
setting this to 0, we get logr=1    r=1e    k=ne\log r=-1\implies r=\frac 1e\implies k=\frac ne

Monty Hall

let A{1,2,...,n}A\in\{1,2,...,n\} represent the car’s location and BB be the set of doors Monty opens
we pick door cc (without loss of generality)
we want P(A=jB)P(A=j\mid B) for each unopened door jj
Bayes Theorem: P(A=jB)=P(BA=j)P(A=j)P(B)P(A=j\mid B)=\frac{P(B\mid A=j)\cdot P(A=j)}{P(B)}
comparing P(A=jB)P(A=j\mid B) for different jj reduces to comparing P(BA=j)P(B\mid A=j), because the prior P(A=j)=1/nP(A=j)=1/n is the same for all jj and the denominator is shared
case 1: Monty opens n2n-2 doors, leaving our door and one other
denote with index rr the one remaining door
P(BA=t)=1/(n1)P(B\mid A=t)=1/(n-1) because when your chosen door has the car, there are n1n-1 choices (i.e., n1n-1 choose n2n-2) for which door to leave closed
P(BA=r)=1P(B\mid A = r)=1 because Monty is completely constrained in which set of doors he can open
P(BA=k)=0P(B\mid A=k)=0 for all opened doors kBk\in B
so the posteriors P(A=tB)1/(n1)P(A=t\mid B)\propto 1/(n-1), P(A=rB)1P(A = r\mid B)\propto 1
normalizing gives P(A=tB)=1/nP(A=t\mid B)=1/n and P(A=rB)=(n1)/nP(A = r\mid B)=(n-1)/n
case 2: Monty opens only 1 door
let rr denote an arbitrary one of the remaining doors
P(BA=t)=1/(n1)P(B\mid A=t)=1/(n-1) because there are n1n-1 choices for which door to open
P(BA=r)=1/(n2)P(B\mid A=r)=1/(n-2) because there are n2n-2 choices for which door to open (every door except door cc and door AA is an option)
P(BA=k)=0P(B\mid A=k)=0 where B={k}B=\{k\}
so the posteriors P(A=tB)1/(n1)P(A=t\mid B)\propto 1/(n-1) and P(A=rB)1/(n2)P(A=r\mid B)\propto 1/(n-2)
so the remaining doors are each slightly more likely
in general, the sum of probabilities of opened doors (k/nk/n where kk is the number of opened doors) is distributed onto the remaining unopened, unchosen doors (of which there are nk1n-k-1)

Longest run of heads

we flip a fair coin nn times and let LnL_n denote the longest run of consecutive heads
there is no clean closed form for E[Ln]\mathbb E[L_n], but a well-known approximation is E[Ln]log2(n)\mathbb E[L_n]\approx \log_2(n)

Throwing balls into bins

if we throw mm balls into mm bins uniformly, about 37% are empty, 37% get one ball, and the rest get two or more

Path counting

how many paths from (0,0)(0,0) to (m,n)(m,n) on a grid, where each step moves one unit right or one unit up?
every path consists of exactly mm right-steps and nn up-steps
a path is uniquely specified by choosing which of the m+nm+n steps are right-steps
answer is (m+nm)\binom{m+n}{m}
how many of these paths pass through (a,b)(a,b)?
multiply number of unique paths to (a,b)(a,b) and number of unique paths from (a,b)(a,b) to (m,n)(m,n)

Statistics

Maximum likelihood estimation

given data x1,,xnx_1,…,x_n drawn from some distribution with unknown parameter θ\theta
maximum likelihood estimation: pick the θ\theta that makes the observed data most probable
log-likelihood trick: take log to turn product into sum
differentiate with respect to θ\theta, set to zero, and solve for θ^\hat\theta
check that it’s a max and not a min by checking second derivative of endpoints
example: x1,,xnx_1,…,x_n are iid from Bernoulli(p)\operatorname{Bernoulli}(p)
PMF: P(X=x;p)=px(1p)1xP(X=x;p)=p^x(1-p)^{1-x}
log likelihood
let kk denote the number of 1s
derivative
MLE is the sample frequency
example: x1,,xnx_1,…,x_n are iid from Exp(λ)\operatorname{Exp}(\lambda)
PDF: f(x;λ)=λeλxf(x;\lambda)=\lambda e^{-\lambda x}
log likelihood
derivative
MLE is the reciprocal of the sample mean
this makes sense because Exp(λ)\operatorname{Exp}(\lambda) has mean 1/λ1/\lambda
example: x1,,xnx_1,…,x_n are iid from Uniform(0,θ)\operatorname{Uniform}(0,\theta)
PDF: f(x;θ)=1/θf(x;\theta)=1/\theta
likelihood
this is maximized for the smallest value of θ\theta that satisfies θmaxxi\theta\geq\max x_i so θ^=maxxi\hat\theta=\max x_i
models are trained to minimize CE loss = 1Nilogp(xi)-\frac 1N\sum_i\log p(x_i) which is the same as maximizing log likelihood = ilogp(xi)\sum_i\log p(x_i)
in other words, models are trained to make observed data as probable as possible

Bias & variance

true parameter θ\theta, estimator θ^\hat\theta
the estimator is a function of the data, and since the data is random → θ^\hat\theta is an RV
bias: how close is θ^\hat\theta to θ\theta on average?
variance: how much does θ^\hat\theta depend on the data distribution?
mean squared error
decomposes into bias^2 + variance

Math things

Taylor series

a Taylor series approximates a function using a polynomial, using only information about the function at a single point
a series around a=0a=0 is called the Maclaurin series
the Taylor series of exe^x around x=0x=0 is
has infinite radius of convergence, so it converges to exe^x everywhere
suppose we want to approximate f(x)f(x) near x=0x=0
0th order approximation: f(x)f(0)f(x)\approx f(0)
horizontal line at f(0)f(0)
1st order approximation: f(x)f(0)+f(0)xf(x)\approx f(0)+f^\prime(0)\,x
tangent line to ff at x=0x=0, matching ff in both value and slope at the origin
2nd order approximation: f(x)f(0)+f(0)x+f(0)2x2f(x)\approx f(0)+f^\prime(0)x+\frac{f^{\prime\prime(0)}}{2}x^2
parabola that matches ff in value, slope, and curvature at 0
each new term adds another derivative of information, letting the polynomial hug the function more tightly near x=0x=0

Derivative rules

memorize these
composition rules

Handy equations

the nn-th harmonic number Hn=k=1n1klognH_n=\sum_{k=1}^n\frac 1k\approx\log n for large nn
log mean xyx+y2\sqrt{xy}\leq\frac{x+y}{2} for x,y>0x, y>0
some identities for ee
replace nn with n-n
replace nn with n/xn/x
exponential series