All problems
Bayes Factor from Marginal Likelihoods
Problem
The Bayes factor comparing two models is the ratio of their marginal likelihoods, BF = P(data | model 1) / P(data | model 2). Return that ratio, or 0.0 when evidence_h1 is negative or evidence_h2 is nonpositive.
Hint
A Bayes factor above 1 favors the first model.
Test cases
case 1
in: [0.02,0.01]
expected: 2
case 2
in: [0.5,0.5]
expected: 1
case 3
in: [0,0.5]
expected: 0
case 4
in: [0.3,0.1]
expected: 2.9999999999999996
case 5
in: [1,0]
expected: 0
Starter codePython
def bayes_factor_from_evidence(evidence_h1, evidence_h2):
# Your code here
pass5 test cases · run your code against them in the editor