Belle II Software light-2406-ragdoll
NodeLayer Class Reference
Inheritance diagram for NodeLayer:
Collaboration diagram for NodeLayer:

Public Member Functions

def __init__ (self, nfeat_in_dim, efeat_in_dim, gfeat_in_dim, nfeat_hid_dim, nfeat_out_dim, num_hid_layers, dropout, normalize=True)
 
def forward (self, x, edge_index, edge_attr, u, batch)
 

Public Attributes

 nonlin_function
 Non-linear activation.
 
 num_hid_layers
 Number of hidden layers.
 
 dropout_prob
 Dropout probability.
 
 normalize
 Normalize.
 
 lin_in
 Input linear layer.
 
 lins_hid
 Intermediate linear layers.
 
 lin_out
 Output linear layer.
 
 norm
 Batch normalization.
 

Detailed Description

Updates node features in MetaLayer:

.. math::
    v_{i}^{'} = \\phi^{v}(v_{i}, \\rho^{e \\to v}(v_{i}), u)

with

.. math::
    \\rho^{e \\to v}(v_{i}) = \\frac{\\sum_{j=1,\\ j \\neq i}^{N} (e_{ji} + e _{ij})}{2 \\cdot (N-1)},

where :math:`\\phi^{v}` is a neural network of the form

.. figure:: figs/MLP_structure.png
    :width: 42em
    :align: center

Args:
    nfeat_in_dim (int): Node features input dimension (number of node features in input).
    efeat_in_dim (int): Edge features input dimension (number of edge features in input).
    gfeat_in_dim (int): Gloabl features input dimension (number of global features in input).
    nfeat_hid_dim (int): Node features dimension in hidden layers.
    nfeat_out_dim (int): Node features output dimension.
    num_hid_layers (int): Number of hidden layers.
    dropout (float): Dropout rate :math:`r \\in [0,1]`.
    normalize (str): Type of normalization (batch/layer).

:return: Updated node features tensor.
:rtype: `Tensor <https://pytorch.org/docs/stable/tensors.html#torch.Tensor>`_

Definition at line 137 of file geometric_layers.py.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  nfeat_in_dim,
  efeat_in_dim,
  gfeat_in_dim,
  nfeat_hid_dim,
  nfeat_out_dim,
  num_hid_layers,
  dropout,
  normalize = True 
)
Initialization.

Definition at line 169 of file geometric_layers.py.

179 ):
180 """
181 Initialization.
182 """
183 super(NodeLayer, self).__init__()
184
185
186 self.nonlin_function = F.elu
187
188 self.num_hid_layers = num_hid_layers
189
190 self.dropout_prob = dropout
191
192 self.normalize = normalize
193
194
195 self.lin_in = nn.Linear(
196 gfeat_in_dim + nfeat_in_dim + efeat_in_dim, nfeat_hid_dim
197 )
198
199 self.lins_hid = nn.ModuleList(
200 [
201 nn.Linear(nfeat_hid_dim, nfeat_hid_dim)
202 for _ in range(self.num_hid_layers)
203 ]
204 )
205
206 self.lin_out = nn.Linear(nfeat_hid_dim, nfeat_out_dim, bias=not normalize)
207
208 if normalize:
209
210 self.norm = nn.BatchNorm1d(nfeat_out_dim)
211
212 _init_weights(self, normalize)
213

Member Function Documentation

◆ forward()

def forward (   self,
  x,
  edge_index,
  edge_attr,
  u,
  batch 
)
Called internally by PyTorch to propagate the input through the network.
 - x: [N, F_x], where N is the number of nodes.
 - edge_index: [2, E] with max entry N - 1.
 - edge_attr: [E, F_e]
 - u: [B, F_u]
 - batch: [N] with max entry B - 1.

Edge labels are averaged (dim_size = N: number of nodes in the graph)

Definition at line 214 of file geometric_layers.py.

214 def forward(self, x, edge_index, edge_attr, u, batch):
215 """
216 Called internally by PyTorch to propagate the input through the network.
217 - x: [N, F_x], where N is the number of nodes.
218 - edge_index: [2, E] with max entry N - 1.
219 - edge_attr: [E, F_e]
220 - u: [B, F_u]
221 - batch: [N] with max entry B - 1.
222
223 Edge labels are averaged (dim_size = N: number of nodes in the graph)
224 """
225 out = scatter(
226 edge_attr, edge_index[1], dim=0, dim_size=batch.size(0), reduce="mean"
227 )
228 out = (
229 torch.cat([x, out, u[batch]], dim=1)
230 if u.shape != torch.Size([0])
231 else torch.cat([x, out], dim=1)
232 )
233
234 out = self.nonlin_function(self.lin_in(out))
235 out = F.dropout(out, self.dropout_prob, training=self.training)
236
237 out_skip = out
238
239 for lin_hid in self.lins_hid:
240 out = self.nonlin_function(lin_hid(out))
241 out = F.dropout(out, self.dropout_prob, training=self.training)
242
243 if self.num_hid_layers > 1:
244 out += out_skip
245
246 if self.normalize:
247 out = self.nonlin_function(self.norm(self.lin_out(out)))
248 else:
249 out = self.nonlin_function(self.lin_out(out))
250
251 return out
252
253

Member Data Documentation

◆ dropout_prob

dropout_prob

Dropout probability.

Definition at line 190 of file geometric_layers.py.

◆ lin_in

lin_in

Input linear layer.

Definition at line 195 of file geometric_layers.py.

◆ lin_out

lin_out

Output linear layer.

Definition at line 206 of file geometric_layers.py.

◆ lins_hid

lins_hid

Intermediate linear layers.

Definition at line 199 of file geometric_layers.py.

◆ nonlin_function

nonlin_function

Non-linear activation.

Definition at line 186 of file geometric_layers.py.

◆ norm

norm

Batch normalization.

Definition at line 210 of file geometric_layers.py.

◆ normalize

normalize

Normalize.

Definition at line 192 of file geometric_layers.py.

◆ num_hid_layers

num_hid_layers

Number of hidden layers.

Definition at line 188 of file geometric_layers.py.


The documentation for this class was generated from the following file: