code: def update_reference(
      X_ref: np.ndarray,
      X: np.ndarray,
      n: int,
      update_method: Dict[str, int] = None,
  ) -> np.ndarray:
      """
      Update reference dataset for drift detectors.
  
      Parameters
      ----------
      X_ref
          Current reference dataset.
      X
          New data.
      n
          Count of the total number of instances that have been used so far.
      update_method
          Dict with as key `reservoir_sampling` or `last` and as value n. `reservoir_sampling` will apply
          reservoir sampling with reservoir of size n while `last` will return (at most) the last n instances.
  
      Returns
      -------
      Updated reference dataset.
      """
      if isinstance(update_method, dict):
          update_type = list(update_method.keys())[0]
          size = update_method[update_type]
          if update_type == "reservoir_sampling":
              return reservoir_sampling(X_ref, X, size, n)
          elif update_type == "last":
              X_update = np.concatenate([X_ref, X], axis=0)
              return X_update[-size:]
          else:
              raise KeyError(
                  "Only `reservoir_sampling` and `last` are valid update options for X_ref."
              )
      else:
          return X_ref
  
file_path: alibi-detect/alibi_detect/cd/utils.py
imports: import logging
  import random
  from typing import Callable, Dict, Optional, Tuple, Union
  import numpy
  from alibi_detect.utils.sampling import reservoir_sampling
  from alibi_detect.utils.frameworks import Framework
  from alibi_detect.utils._types import TorchDeviceType
label_desc: Use image node_id 1 for calling a global function with example usage: update_reference(X_ref, X, n, update_method) and returns: X_ref, reservoir_sampling, X_update