code: def jitter_cholesky(
      F,
      matrix: Tensor,
      num_data_points: Optional[int] = None,
      float_type: Type = np.float64,
      max_iter_jitter: int = 10,
      neg_tol: float = -1e-8,
      diag_weight: float = 1e-6,
      increase_jitter: int = 10,
  ) -> Optional[Tensor]:
      """
      This function applies the jitter method.  It iteratively tries to compute
      the Cholesky decomposition and adds a positive tolerance to the diagonal
      that increases at each iteration until the matrix is positive definite or
      the maximum number of iterations has been reached.
  
      Parameters
      ----------
      matrix
          Kernel matrix of shape (batch_size, num_data_points, num_data_points).
      num_data_points
          Number of rows in the kernel_matrix.
      float_type
          Determines whether to use single or double precision.
      max_iter_jitter
          Maximum number of iterations for jitter to iteratively make the matrix
          positive definite.
      neg_tol
          Parameter in the jitter methods to eliminate eliminate matrices with
          diagonal elements smaller than this when checking if a matrix is
          positive definite.
      diag_weight
              Multiple of mean of diagonal entries to initialize the jitter.
      increase_jitter
          Each iteration multiply by jitter by this amount
      Returns
      -------
      Optional[Tensor]
          The method either fails to make the matrix positive definite within the
          maximum number of iterations and outputs an error or succeeds and
          returns the lower triangular Cholesky factor `L` of shape
          (batch_size, num_data_points, num_data_points)
      """
      num_iter = 0
      diag = batch_diagonal(
          F, matrix, num_data_points, float_type
      )  # shape (batch_size, num_data_points, 1)
      diag_mean = diag.mean(axis=1).expand_dims(
          axis=2
      )  # shape (batch_size, 1, 1)
      jitter = F.zeros_like(
          diag
      )  # shape (batch_size, num_data_points, 1)
      # Ensure that diagonal entries are numerically non-negative, as defined by
      # neg_to
      # TODO: Add support for symbolic case: Cannot use < operator with symbolic
      # variables
      if F.sum(diag <= neg_tol) > 0:
          raise mx.base.MXNetError(
              " Matrix is not positive definite: negative diagonal elements"
          )
      while num_iter <= max_iter_jitter:
          try:
              L = F.linalg.potrf(
                  F.broadcast_add(
                      matrix,
                      F.broadcast_mul(
                          F.eye(num_data_points, dtype=float_type),
                          jitter,
                      ),
                  )
              )
              # gpu will not throw error but will store nans. If nan, L.sum() =
              # nan and L.nansum() computes the sum treating nans as zeros so
              # the error tolerance can be large. for axis = Null, nansum() and
              # sum() will sum over all elements and return scalar array with
              # shape (1,) TODO: Add support for symbolic case: Cannot use <=
              # operator with symbolic variables
              assert F.abs(L.nansum() - L.sum()) <= 1e-1
              return L
          except Exception:  # TODO: this looks weird
              if num_iter == 0:
                  # Initialize the jitter: constant jitter per each batch
                  jitter = (
                      F.broadcast_mul(diag_mean, F.ones_like(jitter))
                      * diag_weight
                  )
              else:
                  jitter = jitter * increase_jitter
          finally:
              num_iter += 1
      raise mx.base.MXNetError(
          " Matrix is not positive definite after the maximum number of"
          f" iterations = {max_iter_jitter} with a maximum jitter ="
          f" {F.max(jitter)}"
      )
  
imports: from typing import Optional, Type
  import mxnet
  import numpy
  from gluonts.mx import Tensor
label_desc: Use image node_id 4 for calling a global function with example usage: jitter_cholesky(F, matrix, num_data_points, float_type, max_iter_jitter, neg_tol, diag_weight, increase_jitter) and returns: L