Click4Ai

462.

Hard

Message Passing is a fundamental operation in Graph Neural Networks (GNNs). Implement a function to perform message passing on a graph using NumPy. **Example:** Given an input graph represented as an adjacency matrix A and node features X, perform one step of message passing to obtain the updated node features X_new. **Constraints:** The graph is undirected and unweighted. The node features are represented as a matrix where each row corresponds to a node. The adjacency matrix A is symmetric.

**Hint:** Use the formula X_new = softmax(A @ X) @ X to perform message passing.

**Hint:** Use np.sum to calculate the sum of each row in the matrix.

**Hint:** Use np.exp to calculate the exponential of each element in the matrix.

**Hint:** Use np.divide to calculate the element-wise division of two matrices.

Test Cases

Test Case 1
Input: [[0, 1, 1], [1, 0, 1], [1, 1, 0]]
Expected: [[0.5, 0.25, 0.25], [0.25, 0.5, 0.25], [0.25, 0.25, 0.5]]
Test Case 2
Input: [[0, 1, 1, 1], [1, 0, 1, 1], [1, 1, 0, 1], [1, 1, 1, 0]]
Expected: [[0.5, 0.25, 0.25, 0.25], [0.25, 0.5, 0.25, 0.25], [0.25, 0.25, 0.5, 0.25], [0.25, 0.25, 0.25, 0.5]]
+ 3 hidden test cases