Skip to content
DeepForgeby svx
All problems
MediumOptimizationop-167

Federated Averaging Step

Problem

Perform one federated averaging aggregation step.

Return the count-weighted mean of the client updates: sum(counts[k] * updates[k]) / sum(counts). Return [] when the total count is zero or there are no updates.

Hint

Clients are weighted by their number of local samples.

Test cases

case 1
in: [[[1,2],[3,4]],[1,3]]
expected: [2.5,3.5]
case 2
in: [[[1],[3],[5]],[2,1,1]]
expected: [2.5]
case 3
in: [[[2,0]],[5]]
expected: [2,0]
Starter codePython
def federated_average(updates, counts):
    # Your code here
    pass

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