code: def build_laplacian_over_ordinal_integer_actions(
      action_spec: types.BoundedTensorSpec,
  ) -> types.Tensor:
      """Build the unnormalized Laplacian matrix over ordinal integer actions.
  
      Assuming integer actions, this functions builds the (unnormalized) Laplacian
      matrix of the graph implied over the action space. The graph vertices are the
      integers {0...action_spec.maximum - 1}. Two vertices are adjacent if they
      correspond to consecutive integer actions. The `action_spec` must specify
      a scalar int32 or int64 with minimum zero.
  
      Args:
        action_spec: a `BoundedTensorSpec`.
  
      Returns:
        The graph Laplacian matrix (float tensor) of size equal to the number of
        actions. The diagonal elements are equal to 2 and the off-diagonal elements
        are equal to -1.
  
      Raises:
        ValueError: if `action_spec` is not a bounded scalar int32 or int64 spec
          with minimum 0.
      """
      num_actions = policy_utilities.get_num_actions_from_tensor_spec(
          action_spec
      )
      adjacency_matrix = np.zeros([num_actions, num_actions])
      for i in range(num_actions - 1):
          adjacency_matrix[i, i + 1] = 1.0
          adjacency_matrix[i + 1, i] = 1.0
      laplacian_matrix = (
          np.diag(np.sum(adjacency_matrix, axis=0)) - 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 2 for calling a global function with example usage: build_laplacian_over_ordinal_integer_actions(action_spec) and returns: laplacian_matrix