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 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 models a single trial with probability of success
compact PMF form
,
proof
categorial RV generalizes Bernoulli from 2 to outcomes
each item is , so and
handy techniques
indicator squaring: for any binary variable , so
Binomial
binomial RV is the sum of independent trials
where
every sequence with successes has the same probability , and there are such sequences
Binomial theorem
we can verify that
,
proof
(second equality follows because the are independent)
handy techniques
decompose into Bernoulli and use linearity of expectation
decompose into cross-terms
this makes computing expectation easy (using the fact that for indicator variables)
Poisson
Poisson RV models the number of events in a fixed interval when they occur independently at an average rate of over that interval
the number of events in interval of length distributed as
derivation using binomial limit: divide the fixed interval into tiny time intervals, assuming it is small enough that at most one event occurs in each interval
then the total count is with
is basically the definition of rate
sums of independent Poisson are Poisson, with rates that add
can be derived using MGF uniqueness
Geometric
geometric RV models the number of Bernoulli trials until first success (inclusive), where each trial has probability of success
the tail probability is a pure power of
memoryless:
the fact that you’ve failed times already is irrelevant
the geometric distribution is the only memoryless distribution on the positive integers any discrete waiting-time distribution that is memoryless must be geometric
the geometric series looks like
converges for to , diverges otherwise
can try to remember this by checking that for ,
sanity check: PMF sums to 1
expected wait time
direct solution: means failures
a little tricky to solve but gives
solution based on first-step analysis: on the first flip, we succeed with probability () and fail with probability , in which case we’re back to where we started ()
algebra then produces
intuition: every trial has change of ending the process, so on average we need attempts
as , both mean and variance blow up
rare successes have high variability in waiting time
handy techniques
first-step analysis
re-index using , turning to
Continuous
Uniform
uniform RV on means is equally likely to be anywhere on the interval
PDF
CDF
difference between two uniform distributions is triangular
the gaps between uniform points are distributed the same way
Exponential
exponential RV with rate models waiting time until the next event, where events happen at an average rate of per unit time
equivalently, waiting time until first event in a Poisson process with rate
tail formula (aka survival function)
memoryless:
the fact that you’ve waited for units of time already is irrelevant
the exponential is the only continuous distribution on that is memoryless
continuous analog to the geometric: waiting time in continuous time
,
if events happen at rate /unit time on average, then on average you need to wait units of time between events
relation between Poisson and exponential
two equivalent statements
number of events in unit interval is
inter-event time is
how many events in the next hour? → Poisson
how long until the next event? → exponential
minimum of exponentials: if and are independent, then
intuition: if emails arrive at rate and texts at rate , then the waiting time for “either an email or a text” is exponential with rate
proof
which is the tail function of
Gaussian
Gaussian RV with mean and variance
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 and , what fraction of people are taller than 76 inches?
the percentile is the value such that
i.e., is the point on the axis with probability mass to the left
symmetry:
2-sided intervals:
a confidence interval uses and as endpoints
stated as bounds:
this also means that for , the -percentile is
sum of independent Gaussians is Gaussian: if and , then
Expectations & variance
expectation
expectation of a function over
tail formula for non-negative RVs
variance
linearity of expectation (regardless of independence)
for independent and
if and are independent, then
Zoo of functions
probability mass function (PMF) of discrete RVs
properties
probability density function (PDF) of continuous RVs
differentiate CDF to get PDF:
cumulative distribution function (CDF) for both discrete and continuous RVs
for discrete:
for continuous:
note
Inequalities
Markov’s inequality: for any non-negative RV and ,
intuitively, cannot be smaller than the contribution of values greater than
proof
Chebyshev’s inequality: for any RV with mean and variance
at least of the distribution lies within standard deviations of the mean
e.g., 75% of probability mass sits within 2 standard deviations
proof: apply Markov to
another form, by substituting
Jensen’s inequality describes how expectations interact with convex/concave transformations
to remember, use (convex) with
convex functions have everywhere (slope is increasing)
, , … ( for any even )
(for )
(for )
concave functions have everywhere (slope is decreasing)
for
linear functions are both convex and concave
worth memorizing:
AM-GM inequality (arithmetic mean, geometric mean): arithmetic mean always 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, and
joint distribution:
marginal distribution:
conditional distribution:
Bayes rule
is the prior (what we believed before seeing )
is the posterior (what we believed after seeing )
calculate with law of total probability
law of total expectation (also known as the tower property)
can also be stated as
note that in this statement, is itself RV expressed in terms of
law of total probability
Limit theorems
central limit theorem: mean of iid RVs with mean and variance is Gaussian, no matter what the look like
derivation of variance
standard error is the standard deviation of , which is
what it means: error shrinks like , need 100x samples to reduce error 10x
confidence interval is given by
law of large numbers: mean of iid RVs with mean converges to the true average
proof from Chebyshev’s (substitute )
Some problem types
First-step analysis
what’s the expected number of coin flips to get two heads in a row?
let
= expected flips to finish after just flipping tails (or just started)
= expected flips after just flipping heads
then solve system of linear equations to get
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
define a sum of indicator random variables
compute for each (use symmetry)
apply linearity of expectation:
examples: expected number of fixed points in a random permutation
by symmetry, position equally likely to have any item, so
Max/min of RVs
if are iid with common CDF
for the max ,
for the min ,
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
let’s do this for
max
CDF:
PDF:
expectation:
intuition: uniform points split the segment into segments which are all equivalently distributed (by symmetry), so each must have mean length
alternatively with tail formula:
min
CDF:
PDF:
expectation:
for
min
max is a lot more complicated, but good to know that it grows logarithmically with
for , (this is pretty difficult to derive)
Combinatorics
combination: choosing items from , order doesn’t matter
the relation to permutation: every set of items can be arranged in orders, and combinations collapse the orderings into one
permutation: arranging items from , order matters
number of ways to arrange objects when there are of type 1, of type 2, …
permute all objects, the divide out the rearrangements of items within each type
a derangement is a permutation with no fixed points
combination with replacement: choosing items from 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 stars and bars → this is choosing placements of stars from positions
how many ways are there to write non-negative integer has sum of non-negative integers?
visualize stars with bars among them
order matters? | replacement? | count |
|---|---|---|
yes | no | (permutations) |
no | no | (combinations) |
yes | yes | |
no | yes | (stars and bars) |
inclusion-exclusion principle
as counts
Markov chains
Markov chain is a sequence of RVs taking values in some state space satisfying the Markov property: the future depends only on the present
for finite state spaces, the chain is described by the transition matrix where
rows sum to 1 and are probability distributions over next-states
if is the distribution over states at time , then
a stationary distribution satisfies
under mild conditions, the chain has a unique stationary distribution and 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 to absorption from state
for target absorbing state
probability of absorption from state
for desired absorbing state , and for all other absorbing states
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 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 between adjacent vertices is always where is the number of nodes
this is because (since stationary distribution has everywhere)
and because each of the adjacent nodes contributes
Puzzles
Birthday problem
how many people does it take so that the probability of two people having the same birthday exceeds 50%?
let be number of days in the year and the number of people
Gambler’s ruin
you start with $ dollars
win $1 with probability and lose $1 with probability
stop when you reach $ (you win) or $0 (you’re ruined)
probability you reach $?
let be probability of reaching starting from
boundary conditions:
for any starting amount ,
second-order linear recurrence
when the game is fair, the probability of hitting when starting at is simply
approach 1: express expected value at stopping time in two different ways
let be the stop time, and be the wealth at time
we know (no drift)
we also know is either or , so
combining these, we get
approach 2: solve recurrence
all consecutive differences are equal → is a linear function of
with and , we get
this is a random walk with absorbing barriers at and
in general, a martingale is a sequence of RVs such that
the expected absorption time is
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 where each with equal probability
obviously
each has variance
typical distance from origin (generally measured by standard deviation) grows like
in the biased case ( with , else )
Coupon collector
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 coupons?
let phase denote the phase in which we have types
each phase
the expected length of phase is
total expected time
where is the -th harmonic number
final phase takes boxes in expectation!
Information-theoretic puzzles
count the information
if we need to distinguish possibilities and each test has outcomes, then we need at least 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: at the end of the stream, return a single item uniformly at random from all the items seen (length of stream is not known ahead of time)
the algorithm
keep the first item:
for
with probability , replace with
proof of correctness by induction
claim: after processing items, each of is stored in with probability
base case : trivially, with probability
inductive step: after processing , there are two possible outcomes
(replace): this happens with probability
for some (keep): this requires (1) after step , which has probability by induction, and that (2) we rejected , which has probability
thus every is in the reservoir with probability after steps
Secretary problem
problem: 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 candidates, then hire the next candidate better than all the first (if no such candidate appears, hire the last one). what is the optimal ?
let probability that strategy with threshold hires the best candidate, let be the position of the best candidate
for the strategy to succeed:
: best candidate appears after the first
the best candidate among positions is in (otherwise we hire someone before getting to )
taking the derivative, we see
setting this to 0, we get
Monty Hall
let represent the car’s location and be the set of doors Monty opens
we pick door (without loss of generality)
we want for each unopened door
Bayes Theorem:
comparing for different reduces to comparing , because the prior is the same for all and the denominator is shared
case 1: Monty opens doors, leaving our door and one other
denote with index the one remaining door
because when your chosen door has the car, there are choices (i.e., choose ) for which door to leave closed
because Monty is completely constrained in which set of doors he can open
for all opened doors
so the posteriors ,
normalizing gives and
case 2: Monty opens only 1 door
let denote an arbitrary one of the remaining doors
because there are choices for which door to open
because there are choices for which door to open (every door except door and door is an option)
where
so the posteriors and
so the remaining doors are each slightly more likely
in general, the sum of probabilities of opened doors ( where is the number of opened doors) is distributed onto the remaining unopened, unchosen doors (of which there are )
Longest run of heads
we flip a fair coin times and let denote the longest run of consecutive heads
there is no clean closed form for , but a well-known approximation is
Throwing balls into bins
if we throw balls into bins uniformly, about 37% are empty, 37% get one ball, and the rest get two or more
Path counting
how many paths from to on a grid, where each step moves one unit right or one unit up?
every path consists of exactly right-steps and up-steps
a path is uniquely specified by choosing which of the steps are right-steps
answer is
how many of these paths pass through ?
multiply number of unique paths to and number of unique paths from to
Statistics
Maximum likelihood estimation
given data drawn from some distribution with unknown parameter
maximum likelihood estimation: pick the that makes the observed data most probable
log-likelihood trick: take log to turn product into sum
differentiate with respect to , set to zero, and solve for
check that it’s a max and not a min by checking second derivative of endpoints
example: are iid from
PMF:
log likelihood
let denote the number of 1s
derivative
MLE is the sample frequency
example: are iid from
PDF:
log likelihood
derivative
MLE is the reciprocal of the sample mean
this makes sense because has mean
example: are iid from
PDF:
likelihood
this is maximized for the smallest value of that satisfies so
models are trained to minimize CE loss = which is the same as maximizing log likelihood =
in other words, models are trained to make observed data as probable as possible
Bias & variance
true parameter , estimator
the estimator is a function of the data, and since the data is random → is an RV
bias: how close is to on average?
variance: how much does 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 is called the Maclaurin series
the Taylor series of around is
has infinite radius of convergence, so it converges to everywhere
suppose we want to approximate near
0th order approximation:
horizontal line at
1st order approximation:
tangent line to at , matching in both value and slope at the origin
2nd order approximation:
parabola that matches in value, slope, and curvature at 0
each new term adds another derivative of information, letting the polynomial hug the function more tightly near
Derivative rules
memorize these
composition rules
Handy equations
the -th harmonic number for large
log mean for
some identities for
replace with
replace with
exponential series