Click4Ai

463.

Hard

Graph Attention Network (GAT) is a type of Graph Neural Network that uses attention mechanisms to weigh the importance of different neighbors when aggregating node features. Implement a function to perform one step of GAT on a graph using NumPy. **Example:** Given an input graph represented as an adjacency matrix A and node features X, perform one step of GAT 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 = LeakyReLU(softmax(A @ X @ W) @ X) to perform GAT.

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