Skip to content
DeepForgeby svx
All problems
EasyTime Seriests-277

Particle Effective Sample Size

Problem

Compute the effective sample size of a normalized weight vector: ESS = 1 / sum(w_i^2).

Return 0.0 when the list is empty or all weights are zero. Uniform weights over n particles give exactly n.

Hint

Concentrated weights drive the sum of squares up and the effective size down.

Test cases

case 1
in: [[0.5,0.5]]
expected: 2
case 2
in: [[1]]
expected: 1
case 3
in: [[0.25,0.25,0.25,0.25]]
expected: 4
case 4
in: [[]]
expected: 0
case 5
in: [[0.1,0.2,0.7]]
expected: 1.851851851851852
Starter codePython
def particle_effective_sample_size(weights):
    # Your code here
    pass

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