class_docstr: Abstract base class for MES-like methods using discrete max posterior sampling.
  
  This class provides basic functionality for sampling posterior maximum values from
  a surrogate Gaussian process model using a discrete set of candidates. It supports
  either exact (w.r.t. the candidate set) sampling, or using a Gumbel approximation.
docstr: Draw samples from the posterior over maximum values on a discrete set.
  
  These samples are used to compute Monte Carlo approximations of expectations
  over the posterior over the function maximum.
  
  Args:
      num_samples: The number of samples to draw.
      X_pending: A `m x d`-dim Tensor of `m` design points that have been
          submitted for function evaluation but have not yet been evaluated.
  
  Returns:
      A `num_samples x num_fantasies` Tensor of posterior max value samples
      (`num_fantasies=1` for non-fantasized models).
docstr_tok: ["Draw","samples","from","the","posterior","over","maximum","values","on","a","discrete","set",".","These","samples","are","used","to","compute","Monte","Carlo","approximations","of","expectations","over","the","posterior","over","the","function","maximum",".","Args",":","num_samples",":","The","number","of","samples","to","draw",".","X_pending",":","A","`","m","x","d","`","-dim","Tensor","of","`","m","`","design","points","that","have","been","submitted","for","function","evaluation","but","have","not","yet","been","evaluated",".","Returns",":","A","`","num_samples","x","num_fantasies","`","Tensor","of","posterior","max","value","samples","(","`","num_fantasies=1","`","for","non-fantasized","models",")","."]
code: def _sample_max_values(
      self, num_samples: int, X_pending: Optional[Tensor] = None
  ) -> Tensor:
      r"""Draw samples from the posterior over maximum values on a discrete set.
  
      These samples are used to compute Monte Carlo approximations of expectations
      over the posterior over the function maximum.
  
      Args:
          num_samples: The number of samples to draw.
          X_pending: A `m x d`-dim Tensor of `m` design points that have been
              submitted for function evaluation but have not yet been evaluated.
  
      Returns:
          A `num_samples x num_fantasies` Tensor of posterior max value samples
          (`num_fantasies=1` for non-fantasized models).
      """
      if self.use_gumbel:
          sample_max_values = _sample_max_value_Gumbel
      else:
          sample_max_values = _sample_max_value_Thompson
      candidate_set = self.candidate_set
  
      with torch.no_grad():
          if X_pending is not None:
              # Append X_pending to candidate set
              X_pending = match_batch_shape(
                  X_pending, self.candidate_set
              )
              candidate_set = torch.cat(
                  [self.candidate_set, X_pending], dim=0
              )
  
          # project the candidate_set to the highest fidelity,
          # which is needed for the multi-fidelity MES
          try:
              candidate_set = self.project(candidate_set)
          except AttributeError:
              pass
  
          self.posterior_max_values = sample_max_values(
              model=self.model,
              candidate_set=candidate_set,
              num_samples=self.num_mv_samples,
              posterior_transform=self.posterior_transform,
              maximize=self.maximize,
          )
  
imports: from __future__ import annotations
  from abc import ABC, abstractmethod
  from copy import deepcopy
  from math import log
  from typing import Any, Callable, Optional
  import numpy
  import torch
  from botorch.acquisition.acquisition import AcquisitionFunction, MCSamplerMixin
  from botorch.acquisition.cost_aware import CostAwareUtility, InverseCostWeightedUtility
  from botorch.acquisition.objective import PosteriorTransform
  from botorch.exceptions.errors import UnsupportedError
  from botorch.models.cost import AffineFidelityCostModel
  from botorch.models.model import Model
  from botorch.models.utils import check_no_nans
  from botorch.sampling.normal import SobolQMCNormalSampler
  from botorch.utils.transforms import match_batch_shape, t_batch_mode_transform
  from linear_operator.functions import inv_quad
  from linear_operator.utils.cholesky import psd_safe_cholesky
  from scipy.optimize import brentq
  from scipy.stats import norm
  from torch import Tensor
label_desc: Use image node_id 2 for calling the DiscreteMaxValueBase obj's underlying member method code with example usage: obj._sample_max_values(num_samples, X_pending) without return types