(self, in_features: int, out_features: int, n_heads: int, concat: bool = False, dropout: float = 0.4, leaky_relu_slope: float = 0.2)
| 30 | |
| 31 | """ |
| 32 | def __init__(self, in_features: int, out_features: int, n_heads: int, concat: bool = False, dropout: float = 0.4, leaky_relu_slope: float = 0.2): |
| 33 | super(GraphAttentionLayer, self).__init__() |
| 34 | |
| 35 | self.n_heads = n_heads # Number of attention heads |
| 36 | self.concat = concat # wether to concatenate the final attention heads |
| 37 | self.dropout = dropout # Dropout rate |
| 38 | |
| 39 | if concat: # concatenating the attention heads |
| 40 | self.out_features = out_features # Number of output features per node |
| 41 | assert out_features % n_heads == 0 # Ensure that out_features is a multiple of n_heads |
| 42 | self.n_hidden = out_features // n_heads |
| 43 | else: # averaging output over the attention heads (Used in the main paper) |
| 44 | self.n_hidden = out_features |
| 45 | |
| 46 | # A shared linear transformation, parametrized by a weight matrix W is applied to every node |
| 47 | # Initialize the weight matrix W |
| 48 | self.W = nn.Parameter(torch.empty(size=(in_features, self.n_hidden * n_heads))) |
| 49 | |
| 50 | # Initialize the attention weights a |
| 51 | self.a = nn.Parameter(torch.empty(size=(n_heads, 2 * self.n_hidden, 1))) |
| 52 | |
| 53 | self.leakyrelu = nn.LeakyReLU(leaky_relu_slope) # LeakyReLU activation function |
| 54 | self.softmax = nn.Softmax(dim=1) # softmax activation function to the attention coefficients |
| 55 | |
| 56 | self.reset_parameters() # Reset the parameters |
| 57 | |
| 58 | |
| 59 | def reset_parameters(self): |
nothing calls this directly
no test coverage detected