Skip to content
DeepForgeby svx
All problems

Reward Scaling

Problem

Scale rewards by a running standard deviation.

Return rewards[i] / (std + epsilon) so the scaled rewards have roughly unit scale. An empty list returns [].

Hint

The epsilon keeps the division safe when the running std is near zero.

Test cases

case 1
in: [[1,2,3],1]
expected: [0.9999999900000002,1.9999999800000003,2.9999999700000006]
case 2
in: [[10],0.5]
expected: [19.999999600000006]
case 3
in: [[-1,1],2]
expected: [-0.4999999975,0.4999999975]
case 4
in: [[],1]
expected: []
Starter codePython
def scale_rewards(rewards, std, epsilon=1e-8):
    # Your code here
    pass

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