All problems
Probabilistic PCA Posterior Mean
Problem
For probabilistic PCA with loading matrix loadings, noise variance noise_variance, and observation x, the posterior mean of the latent vector is (W^T W + noise_variance * I)^-1 W^T x. The loadings matrix is d by k and x has length d. Solve the linear system with Gaussian elimination and return the latent mean, or an empty list for invalid shapes or a nonpositive noise variance.
Hint
The posterior precision is W-transpose W plus the noise variance on the diagonal.
Test cases
case 1
in: [[1],[[1]],1]
expected: [0.5]
case 2
in: [[1,2],[[1],[2]],1]
expected: [0.8333333333333334]
case 3
in: [[1,0],[[1,0],[0,1]],1]
expected: [0.5,0]
case 4
in: [[1,2],[[1,0],[0,1]],2]
expected: [0.3333333333333333,0.6666666666666666]
case 5
in: [[1],[[1]],0]
expected: []
Starter codePython
def ppca_posterior_mean(x, loadings, noise_variance):
# Your code here
pass5 test cases · run your code against them in the editor