All problems
Diagonal Gaussian Density
Problem
Return the density of a multivariate Gaussian with independent coordinates at the point x, given the mean vector mean and per-coordinate standard deviations sigmas. The density is exp(-0.5 * sum(((x[i] - mean[i]) / sigmas[i])^2)) divided by the product of sigmas[i] * sqrt(2 * pi). Return 0.0 when lengths differ or any standard deviation is nonpositive.
Hint
The diagonal covariance makes the multivariate density a product of univariate ones.
Test cases
case 1
in: [[0],[0],[1]]
expected: 0.3989422804014327
case 2
in: [[0,0],[0,0],[1,1]]
expected: 0.15915494309189537
case 3
in: [[1,2],[0,0],[1,1]]
expected: 0.013064233284684923
case 4
in: [[2],[2],[3]]
expected: 0.1329807601338109
case 5
in: [[0],[0],[0]]
expected: 0
Starter codePython
import math
def diagonal_gaussian_density(x, mean, sigmas):
# Your code here
pass5 test cases · run your code against them in the editor