Definition (Proposal kernel)
In the MH algorithm we use a proposal kernel which we define as T(⋅∣⋅) where T(⋅∣⋅)\mboxisthetransitionmatrixonSiT(y∣x)\mboxistheone−steptransitionprobabilityT(⋅∣x)\mboxisarowinT(⋅∣⋅)
Definition (Acceptance rate)
In the MH algorithm we define the acceptance rate, r, as the threshold function that determines whether a state get’s accepted or not: r(xt−1,y)=min{1,π(xt−1)T(y∣xt−1)π(y)T(xt−1∣y)}where xt−1is the previous state, y is the proposed state, and T(⋅∣⋅) is the .
Goal
To a create a MC with π(⋅) as its invariant distribution. The MH algorithm needs a proposal kernel, T(⋅∣⋅) which is user-specified.
Algorithm
At time t=1, generate X1 (pick random i∈S and set X1=i) from an arbitrary distribution. For t≥2, given Xt−1=xt−1,
- Draw y from the distribution T(⋅∣xt−1), and compute the acceptance rate: r(xt−1,y)=min{1,π(xt−1)T(y∣xt−1)π(y)T(xt−1∣y)}
- Draw Ut∼\mboxUnif(0,1), and Xt={y,xt−1,\mboxifUt≤r(xt−1,y)\mboxotherwise
- The transition kernel for MH is for y=x, p(y∣x)=T(y∣x)min{1,π(x)T(y∣x)π(y)T(x∣y)}
- Then the detailed balance hold since π(x)p(y∣x)=π(x)T(y∣x)min{1,π(x)T(y∣x)π(y)T(x∣y)}=min{π(y)T(x∣y),π(x)T(y∣x)}=π(y)p(x∣y) or
def MH_algo(state_space, T, pi):
x = []
x.append(state_space[random.randint(len(state_space))])
db = False
t = 0
while(not db):
t += 1
x_tm1 = x[t-1]
possible_y = T[:][x_tm1]
# Step 1
y = possible_y[random.randint(len(possible_y))]
while(y <= 0):
y = possible_y[random.randint(len(possible_y))]
r = min(1,float(pi(y)*T[x_tm1][y]/float(pi(x_tm1)T[y][x_tm1]))
# Step 2
Ut = random.random()
x.append(y if Ut <= r else x_tm1)
# Step 3
if(y is not x):
p[y][:]=T[y][:]*min(1,pi(y)*T[:][y]/float(pi(state_space[:])*T[y][:]))
# Step 4
# idk if this is right ibr
Theorem (Theoretical Guarantees for Countable State Space)
Assume π(⋅) is a distribution over a countable space.
- If the transition matrix P is irreducible, then w.p.1 for any bounded function f:S→R, n→∞limN1n=1∑Nf(Xn)=i∈S∑f(i)π(i)i.e. Ergodic Theorem II holds true.
- If in addition P is aperiodic, then N→∞limj∈Ssup∣P(XN=j)−πj∣=0i.e. Convergence to Equilibrium holds true
Theorem (Symmetric kernel)
When applying the MH algorithm, if the is symmetric, i.e., T(y∣x)=T(x∣y)then the , r, can be simplified to r(x,y)=min{1,π(x)π(y)}