Skip to content
DeepForgeby svx
All problems
HardProbabilitypr-228

Systematic Resampling (Seeded)

Problem

Systematic resampling of normalized weights with random.Random(seed). Draw one uniform offset u in [0, 1 / n), then select indices at positions u, u + 1/n, ..., u + (n - 1)/n of the cumulative distribution. Return the resampled index list.

Return [] for an empty or all-zero weight vector.

Hint

One random offset produces a stratified set of selection points.

Test cases

case 1
in: [[0.25,0.25,0.25,0.25],42]
expected: [0,1,2,3]
case 2
in: [[0.7,0.2,0.1],7]
expected: [0,0,1]
case 3
in: [[1],5]
expected: [0]
case 4
in: [[],1]
expected: []
Starter codePython
import random


def sequential_importance_resampling(weights, seed):
    # Your code here
    pass

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