All problems
Metropolis Hastings Acceptance Ratio
Problem
The Metropolis-Hastings acceptance ratio is min(1, p_new * q_forward / (p_old * q_reverse)), where p are target densities and q are proposal densities.
Given the target densities and proposal densities, return the ratio.
Hint
The ratio is capped at one for certain acceptance.
Test cases
case 1
in: [1,2,1,1]
expected: 0.5
case 2
in: [0.5,1,1,2]
expected: 0.25
case 3
in: [3,1,0.5,0.5]
expected: 1
Starter codePython
def metropolis_acceptance_ratio(p_new, p_old, q_forward, q_reverse):
# Your code here
pass3 test cases · run your code against them in the editor