Skip to content
DeepForgeby svx
All problems
EasyOptimizationop-027

Polyak Averaging Combine

Problem

Fold a new parameter value into a running Polyak average.

Given the current average, the new value, and count (the number of values already averaged), return (current_avg * count + param) / (count + 1).

Hint

This is just the incremental mean formula.

Test cases

case 1
in: [0,1,0]
expected: 1
case 2
in: [0.5,1,1]
expected: 0.75
case 3
in: [2,0,3]
expected: 1.5
case 4
in: [1,2,9]
expected: 1.1
Starter codePython
def polyak_average(current_avg, param, count):
    # Your code here
    pass

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