code: def _pivoted_cholesky_init(
      train_inputs: Tensor,
      kernel_matrix: Union[Tensor, LinearOperator],
      max_length: int,
      quality_scores: Tensor,
      epsilon: float = 1e-6,
  ) -> Tensor:
      r"""
      A pivoted Cholesky initialization method for the inducing points,
      originally proposed in [burt2020svgp]_ with the algorithm itself coming from
      [chen2018dpp]_. Code is a PyTorch version from [chen2018dpp]_, based on
      https://github.com/laming-chen/fast-map-dpp/blob/master/dpp.py but with a small
      modification to allow the underlying DPP to be defined through its diversity-quality
      decomposition,as discussed by [moss2023ipa]_. This method returns a greedy
      approximation of the MAP estimate of the specified DPP, i.e. its returns a
      set of points that are highly diverse (according to the provided kernel_matrix)
      and have high quality (according to the provided quality_scores).
  
      Args:
          train_inputs: training inputs (of shape n x d)
          kernel_matrix: kernel matrix on the training inputs
          max_length: number of inducing points to initialize
          quality_scores: scores representing the quality of each candidate
              input (of shape [n])
          epsilon: numerical jitter for stability.
  
      Returns:
          max_length x d tensor of the training inputs corresponding to the top
          max_length pivots of the training kernel matrix
      """
  
      # this is numerically equivalent to iteratively performing a pivoted cholesky
      # while storing the diagonal pivots at each iteration
      # TODO: use gpytorch's pivoted cholesky instead once that gets an exposed list
      # TODO: ensure this works in batch mode, which it does not currently.
  
      # todo test for shape of quality function
  
      if quality_scores.shape[0] != train_inputs.shape[0]:
          raise ValueError(
              "_pivoted_cholesky_init requires a quality score for each of train_inputs"
          )
  
      if kernel_matrix.requires_grad:
          raise UnsupportedError(
              "`_pivoted_cholesky_init` does not support using a `kernel_matrix` "
              "with `requires_grad=True`."
          )
  
      item_size = kernel_matrix.shape[-2]
      cis = torch.zeros(
          (max_length, item_size),
          device=kernel_matrix.device,
          dtype=kernel_matrix.dtype,
      )
      di2s = kernel_matrix.diagonal()
      scores = di2s * torch.square(quality_scores)
      selected_item = torch.argmax(scores)
      selected_items = [selected_item]
  
      while len(selected_items) < max_length:
          k = len(selected_items) - 1
          ci_optimal = cis[:k, selected_item]
          di_optimal = torch.sqrt(di2s[selected_item])
          elements = kernel_matrix[..., selected_item, :]
          eis = (
              elements - torch.matmul(ci_optimal, cis[:k, :])
          ) / di_optimal
          cis[k, :] = eis
          di2s = di2s - eis.pow(2.0)
          di2s[selected_item] = NEG_INF
          scores = di2s * torch.square(quality_scores)
          selected_item = torch.argmax(scores)
          if di2s[selected_item] < epsilon:
              break
          selected_items.append(selected_item)
  
      ind_points = train_inputs[torch.stack(selected_items)]
  
      return ind_points[:max_length, :]
  
imports: from __future__ import annotations
  from abc import ABC, abstractmethod
  from typing import Union
  import torch
  from botorch.exceptions.errors import UnsupportedError
  from botorch.models.model import Model
  from botorch.utils.probability.utils import ndtr, phi
  from gpytorch.module import Module
  from linear_operator.operators import LinearOperator
  from torch import Tensor
label_desc: Use image node_id 1 for calling a global function with example usage: _pivoted_cholesky_init(train_inputs, kernel_matrix, max_length, quality_scores, epsilon) and returns: ind_points