code: def avg_of_k_best(
      archive: utils.Archive[utils.MultiValue],
      method: str = "dimfourth",
  ) -> np.ndarray:
      """Operators inspired by the work of Yann Chevaleyre, Laurent Meunier, Clement Royer, Olivier Teytaud, Fabien Teytaud.
  
      Parameters
      ----------
      archive: utils.Archive[utils.Value]
          Provides a random recommendation instead of the best point so far (for baseline)
      method: str
          If dimfourth, we use the Fteytaud heuristic, i.e. k = min(len(archive) // 4, dimension)
          If exp, we use the Lmeunier method, i.e. k=max(1, len(archiv) // (2**dimension))
          If hull, we use the maximum k <= dimfourth-value, such that the function looks quasiconvex on the k best points.
      """
      items = list(archive.items_as_arrays())
      dimension = len(items[0][0])
      if method == "dimfourth":
          k = min(len(archive) // 4, dimension)  # fteytaud heuristic.
      elif method == "exp":
          k = max(1, int(len(archive) // (1.1**dimension)))
      elif method == "hull":
          k = convex_limit(
              np.concatenate(
                  sorted(
                      items,
                      key=lambda indiv: archive[
                          indiv[0]
                      ].get_estimation("pessimistic"),
                  ),
                  axis=0,
              )
          )
          k = min(
              len(archive) // 4,
              min(k, int(len(archive) / (1.1**dimension))),
          )
          # We might investigate the possibility to return the middle of the convex hull instead of averaging:
          # return hull_center(np.concatenate(sorted(items, key=lambda indiv: archive[indiv[0]].get_estimation("pessimistic")), axis=0), k)
      else:
          raise ValueError(
              f"{method} not implemented as a method for choosing k in avg_of_k_best."
          )
      k = 1 if k < 1 else int(k)
      # Wasted time.
      first_k_individuals = sorted(
          items,
          key=lambda indiv: archive[indiv[0]].get_estimation(
              "pessimistic"
          ),
      )[:k]
      assert len(first_k_individuals) == k
      return np.array(sum(p[0] for p in first_k_individuals) / k)
  
imports: import copy
  import numpy
  from scipy.spatial import ConvexHull
  import nevergrad.common.typing
  from nevergrad.parametrization import parameter
  from nevergrad.parametrization import transforms
  from .None import sequences
  from .None import base
  from .base import IntOrParameter
  from .None import utils
label_desc: Use image node_id 3 for calling a global function with example usage: avg_of_k_best(archive, method) and returns: np