Skip to content
DeepForgeby svx
All problems
EasyTime Seriests-139

Conjugate Prior Posterior Mean

Problem

Compute the conjugate normal posterior mean directly from precisions: (tau0 * mu0 + tau_data * xbar) / (tau0 + tau_data).

Return 0.0 when the total precision is zero.

Hint

The posterior mean is a precision-weighted average of prior mean and data mean.

Test cases

case 1
in: [0,1,2,1]
expected: 1
case 2
in: [10,4,12,2]
expected: 10.666666666666666
case 3
in: [5,0,100,1]
expected: 100
case 4
in: [0,0,0,0]
expected: 0
Starter codePython
def conjugate_posterior_mean(mu0, tau0, xbar, tau_data):
    # Your code here
    pass

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