All problems
PER Beta Annealed Weight
Problem
Compute a single prioritized replay importance-sampling weight with beta annealing.
The schedule is beta = beta0 + (1 - beta0) * (step / total_steps) with step clamped to [0, total_steps], and the weight is (1 / (n * prob))^beta. A non-positive total_steps uses beta = 1.0, and non-positive n or prob returns 0.0.
Hint
Annealing beta from beta0 to 1 gradually removes the importance-sampling bias.
Test cases
case 1
in: [0.2,10,0.4,0,100]
expected: 0.757858283255199
case 2
in: [0.2,10,0.4,100,100]
expected: 0.5
case 3
in: [0.2,10,0.4,50,100]
expected: 0.6155722066724582
case 4
in: [0.2,10,0,50,100]
expected: 0.7071067811865476
case 5
in: [0,10,0.4,50,100]
expected: 0
Starter codePython
def per_beta_annealed_weight(prob, n, beta0, step, total_steps):
# Your code here
pass5 test cases · run your code against them in the editor