Math Empirical Flashcards
(29 cards)
bias-variance tradeoff
illustrate BVT: true data y; model h(X)
E[(y-h)2]
= E[(y-E[y])2] + (E[y] - E[h])2 + E[(h-E[h])2]
= Var(y) + (E[y] - E[h])2 + Var(h)
= noise + bias + variance
simulate triangle
how would you simulate the distribution of points on a triangular region in the plane?
triangle (x0,y0), (x1,y1), (x2,y2)
- simulate on triangle (0,0), (0,1), (1,0): x, y ~ Unif(0,1), if y > -x + 1, x = -x + 1, y = -y + 1
- transform and translate: [x1-x0,x2-x0;y1-y0,y2-y0][x;y] + [x0;y0]
roll die with cost
Roll a die and get $i; can pay $1 to reroll, can reroll inf times. What’s the strategy and what’s the EV?
Reroll if i = 1 or 2: EV = 2/3(4.5) + 1/3(EV-1) –> EV = 4
sum of uniforms
What’s the expected number of U~unif(0,1) such that their sum first exceeds 1?
Let S[n] = sum of n U’s
P(S[n] < 1) = 1/n!
P[N=n] = P(S[n-1] < 1 and S[n] >= 1) = 1/(n-1)! - 1/n! = (n-1)/n!
E[N] = sumn=0..inf [nP[N=n]] = sumn=0..inf [1/n!] = e
change bases
given 1 balance, how many unique weights are needed to weigh items with w=1…N? what if you could have k copies of each weight?
we can represent any number as sumi=1..m x*3i, x in {-1,0,1}
thus the weights are {30, 31, … 3m} where m = min sumi=1..m 3i >= N –> m = log_3(2N+1) - 1
for k copies, replace 3 with 2k+1
super egg drop
with F floors and K eggs, what’s the min worst case # drops to determine which floor the egg breaks on? Write out init and dp steps
init: dp[f][1] = f; dp[0][k] = 0, dp[1][k] = 1
dp: dp[f][k] = 1 + min(max(dp[i-1][k-1], dp[f-i][k] for 1<=i<=f))
bid item
seller values item s~N(0,1) and you value item at y = 1.8s. How should you bid?
Say you bid x and win: E[s] = 0.5x, and E[y] = 1.8E[s] = 0.9x < x, so you should not bid at all.
distance on unit sphere
what’s the expected distance (in 3D, not on surface) of any point on a unit sphere’s surface to the sphere’s north pole?
p(point on ring) = 2πdx/4π = 1/2 dx
d(point on ring, north pole) = sqrt(x2 + (1-(x-1)2) = sqrt(2x)
E[point on sphere, north pole) = integratex=0..2 sqrt(2x) 1/2 dx = 4/3
stick breaking
break a stick into 3 pieces:
- what’s the probability that they form a triangle?
- what’s the expected length of the middle part?
- Plot: 0<=x,y<=1
- min(x,y) <= 1/2
- max(x,y) >= 1/2
- |x-y| <= 1/2
Area = 1/4
- integratex=0..1 x(x/2) + (1-x)(1-x)/2 dx = 1/3
arrival time
A and B each arrive t ~ U(0,1) hr and stay for 1/2 hr, what’s the probability that they meet?
Plot: 0<=x,y<=1, |x-y| <= 1/2 –> Area = 3/4
ant on cube
What’s the expected number of steps for ant to go from one corner of cube to opposite corner of cube?
x1 = 1 + x2
x2 = 1 + 1/3 x1 + 2/3 x3
x3 = 1 + 2/3 x2 + 1/3 x4
x4 = 0
–> x1 = 10
simulate fair coin
how to used a biased coin to simulate a fair coin?
naive: 2 flips at a time, HT/TH –> 1/0, HH/TT –> continue; E[flips] = 2 * 1/2pq = 1/pq
optimized: at kth flip, if kC(#H) is even, X[k] = H/T –> 1/0; odd –> continue
ball sequence
N white and N black balls, randomly ordered. what’s the expected # color switches? what’s the expected # color runs?
let Xi = color switch between (i, i+1)
E[# color switches] = E[Σi=1..2N-1 Xi] = (2N-1) (N/2N * N/(2N-1) * 2) = N
E[# color runs] = E[# color switch] + 1 = N + 1
coin flips
- what’s x[N] = E[# adj H in N flips]?
- what’s x[N] = E[# flips to get N consecutive H]?
- x[N] = 1/2 x[N-1] + 1/2 (1/2 x[N-1] + 1/2 (x[N-1] + 1)); x[2] = 1/4 –> x[N] = (N-1)/4
- x[N] = 1/2 (x[N-1] + 1) + 1/2 (x[N-1] + 1 + x[N]); x[N] = 0 –> x[N] = 2N+1 - 2
draw with replacement
draw N numbers from {1…N} with replacement, what’s the expected # distinct numbers?
N(1 - ((N-1)/N)N)
max seq length
a sequence of numbers, all MA(8) > 0 and all MA(5) < 0, what’s the max length of this sequence?
Write numbers in a 8x5 grid, get contradiction where all rows < 0 and all columns > 0. Hence max length is 8 + 5 - 1 = 11
dice sum
roll dice continuously, what’s the probability that the sum hits exactly 100?
P(1) = 1/6
P(2) = 1/6 + 1/6 P(1)
P(3) = 1/6 + 1/6 P(2) + 1/6 P(1)
…
P(6) = 1/6 + 1/6 P(5) + … 1/6 P(1)
P(7) = 1/6 P(6) + … + 1/6 P(1)
P(n) = 1/6 Σi=1..6 P(i) = Σi=0..5 (n-1)Ci 6n-i
guess coin
2 people each flip a coin and guess each other’s result, how to maximize probability that both are correct?
random guess: p = 1/4
guess own coin: p = 1/2
draw ball
n-1 red balls, 1 blue ball. 2 people take turns drawing w/o replacement, and win if draw blue. does the 1st person have an advantage?
same as lining up the balls and see if blue is at odd or even index.
if n even, P1 = P2; if n odd, P1 = P2 + 1/n > P2
languages
70 people in total, for every pair, i knows a language that j doesn’t and vice versa. at least how many languages in total?
k language / person: solve for min n s.t. nC1 >= 70
k = 1, n = 70
k = 2, n = 13
k = 3, n = 9
k = 4, n = 8
k = 5, n = 9
…
survivor
n people (i=0..n-1) in a circle, #0 shoots #1, #2 shoots #3, and so on. who survives in the end?
if n = 2^k, then i=0 survivies
else, once n is reduced to n = 2^k, the next person survives
So idx = 2(n - 2^m), where 2^m is max 2^m s.t. 2^m <= n
birthday problem
in a long line, the 1st person to have a shared birthday as someone before him wins. where to stand?
P(N) = prob(no shared birthday in N people) = 365*364*..*(365-n+1) / 365^n = 365Pn / 365^n
argmax P(i) i/365 = 19 –> stand in 20th place
sample from disk
how to sample uniformly from a disk with radius R?
x1, x2 ~ Unif(0,1)
theta = 2πx1
r = R sqrt(x2)
–> pdf f(r) = 2r/R2; cdf F(r) = r2/R2; F-1(x) = R sqrt(x)
coin flip
flip n coins, Pi = 1/(2i+1) for i = 1…n. What’s P(#H is odd)?
P[i] = P[i-1] (1 - 1/(2i+1)) + (1 - P[i-1]) 1/(2i+1) = P[i-1] (2i-1)/(2i+1) + 1/(2i+1)
P[0] = 0
P[n] = n / (2n+1)