Skip to content
DeepForgeby svx
All problems
HardProbabilitypr-042

Bayes Three Hypotheses

Problem

Posterior probabilities of three mutually exclusive hypotheses after observing data.

Given prior probabilities and likelihoods, return the normalized posterior list joints[i] / sum(joints) where joints[i] = priors[i] * likelihoods[i]. If the total is 0 return a list of zeros.

Hint

Scale the joint probabilities so they sum to 1.

Test cases

case 1
in: [[0.2,0.3,0.5],[0.5,0.6,0.1]]
expected: [0.30303030303030304,0.5454545454545454,0.15151515151515152]
case 2
in: [[0.5,0.25,0.25],[0.1,0.5,0.9]]
expected: [0.125,0.3125,0.5625]
case 3
in: [[0.3333333333333333,0.3333333333333333,0.3333333333333333],[1,1,1]]
expected: [0.3333333333333333,0.3333333333333333,0.3333333333333333]
case 4
in: [[0,0.5,0.5],[0.9,0.4,0.4]]
expected: [0,0.5,0.5]
Starter codePython
def bayes_three_hypotheses(priors, likelihoods):
    # Your code here
    pass

4 test cases · run your code against them in the editor