Skip to content
DeepForgeby svx
All problems
EasyOptimizationop-246

Bias-Corrected EMA Weights

Problem

Debias an exponential moving average of the weights.

Given the current EMA vector, the decay factor, and the step count t, return each ema_i / (1 - decay^t). The correction compensates for the EMA starting at zero. If the denominator is zero, return the EMA unchanged.

Hint

Early EMA values are too small because they start from zero.

Test cases

case 1
in: [[1,2],0.9,1]
expected: [10.000000000000002,20.000000000000004]
case 2
in: [[0.5,0.5],0.9,3]
expected: [1.8450184501845024,1.8450184501845024]
case 3
in: [[1],0.999,10]
expected: [100.45082541138463]
case 4
in: [[2,-2],0.5,2]
expected: [2.6666666666666665,-2.6666666666666665]
Starter codePython
def ema_bias_corrected(ema, decay, t):
    # Your code here
    pass

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