Skip to content
DeepForgeby svx
All problems
MediumProbabilitypr-303

Mean-Field Mixture Update

Problem

A mean-field update for mixture assignments sets each logit to the expected log density E[log N(x | mu, sigma^2)] under q(mu) = N(expected_mean, mean_variance), which equals -log(sigma) - 0.5 * log(2 * pi) - ((x - expected_mean)^2 + mean_variance) / (2 * sigma^2). Return the softmax of these logits. Return an empty list for empty or mismatched inputs or a nonpositive standard deviation.

Hint

The mean-field coordinate update exponentiates expected log densities and normalizes.

Test cases

case 1
in: [0,[0,1],[0,0],[1,1]]
expected: [0.6224593312018546,0.37754066879814546]
case 2
in: [0,[0,2],[0,0],[1,1]]
expected: [0.8807970779778823,0.11920292202211755]
case 3
in: [1,[0],[1],[1]]
expected: [1]
case 4
in: [0,[0,0],[0,1],[1,1]]
expected: [0.6224593312018546,0.37754066879814546]
case 5
in: [0,[0,1],[-1,0],[1,1]]
expected: []
Starter codePython
import math


def mean_field_mixture_update(x, expected_means, mean_variances, sigmas):
    # Your code here
    pass

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