All problems
Particle Filter Weight Normalization
Problem
Normalize a list of particle weights so they sum to one by dividing each weight by the total. If the total weight is not positive, including an all-zero list, return a uniform distribution over the particles instead.
Return an empty list for empty input.
Hint
Degenerate weights fall back to a uniform distribution so the filter never stalls.
Test cases
case 1
in: [[1,1,2]]
expected: [0.25,0.25,0.5]
case 2
in: [[2,3]]
expected: [0.4,0.6]
case 3
in: [[0,0]]
expected: [0.5,0.5]
case 4
in: [[]]
expected: []
case 5
in: [[1,2,0]]
expected: [0.3333333333333333,0.6666666666666666,0]
Starter codePython
def particle_weight_normalization(weights):
# Your code here
pass5 test cases · run your code against them in the editor