class_docstr: Base class for dynamic graph construction.
  
  Parameters
  ----------
  sim_metric_type : str, optional
      Specify similarity metric function type including "attention",
      "weighted_cosine", "gat_attention", "rbf_kernel", and "cosine".
      Default: ``"weighted_cosine"``.
  num_heads : int, optional
      Specify the number of heads for multi-head similarity metric
      function, default: ``1``.
  top_k_neigh : int, optional
      Specify the top k value for knn neighborhood graph sparsificaiton,
      default: ``None``.
  epsilon_neigh : float, optional
      Specify the epsilon value (i.e., between ``0`` and ``1``) for
      epsilon neighborhood graph sparsificaiton, default: ``None``.
  smoothness_ratio : float, optional
      Specify the smoothness ratio (i.e., between ``0`` and ``1``)
      for graph regularization on smoothness, default: ``None``.
  connectivity_ratio : float, optional
      Specify the connectivity ratio (i.e., between ``0`` and ``1``)
      for graph regularization on connectivity, default: ``None``.
  sparsity_ratio : float, optional
      Specify the sparsity ratio (i.e., between ``0`` and ``1``)
      for graph regularization on sparsity, default: ``None``.
  input_size : int, optional
      The dimension of input embeddings, default: ``None``.
  hidden_size : int, optional
      The dimension of hidden layers, default: ``None``.
class_docstr_tok: ["Base","class","for","dynamic","graph","construction",".","Parameters","--","--","--","--","--","sim_metric_type",":","str",",","optional","Specify","similarity","metric","function","type","including","``","attention","''",",","``","weighted_cosine","''",",","``","gat_attention","''",",","``","rbf_kernel","''",",","and","``","cosine","''",".","Default",":","``","``","weighted_cosine","''","``",".","num_heads",":","int",",","optional","Specify","the","number","of","heads","for","multi-head","similarity","metric","function",",","default",":","``","1","``",".","top_k_neigh",":","int",",","optional","Specify","the","top","k","value","for","knn","neighborhood","graph","sparsificaiton",",","default",":","``","None","``",".","epsilon_neigh",":","float",",","optional","Specify","the","epsilon","value","(","i.e.",",","between","``","0","``","and","``","1","``",")","for","epsilon","neighborhood","graph","sparsificaiton",",","default",":","``","None","``",".","smoothness_ratio",":","float",",","optional","Specify","the","smoothness","ratio","(","i.e.",",","between","``","0","``","and","``","1","``",")","for","graph","regularization","on","smoothness",",","default",":","``","None","``",".","connectivity_ratio",":","float",",","optional","Specify","the","connectivity","ratio","(","i.e.",",","between","``","0","``","and","``","1","``",")","for","graph","regularization","on","connectivity",",","default",":","``","None","``",".","sparsity_ratio",":","float",",","optional","Specify","the","sparsity","ratio","(","i.e.",",","between","``","0","``","and","``","1","``",")","for","graph","regularization","on","sparsity",",","default",":","``","None","``",".","input_size",":","int",",","optional","The","dimension","of","input","embeddings",",","default",":","``","None","``",".","hidden_size",":","int",",","optional","The","dimension","of","hidden","layers",",","default",":","``","None","``","."]
docstr: Compute similarity metric.
  
  Parameters
  ----------
  node_emb : torch.Tensor
      The input node embedding matrix.
  node_mask : torch.Tensor, optional
      The node mask matrix, default: ``None``.
  
  Returns
  -------
  torch.Tensor
      Adjacency matrix.
docstr_tok: ["Compute","similarity","metric",".","Parameters","--","--","--","--","--","node_emb",":","torch.Tensor","The","input","node","embedding","matrix",".","node_mask",":","torch.Tensor",",","optional","The","node","mask","matrix",",","default",":","``","None","``",".","Returns","--","--","--","-","torch.Tensor","Adjacency","matrix","."]
code: def compute_similarity_metric(self, node_emb, node_mask=None):
      """Compute similarity metric.
  
      Parameters
      ----------
      node_emb : torch.Tensor
          The input node embedding matrix.
      node_mask : torch.Tensor, optional
          The node mask matrix, default: ``None``.
  
      Returns
      -------
      torch.Tensor
          Adjacency matrix.
      """
      if self.sim_metric_type == "attention":
          attention = 0
          for _ in range(len(self.linear_sims)):
              node_vec_t = torch.relu(self.linear_sims[_](node_emb))
              attention += torch.matmul(
                  node_vec_t, node_vec_t.transpose(-1, -2)
              )
  
          attention /= len(self.linear_sims)
      elif self.sim_metric_type == "weighted_cosine":
          expand_weight_tensor = self.weight.unsqueeze(1)
          if len(node_emb.shape) == 3:
              expand_weight_tensor = expand_weight_tensor.unsqueeze(1)
  
          node_vec_t = node_emb.unsqueeze(0) * expand_weight_tensor
          node_vec_norm = F.normalize(node_vec_t, p=2, dim=-1)
          attention = torch.matmul(
              node_vec_norm, node_vec_norm.transpose(-1, -2)
          ).mean(0)
      elif self.sim_metric_type == "gat_attention":
          attention = []
          for _ in range(len(self.linear_sims1)):
              a_input1 = self.linear_sims1[_](node_emb)
              a_input2 = self.linear_sims2[_](node_emb)
              attention.append(
                  self.leakyrelu(a_input1 + a_input2.transpose(-1, -2))
              )
  
          attention = torch.mean(torch.stack(attention, 0), 0)
      elif self.sim_metric_type == "rbf_kernel":
          dist_weight = torch.mm(
              self.weight, self.weight.transpose(-1, -2)
          )
          attention = self._compute_distance_matrix(
              node_emb, dist_weight
          )
          attention = torch.exp(
              -0.5 * attention * (self.precision_inv_dis**2)
          )
      elif self.sim_metric_type == "cosine":
          node_vec_norm = node_emb.div(
              torch.norm(node_emb, p=2, dim=-1, keepdim=True)
          )
          attention = torch.mm(
              node_vec_norm, node_vec_norm.transpose(-1, -2)
          ).detach()
  
      if node_mask is not None:
          if torch.__version__ < "1.3.0":
              attention = attention.masked_fill_(
                  ~(node_mask == 1.0), self.mask_off_val
              )
          else:
              attention = attention.masked_fill_(
                  ~node_mask.bool(), self.mask_off_val
              )
  
      return attention
  
imports: import numpy
  import torch
  import torch.nn.functional
  from scipy import sparse
  from torch import nn
  from ..utils.constants import INF, VERY_SMALL_NUMBER
  from ..utils.generic_utils import normalize_adj, sparse_mx_to_torch_sparse_tensor
label_desc: Use image node_id 3 for calling the DynamicGraphConstructionBase obj's underlying member method code with example usage: obj.compute_similarity_metric(node_emb, node_mask) and returns: attention