All problems
Bridge Sampling Estimator
Problem
Bridge sampling estimates the ratio Z1 / Z0 of normalizing constants as the mean over samples from p0 of l1 * alpha divided by the mean over samples from p1 of l2 * alpha, where l1 and l2 are the unnormalized densities and alpha is the bridge function. Given the four parallel lists of likelihoods and bridge values for each sample set, return that ratio. Return 0.0 for empty, mismatched, or zero-denominator inputs.
Hint
The bridge identity equates Z1 times an expectation under p1 with Z0 times an expectation under p0.
Test cases
case 1
in: [[0.5,0.7],[1,1],[0.4,0.6],[1,1]]
expected: 1.2
case 2
in: [[1,2],[0.1,0.2],[3,1],[0.5,0.5]]
expected: 0.25
case 3
in: [[1],[2],[1],[0.25]]
expected: 8
case 4
in: [[1,1],[1,1],[0,0],[1,1]]
expected: 0
case 5
in: [[1,2],[1],[1],[1]]
expected: 0
Starter codePython
def bridge_sampling_estimate(likelihoods0, alphas0, likelihoods1, alphas1):
# Your code here
pass5 test cases · run your code against them in the editor