Skip to content
DeepForgeby svx
All problems
EasyAlgorithmsal-368

Exponential Decay Window Average

Problem

Compute the exponentially decayed running average of values with smoothing factor alpha.

Start the state at the first value and update it as alpha * x + (1 - alpha) * state for every later x. Return 0.0 for an empty list, so recent values dominate when alpha is close to 1.

Hint

Fold each new value into one running state instead of keeping the whole window.

Test cases

case 1
in: [[1,2,3],0.5]
expected: 2.25
case 2
in: [[5],0.3]
expected: 5
case 3
in: [[],0.5]
expected: 0
case 4
in: [[0,10,0],0.25]
expected: 1.875
case 5
in: [[1,1,1],0.9]
expected: 1
Starter codePython
def exponential_decay_average(values, alpha):
    # Your code here
    pass

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