code: def build_laplacian_nearest_neighbor_graph(
      input_vecs: types.Tensor, k: int = 1
  ) -> types.Tensor:
      """Build the Laplacian matrix of a nearest neighbor graph.
  
      Given input embedding vectors, this utility returns the Laplacian matrix of
      the induced k-nearest-neighbor graph.
  
      Args:
        input_vecs: a `Tensor`. Input embedding vectors (one per row). Shaped
          `[num_vectors, ...]`.
        k: an integer. Number of nearest neighbors to use.
  
      Returns:
        The graph Laplacian matrix. A dense float `Tensor` of shape
        `[num_vectors, num_vectors]`, where `num_vectors` is the number of input
        embedding vectors (`Tensor`).
      """
      num_actions = tf.shape(input_vecs)[0]
      pdistance_matrix = compute_pairwise_distances(input_vecs)
      sorted_indices = tf.argsort(values=pdistance_matrix)
      selected_indices = tf.reshape(
          sorted_indices[:, 1 : k + 1], [-1, 1]
      )
      rng = tf.tile(
          tf.expand_dims(tf.range(num_actions), axis=-1), [1, k]
      )
      rng = tf.reshape(rng, [-1, 1])
      full_indices = tf.concat([rng, selected_indices], axis=1)
      adjacency_matrix = tf.zeros(
          [num_actions, num_actions], dtype=tf.float32
      )
      adjacency_matrix = tf.tensor_scatter_nd_update(
          tensor=adjacency_matrix,
          indices=full_indices,
          updates=tf.ones([k * num_actions], dtype=tf.float32),
      )
      # Symmetrize it.
      adjacency_matrix = adjacency_matrix + tf.transpose(
          adjacency_matrix
      )
      adjacency_matrix = tf.minimum(
          adjacency_matrix, tf.ones_like(adjacency_matrix)
      )
      degree_matrix = tf.linalg.tensor_diag(
          tf.reduce_sum(adjacency_matrix, axis=1)
      )
      laplacian_matrix = degree_matrix - adjacency_matrix
      return laplacian_matrix
  
file_path: agents/tf_agents/bandits/agents/utils.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from typing import Tuple
  import gin
  import numpy
  import tensorflow
  from tf_agents.bandits.specs import utils
  from tf_agents.policies import utils
  from tf_agents.typing import types
  from tf_agents.utils import nest_utils
label_desc: Use image node_id 4 for calling a global function with example usage: build_laplacian_nearest_neighbor_graph(input_vecs, k) and returns: laplacian_matrix