class_docstr: The soft attention aggregation layer from the `"Graph Matching Networks
  for Learning the Similarity of Graph Structured Objects"
  <https://arxiv.org/abs/1904.12787>`_ paper.
  
  .. math::
      \mathbf{r}_i = \sum_{n=1}^{N_i} \mathrm{softmax} \left(
      h_{\mathrm{gate}} ( \mathbf{x}_n ) \right) \cdot
      h_{\mathbf{\Theta}} ( \mathbf{x}_n ),
  
  where :math:`h_{\mathrm{gate}} \colon \mathbb{R}^F \to
  \mathbb{R}` and :math:`h_{\mathbf{\Theta}}` denote neural networks, *i.e.*
  MLPs.
  
  Args:
      gate_nn (torch.nn.Module): A neural network :math:`h_{\mathrm{gate}}`
          that computes attention scores by mapping node features :obj:`x` of
          shape :obj:`[-1, in_channels]` to shape :obj:`[-1, 1]` (for
          node-level gating) or :obj:`[1, out_channels]` (for feature-level
          gating), *e.g.*, defined by :class:`torch.nn.Sequential`.
      nn (torch.nn.Module, optional): A neural network
          :math:`h_{\mathbf{\Theta}}` that maps node features :obj:`x` of
          shape :obj:`[-1, in_channels]` to shape :obj:`[-1, out_channels]`
          before combining them with the attention scores, *e.g.*, defined by
          :class:`torch.nn.Sequential`. (default: :obj:`None`)
class_docstr_tok: ["The","soft","attention","aggregation","layer","from","the","`","``","Graph","Matching","Networks","for","Learning","the","Similarity","of","Graph","Structured","Objects","''","<","https",":","\/\/arxiv.org\/abs\/1904.12787",">","`","_","paper",".","..","math",":",":","\\mathbf","{","r","}","_i","=","\\sum_","{","n=1","}","^","{","N_i","}","\\mathrm","{","softmax","}","\\left","(","h_","{","\\mathrm","{","gate","}","}","(","\\mathbf","{","x","}","_n",")","\\right",")","\\cdot","h_","{","\\mathbf","{","\\Theta","}","}","(","\\mathbf","{","x","}","_n",")",",","where",":","math",":","`","h_","{","\\mathrm","{","gate","}","}","\\colon","\\mathbb","{","R","}","^F","\\to","\\mathbb","{","R","}","`","and",":","math",":","`","h_","{","\\mathbf","{","\\Theta","}","}","`","denote","neural","networks",",","*","i.e",".","*","MLPs",".","Args",":","gate_nn","(","torch.nn.Module",")",":","A","neural","network",":","math",":","`","h_","{","\\mathrm","{","gate","}","}","`","that","computes","attention","scores","by","mapping","node","features",":","obj",":","`","x","`","of","shape",":","obj",":","`","[","-1",",","in_channels","]","`","to","shape",":","obj",":","`","[","-1",",","1","]","`","(","for","node-level","gating",")","or",":","obj",":","`","[","1",",","out_channels","]","`","(","for","feature-level","gating",")",",","*","e.g",".","*",",","defined","by",":","class",":","`","torch.nn.Sequential","`",".","nn","(","torch.nn.Module",",","optional",")",":","A","neural","network",":","math",":","`","h_","{","\\mathbf","{","\\Theta","}","}","`","that","maps","node","features",":","obj",":","`","x","`","of","shape",":","obj",":","`","[","-1",",","in_channels","]","`","to","shape",":","obj",":","`","[","-1",",","out_channels","]","`","before","combining","them","with","the","attention","scores",",","*","e.g",".","*",",","defined","by",":","class",":","`","torch.nn.Sequential","`",".","(","default",":",":","obj",":","`","None","`",")"]
code: def __init__(
      self,
      gate_nn: torch.nn.Module,
      nn: Optional[torch.nn.Module] = None,
  ):
      super().__init__()
  
      from torch_geometric.nn import MLP
  
      self.gate_nn = self.gate_mlp = None
      if isinstance(gate_nn, MLP):
          self.gate_mlp = gate_nn
      else:
          self.gate_nn = gate_nn
  
      self.nn = self.mlp = None
      if isinstance(nn, MLP):
          self.mlp = nn
      else:
          self.nn = nn
  
file_path: pytorch_geometric/torch_geometric/nn/aggr/attention.py
imports: from typing import Optional
  import torch
  from torch import Tensor
  from torch_geometric.nn.aggr import Aggregation
  from torch_geometric.nn.inits import reset
  from torch_geometric.utils import softmax
label_desc: Use image node_id 1 to create a new AttentionalAggregation object from inherited base classes: Aggregation with example: obj = AttentionalAggregation(gate_nn, nn)