Skip to content
DeepForgeby svx
All problems
EasyGraph Algorithmsgraph-181

Message Passing Mean

Problem

Perform one round of mean message passing on an undirected graph.

Each node's new feature vector is the arithmetic mean of its neighbors' feature vectors; nodes without neighbors get an all-zero vector. features is a list of n equal-length vectors. Return the updated feature matrix.

Hint

Isolated nodes have no incoming messages, so their aggregation is the zero vector.

Test cases

case 1
in: [3,[[0,1],[1,2]],[[1,0],[0,1],[1,1]]]
expected: [[0,1],[1,0.5],[0,1]]
case 2
in: [2,[[0,1]],[[2,3],[4,5]]]
expected: [[4,5],[2,3]]
case 3
in: [1,[],[[5,5]]]
expected: [[0,0]]
case 4
in: [4,[[0,1],[0,2],[0,3]],[[1,1],[2,2],[3,3],[4,4]]]
expected: [[3,3],[1,1],[1,1],[1,1]]
Starter codePython
def message_passing_mean(n, edges, features):
    # Your code here
    pass

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