class_docstr: The Recurrent Event Network model from the `"Recurrent Event Network
  for Reasoning over Temporal Knowledge Graphs"
  <https://arxiv.org/abs/1904.05530>`_ paper.
  
  .. math::
      f_{\mathbf{\Theta}}(\mathbf{e}_s, \mathbf{e}_r,
      \mathbf{h}^{(t-1)}(s, r))
  
  based on a RNN encoder
  
  .. math::
      \mathbf{h}^{(t)}(s, r) = \textrm{RNN}(\mathbf{e}_s, \mathbf{e}_r,
      g(\mathcal{O}^{(t)}_r(s)), \mathbf{h}^{(t-1)}(s, r))
  
  where :math:`\mathbf{e}_s` and :math:`\mathbf{e}_r` denote entity and
  relation embeddings, and :math:`\mathcal{O}^{(t)}_r(s)` represents the set
  of objects interacted with subject :math:`s` under relation :math:`r` at
  timestamp :math:`t`.
  This model implements :math:`g` as the **Mean Aggregator** and
  :math:`f_{\mathbf{\Theta}}` as a linear projection.
  
  Args:
      num_nodes (int): The number of nodes in the knowledge graph.
      num_rels (int): The number of relations in the knowledge graph.
      hidden_channels (int): Hidden size of node and relation embeddings.
      seq_len (int): The sequence length of past events.
      num_layers (int, optional): The number of recurrent layers.
          (default: :obj:`1`)
      dropout (float): If non-zero, introduces a dropout layer before the
          final prediction. (default: :obj:`0.`)
      bias (bool, optional): If set to :obj:`False`, all layers will not
          learn an additive bias. (default: :obj:`True`)
class_docstr_tok: ["The","Recurrent","Event","Network","model","from","the","`","``","Recurrent","Event","Network","for","Reasoning","over","Temporal","Knowledge","Graphs","''","<","https",":","\/\/arxiv.org\/abs\/1904.05530",">","`","_","paper",".","..","math",":",":","f_","{","\\mathbf","{","\\Theta","}","}","(","\\mathbf","{","e","}","_s",",","\\mathbf","{","e","}","_r",",","\\mathbf","{","h","}","^","{","(","t-1",")","}","(","s",",","r",")",")","based","on","a","RNN","encoder","..","math",":",":","\\mathbf","{","h","}","^","{","(","t",")","}","(","s",",","r",")","=","\\textrm","{","RNN","}","(","\\mathbf","{","e","}","_s",",","\\mathbf","{","e","}","_r",",","g","(","\\mathcal","{","O","}","^","{","(","t",")","}","_r","(","s",")",")",",","\\mathbf","{","h","}","^","{","(","t-1",")","}","(","s",",","r",")",")","where",":","math",":","`","\\mathbf","{","e","}","_s","`","and",":","math",":","`","\\mathbf","{","e","}","_r","`","denote","entity","and","relation","embeddings",",","and",":","math",":","`","\\mathcal","{","O","}","^","{","(","t",")","}","_r","(","s",")","`","represents","the","set","of","objects","interacted","with","subject",":","math",":","`","s","`","under","relation",":","math",":","`","r","`","at","timestamp",":","math",":","`","t","`",".","This","model","implements",":","math",":","`","g","`","as","the","*","*","Mean","Aggregator","*","*","and",":","math",":","`","f_","{","\\mathbf","{","\\Theta","}","}","`","as","a","linear","projection",".","Args",":","num_nodes","(","int",")",":","The","number","of","nodes","in","the","knowledge","graph",".","num_rels","(","int",")",":","The","number","of","relations","in","the","knowledge","graph",".","hidden_channels","(","int",")",":","Hidden","size","of","node","and","relation","embeddings",".","seq_len","(","int",")",":","The","sequence","length","of","past","events",".","num_layers","(","int",",","optional",")",":","The","number","of","recurrent","layers",".","(","default",":",":","obj",":","`","1","`",")","dropout","(","float",")",":","If","non-zero",",","introduces","a","dropout","layer","before","the","final","prediction",".","(","default",":",":","obj",":","`","0.","`",")","bias","(","bool",",","optional",")",":","If","set","to",":","obj",":","`","False","`",",","all","layers","will","not","learn","an","additive","bias",".","(","default",":",":","obj",":","`","True","`",")"]
docstr: Precomputes history objects.
  
  .. math::
      \{ \mathcal{O}^{(t-k-1)}_r(s), \ldots, \mathcal{O}^{(t-1)}_r(s) \}
  
  of a :class:`torch_geometric.datasets.icews.EventDataset` with
  :math:`k` denoting the sequence length :obj:`seq_len`.
