Static layers
graphs_on_grids.layers.base
#
GraphBase
#
Bases: GraphLayer
Standard GNN layer. Implements
Source code in graphs_on_grids/layers/base.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | |
__init__(adjacency_matrix, embedding_size, hidden_units_node=None, hidden_units_edge=None, dropout_rate=0, use_bias=True, activation=None, aggregation_method='sum', weight_initializer='glorot_uniform', weight_regularizer=None, bias_initializer='zeros')
#
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adjacency_matrix |
ndarray
|
adjacency matrix of the graphs to be passed to the model |
required |
embedding_size |
int
|
the output dimensionality of the node feature vector |
required |
hidden_units_node |
list | tuple
|
list or tuple of neuron counts in the hidden layers used in the MLP for processing node features |
None
|
hidden_units_edge |
list | tuple
|
list or tuple of neuron counts in the hidden layers used in the MLP for processing edge features |
None
|
dropout_rate |
int | float
|
The dropout rate used after each dense layer in the node- or edge-MLPs |
0
|
use_bias |
bool
|
Whether to use bias in the hidden layers in the node- and edge-MLPs |
True
|
activation |
str | None
|
Activation function to be used within the layer |
None
|
aggregation_method |
str
|
Chooses the aggregation method for message passing. Either "sum" or "mean". |
'sum'
|
weight_initializer |
str | Initializer | None
|
Weight initializer to be used within the layer |
'glorot_uniform'
|
weight_regularizer |
str | Regularizer | None
|
Weight regularizer to be used within the layer |
None
|
bias_initializer |
str | Initializer | None
|
Bias initializer to be used within the layer |
'zeros'
|
Source code in graphs_on_grids/layers/base.py
graphs_on_grids.layers.conv
#
GraphConvolution
#
Bases: GraphLayer
Graph convolution layer as shown in the original paper
where where is the adjacency matrix with added self-loops and is its degree matrix.
Source code in graphs_on_grids/layers/conv.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |
__init__(adjacency_matrix, embedding_size, hidden_units_node=None, hidden_units_edge=None, dropout_rate=0, use_bias=True, activation=None, weight_initializer='glorot_uniform', weight_regularizer=None, bias_initializer='zeros')
#
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adjacency_matrix |
ndarray
|
adjacency matrix of the graphs to be passed to the model |
required |
embedding_size |
int
|
the output dimensionality of the node feature vector |
required |
hidden_units_node |
list | tuple
|
list or tuple of neuron counts in the hidden layers used in the MLP for processing node features |
None
|
hidden_units_edge |
list | tuple
|
list or tuple of neuron counts in the hidden layers used in the MLP for processing edge features |
None
|
dropout_rate |
int | float
|
The dropout rate used after each dense layer in the node- or edge-MLPs |
0
|
use_bias |
bool
|
Whether to use bias in the hidden layers in the node- and edge-MLPs |
True
|
activation |
str | None
|
Activation function to be used within the layer |
None
|
weight_initializer |
str | Initializer | None
|
Weight initializer to be used within the layer |
'glorot_uniform'
|
weight_regularizer |
str | Regularizer | None
|
Weight regularizer to be used within the layer |
None
|
bias_initializer |
str | Initializer | None
|
Bias initializer to be used within the layer |
'zeros'
|
Source code in graphs_on_grids/layers/conv.py
graphs_on_grids.layers.attention
#
GraphAttention
#
Bases: GraphLayer
Graph attention layer as shown in the original paper
where is the adjacency matrix weighted by the attention scores and is computed by: for each node pair where is a trainable attention kernel.
Source code in graphs_on_grids/layers/attention.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | |
__init__(adjacency_matrix, embedding_size, hidden_units_node=None, hidden_units_attention=None, dropout_rate=0, use_bias=True, activation=None, weight_initializer='glorot_uniform', weight_regularizer=None, bias_initializer='zeros')
#
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adjacency_matrix |
ndarray
|
adjacency matrix of the graphs to be passed to the model |
required |
embedding_size |
int
|
the output dimensionality of the node feature vector |
required |
hidden_units_node |
list | tuple
|
list or tuple of neuron counts in the hidden layers used in the MLP for processing node features |
None
|
hidden_units_attention |
list | tuple
|
list or tuple of neuron counts in the hidden layers used in the MLP for computing attention scores |
None
|
dropout_rate |
int | float
|
The dropout rate used after each dense layer in the node- or edge-MLPs |
0
|
use_bias |
bool
|
Whether to use bias in the hidden layers in the node- and edge-MLPs |
True
|
activation |
str | None
|
Activation function to be used within the layer |
None
|
weight_initializer |
str | Initializer | None
|
Weight initializer to be used within the layer |
'glorot_uniform'
|
weight_regularizer |
str | Regularizer | None
|
Weight regularizer to be used within the layer |
None
|
bias_initializer |
str | Initializer | None
|
Bias initializer to be used within the layer |
'zeros'
|
Source code in graphs_on_grids/layers/attention.py
MultiHeadGraphAttention
#
Bases: GraphLayer
Multi-head graph attention layer as shown in the original paper
Computes num_heads independent graph attention layers and combines them by concatenation or averaging
depending on the concat_heads parameter.
Source code in graphs_on_grids/layers/attention.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | |
__init__(adjacency_matrix, embedding_size, hidden_units_node=None, hidden_units_attention=None, dropout_rate=0, num_heads=3, use_bias=True, activation=None, weight_initializer='glorot_uniform', weight_regularizer=None, bias_initializer='zeros', concat_heads=True)
#
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adjacency_matrix |
ndarray
|
adjacency matrix of the graphs to be passed to the model |
required |
embedding_size |
int
|
the output dimensionality of the node feature vector |
required |
hidden_units_node |
list | tuple
|
list or tuple of neuron counts in the hidden layers used in the MLP for processing node features |
None
|
hidden_units_attention |
list | tuple
|
list or tuple of neuron counts in the hidden layers used in the MLP for computing attention scores |
None
|
dropout_rate |
int | float
|
The dropout rate used after each dense layer in the node- or edge-MLPs |
0
|
num_heads |
int
|
Number of independent attention heads |
3
|
use_bias |
bool
|
Whether to use bias in the hidden layers in the node- and edge-MLPs |
True
|
activation |
str | None
|
Activation function to be used within the layer |
None
|
weight_initializer |
str | Initializer | None
|
Weight initializer to be used within the layer |
'glorot_uniform'
|
weight_regularizer |
str | Regularizer | None
|
Weight regularizer to be used within the layer |
None
|
bias_initializer |
str | Initializer | None
|
Bias initializer to be used within the layer |
'zeros'
|
concat_heads |
bool
|
Whether to concatenate (True) results from the attention heads or average (False) them. |
True
|
Source code in graphs_on_grids/layers/attention.py
graphs_on_grids.layers.output_layer
#
FlattenedDenseOutput
#
Bases: Layer
A utility output layer that takes in a 2D feature matrix and flattens it before passing it through a regular dense layer. The output feature matrix is reshaped to be 2D again.
Source code in graphs_on_grids/layers/output_layer.py
__init__(units, activation=None)
#
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
units |
int
|
dimensionality of the output node feature vector |
required |
activation |
str
|
activation function used in dense layer |
None
|