class_docstr: DiffPool Fuse
class_docstr_tok: ["DiffPool","Fuse"]
code: def __init__(
      self,
      input_dim,
      hidden_dim,
      embedding_dim,
      label_dim,
      activation,
      n_layers,
      dropout,
      n_pooling,
      linkpred,
      batch_size,
      aggregator_type,
      assign_dim,
      pool_ratio,
      cat=False,
  ):
      super(DiffPool, self).__init__()
      self.link_pred = linkpred
      self.concat = cat
      self.n_pooling = n_pooling
      self.batch_size = batch_size
      self.link_pred_loss = []
      self.entropy_loss = []
  
      # list of GNN modules before the first diffpool operation
      self.gc_before_pool = nn.ModuleList()
      self.diffpool_layers = nn.ModuleList()
  
      # list of list of GNN modules, each list after one diffpool operation
      self.gc_after_pool = nn.ModuleList()
      self.assign_dim = assign_dim
      self.bn = True
      self.num_aggs = 1
  
      # constructing layers
      # layers before diffpool
      assert n_layers >= 3, "n_layers too few"
      self.gc_before_pool.append(
          GraphSageLayer(
              input_dim,
              hidden_dim,
              activation,
              dropout,
              aggregator_type,
              self.bn,
          )
      )
      for _ in range(n_layers - 2):
          self.gc_before_pool.append(
              GraphSageLayer(
                  hidden_dim,
                  hidden_dim,
                  activation,
                  dropout,
                  aggregator_type,
                  self.bn,
              )
          )
      self.gc_before_pool.append(
          GraphSageLayer(
              hidden_dim, embedding_dim, None, dropout, aggregator_type
          )
      )
  
      assign_dims = []
      assign_dims.append(self.assign_dim)
      if self.concat:
          # diffpool layer receive pool_emedding_dim node feature tensor
          # and return pool_embedding_dim node embedding
          pool_embedding_dim = (
              hidden_dim * (n_layers - 1) + embedding_dim
          )
      else:
          pool_embedding_dim = embedding_dim
  
      self.first_diffpool_layer = DiffPoolBatchedGraphLayer(
          pool_embedding_dim,
          self.assign_dim,
          hidden_dim,
          activation,
          dropout,
          aggregator_type,
          self.link_pred,
      )
      gc_after_per_pool = nn.ModuleList()
  
      for _ in range(n_layers - 1):
          gc_after_per_pool.append(
              BatchedGraphSAGE(hidden_dim, hidden_dim)
          )
      gc_after_per_pool.append(
          BatchedGraphSAGE(hidden_dim, embedding_dim)
      )
      self.gc_after_pool.append(gc_after_per_pool)
  
      self.assign_dim = int(self.assign_dim * pool_ratio)
      # each pooling module
      for _ in range(n_pooling - 1):
          self.diffpool_layers.append(
              BatchedDiffPool(
                  pool_embedding_dim,
                  self.assign_dim,
                  hidden_dim,
                  self.link_pred,
              )
          )
          gc_after_per_pool = nn.ModuleList()
          for _ in range(n_layers - 1):
              gc_after_per_pool.append(
                  BatchedGraphSAGE(hidden_dim, hidden_dim)
              )
          gc_after_per_pool.append(
              BatchedGraphSAGE(hidden_dim, embedding_dim)
          )
          self.gc_after_pool.append(gc_after_per_pool)
          assign_dims.append(self.assign_dim)
          self.assign_dim = int(self.assign_dim * pool_ratio)
  
      # predicting layer
      if self.concat:
          self.pred_input_dim = (
              pool_embedding_dim * self.num_aggs * (n_pooling + 1)
          )
      else:
          self.pred_input_dim = embedding_dim * self.num_aggs
      self.pred_layer = nn.Linear(self.pred_input_dim, label_dim)
  
      # weight initialization
      for m in self.modules():
          if isinstance(m, nn.Linear):
              m.weight.data = init.xavier_uniform_(
                  m.weight.data, gain=nn.init.calculate_gain("relu")
              )
              if m.bias is not None:
                  m.bias.data = init.constant_(m.bias.data, 0.0)
  
file_path: dgl/examples/pytorch/diffpool/model/encoder.py
imports: import time
  import dgl
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from scipy.linalg import block_diag
  from torch.nn import init
  from .dgl_layers import DiffPoolBatchedGraphLayer, GraphSage, GraphSageLayer
  from .model_utils import batch2tensor
  from .tensorized_layers import *
label_desc: Use image node_id 1 to create a new DiffPool object from inherited base classes: nn with example: obj = DiffPool(input_dim, hidden_dim, embedding_dim, label_dim, activation, n_layers, dropout, n_pooling, linkpred, batch_size, aggregator_type, assign_dim, pool_ratio, cat)