docstr_tok: ["Precomputes","history","objects",".","..","math",":",":","\\","{","\\mathcal","{","O","}","^","{","(","t-k-1",")","}","_r","(","s",")",",","\\ldots",",","\\mathcal","{","O","}","^","{","(","t-1",")","}","_r","(","s",")","\\","}","of","a",":","class",":","`","torch_geometric.datasets.icews.EventDataset","`","with",":","math",":","`","k","`","denoting","the","sequence","length",":","obj",":","`","seq_len","`","."]
code: def pre_transform(seq_len: int) -> Callable:
      r"""Precomputes history objects.
  
      .. math::
          \{ \mathcal{O}^{(t-k-1)}_r(s), \ldots, \mathcal{O}^{(t-1)}_r(s) \}
  
      of a :class:`torch_geometric.datasets.icews.EventDataset` with
      :math:`k` denoting the sequence length :obj:`seq_len`.
      """
  
      class PreTransform:
          def __init__(self, seq_len: int):
              self.seq_len = seq_len
              self.inc = 5000
              self.t_last = 0
              self.sub_hist = self.increase_hist_node_size([])
              self.obj_hist = self.increase_hist_node_size([])
  
          def increase_hist_node_size(
              self, hist: List[int]
          ) -> List[int]:
              hist_inc = torch.zeros((self.inc, self.seq_len + 1, 0))
              return hist + hist_inc.tolist()
  
          def get_history(
              self,
              hist: List[int],
              node: int,
              rel: int,
          ) -> Tuple[Tensor, Tensor]:
              hists, ts = [], []
              for s in range(seq_len):
                  h = hist[node][s]
                  hists += h
                  ts.append(torch.full((len(h),), s, dtype=torch.long))
              node, r = (
                  torch.tensor(hists, dtype=torch.long)
                  .view(-1, 2)
                  .t()
                  .contiguous()
              )
              node = node[r == rel]
              t = torch.cat(ts, dim=0)[r == rel]
              return node, t
  
          def step(self, hist: List[int]) -> List[int]:
              for i in range(len(hist)):
                  hist[i] = hist[i][1:]
                  hist[i].append([])
              return hist
  
          def __call__(self, data: Data) -> Data:
              sub, rel, obj, t = data.sub, data.rel, data.obj, data.t
  
              if max(sub, obj) + 1 > len(
                  self.sub_hist
              ):  # pragma: no cover
                  self.sub_hist = self.increase_hist_node_size(
                      self.sub_hist
                  )
                  self.obj_hist = self.increase_hist_node_size(
                      self.obj_hist
                  )
  
              # Delete last timestamp in history.
              if t > self.t_last:
                  self.sub_hist = self.step(self.sub_hist)
                  self.obj_hist = self.step(self.obj_hist)
                  self.t_last = t
  
              # Save history in data object.
              data.h_sub, data.h_sub_t = self.get_history(
                  self.sub_hist, sub, rel
              )
              data.h_obj, data.h_obj_t = self.get_history(
                  self.obj_hist, obj, rel
              )
  
              # Add new event to history.
              self.sub_hist[sub][-1].append([obj, rel])
              self.obj_hist[obj][-1].append([sub, rel])
  
              return data
  
          def __repr__(self) -> str:  # pragma: no cover
              return (
                  f"{self.__class__.__name__}(seq_len={self.seq_len})"
              )
  
      return PreTransform(seq_len)
  
file_path: pytorch_geometric/torch_geometric/nn/models/re_net.py
imports: import math
  from typing import Callable, List, Tuple
  import torch
  import torch.nn.functional
  from torch import Tensor
  from torch.nn import GRU, Linear, Parameter
  from torch_geometric.data.data import Data
  from torch_geometric.utils import scatter
label_desc: Use image node_id 3 for calling the RENet obj's underlying member method code with example usage: obj.pre_transform(seq_len) and returns: PreTransform, unknown, node,  t, hist, data, self, str, self, str