All problems
Sequential Bayesian Update from Likelihoods
Problem
Given prior probabilities over hypotheses and a sequence of observation likelihood vectors, apply Bayes' rule once per observation. Each row likelihood_vectors[t] gives the probability of observation t under every hypothesis, and the posterior after each step becomes the prior for the next. Return the normalized final posterior, or a list of zeros when it has no mass; rows whose length does not match are skipped.
Hint
Multiply the current posterior by each likelihood row, then renormalize.
Test cases
case 1
in: [[0.5,0.5],[[0.9,0.3],[0.8,0.4]]]
expected: [0.8571428571428572,0.14285714285714285]
case 2
in: [[0.2,0.8],[]]
expected: [0.2,0.8]
case 3
in: [[0.5,0.5],[[1,0]]]
expected: [1,0]
case 4
in: [[0.3,0.7],[[0,0],[1,1]]]
expected: [0,0]
case 5
in: [[0.25,0.25,0.5],[[2,1,1]]]
expected: [0.4,0.2,0.4]
Starter codePython
def sequential_bayesian_update(priors, likelihood_vectors):
# Your code here
pass5 test cases · run your code against them in the editor