class_docstr: Multi-fidelity max-value entropy.
  
  The acquisition function for multi-fidelity max-value entropy search
  with support for trace observations. See [Takeno2020mfmves]_
  for a detailed discussion of the basic ideas on multi-fidelity MES
  (note that this implementation is somewhat different).
  
  The model must be single-outcome, unless using a PosteriorTransform.
  The batch case `q > 1` is supported through cyclic optimization and fantasies.
  
  Example:
      >>> model = SingleTaskGP(train_X, train_Y)
      >>> candidate_set = torch.rand(1000, bounds.size(1))
      >>> candidate_set = bounds[0] + (bounds[1] - bounds[0]) * candidate_set
      >>> MF_MES = qMultiFidelityMaxValueEntropy(model, candidate_set)
      >>> mf_mes = MF_MES(test_X)
docstr: Single-outcome max-value entropy search acquisition function.
  
  Args:
      model: A fitted single-outcome model.
      candidate_set: A `n x d` Tensor including `n` candidate points to
          discretize the design space, which will be used to sample the
          max values from their posteriors.
      cost_aware_utility: A CostAwareUtility computing the cost-transformed
          utility from a candidate set and samples of increases in utility.
      num_fantasies: Number of fantasies to generate. The higher this
          number the more accurate the model (at the expense of model
          complexity and performance) and it's only used when `X_pending`
          is not `None`.
      num_mv_samples: Number of max value samples.
      num_y_samples: Number of posterior samples at specific design point `X`.
      posterior_transform: A PosteriorTransform. If using a multi-output model,
          a PosteriorTransform that transforms the multi-output posterior into a
          single-output posterior is required.
      use_gumbel: If True, use Gumbel approximation to sample the max values.
      maximize: If True, consider the problem a maximization problem.
      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.
      cost_aware_utility: A CostAwareUtility computing the cost-transformed
          utility from a candidate set and samples of increases in utility.
      project: A callable mapping a `batch_shape x q x d` tensor of design
          points to a tensor of the same shape projected to the desired
          target set (e.g. the target fidelities in case of multi-fidelity
          optimization).
      expand: A callable mapping a `batch_shape x q x d` input tensor to
          a `batch_shape x (q + q_e)' x d`-dim output tensor, where the
          `q_e` additional points in each q-batch correspond to
          additional ("trace") observations.
docstr_tok: ["Single-outcome","max-value","entropy","search","acquisition","function",".","Args",":","model",":","A","fitted","single-outcome","model",".","candidate_set",":","A","`","n","x","d","`","Tensor","including","`","n","`","candidate","points","to","discretize","the","design","space",",","which","will","be","used","to","sample","the","max","values","from","their","posteriors",".","cost_aware_utility",":","A","CostAwareUtility","computing","the","cost-transformed","utility","from","a","candidate","set","and","samples","of","increases","in","utility",".","num_fantasies",":","Number","of","fantasies","to","generate",".","The","higher","this","number","the","more","accurate","the","model","(","at","the","expense","of","model","complexity","and","performance",")","and","it","'s","only","used","when","`","X_pending","`","is","not","`","None","`",".","num_mv_samples",":","Number","of","max","value","samples",".","num_y_samples",":","Number","of","posterior","samples","at","specific","design","point","`","X","`",".","posterior_transform",":","A","PosteriorTransform",".","If","using","a","multi-output","model",",","a","PosteriorTransform","that","transforms","the","multi-output","posterior","into","a","single-output","posterior","is","required",".","use_gumbel",":","If","True",",","use","Gumbel","approximation","to","sample","the","max","values",".","maximize",":","If","True",",","consider","the","problem","a","maximization","problem",".","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",".","cost_aware_utility",":","A","CostAwareUtility","computing","the","cost-transformed","utility","from","a","candidate","set","and","samples","of","increases","in","utility",".","project",":","A","callable","mapping","a","`","batch_shape","x","q","x","d","`","tensor","of","design","points","to","a","tensor","of","the","same","shape","projected","to","the","desired","target","set","(","e.g",".","the","target","fidelities","in","case","of","multi-fidelity","optimization",")",".","expand",":","A","callable","mapping","a","`","batch_shape","x","q","x","d","`","input","tensor","to","a","`","batch_shape","x","(","q","+","q_e",")","'","x","d","`","-dim","output","tensor",",","where","the","`","q_e","`","additional","points","in","each","q-batch","correspond","to","additional","(","``","trace","''",")","observations","."]
code: def __init__(
      self,
      model: Model,
      candidate_set: Tensor,
      num_fantasies: int = 16,
      num_mv_samples: int = 10,
      num_y_samples: int = 128,
      posterior_transform: Optional[PosteriorTransform] = None,
      use_gumbel: bool = True,
      maximize: bool = True,
      X_pending: Optional[Tensor] = None,
      cost_aware_utility: Optional[CostAwareUtility] = None,
      project: Callable[[Tensor], Tensor] = lambda X: X,
      expand: Callable[[Tensor], Tensor] = lambda X: X,
  ) -> None:
      r"""Single-outcome max-value entropy search acquisition function.
  
      Args:
          model: A fitted single-outcome model.
          candidate_set: A `n x d` Tensor including `n` candidate points to
              discretize the design space, which will be used to sample the
              max values from their posteriors.
          cost_aware_utility: A CostAwareUtility computing the cost-transformed
              utility from a candidate set and samples of increases in utility.
          num_fantasies: Number of fantasies to generate. The higher this
              number the more accurate the model (at the expense of model
              complexity and performance) and it's only used when `X_pending`
              is not `None`.
          num_mv_samples: Number of max value samples.
          num_y_samples: Number of posterior samples at specific design point `X`.
          posterior_transform: A PosteriorTransform. If using a multi-output model,
              a PosteriorTransform that transforms the multi-output posterior into a
              single-output posterior is required.
          use_gumbel: If True, use Gumbel approximation to sample the max values.
          maximize: If True, consider the problem a maximization problem.
          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.
          cost_aware_utility: A CostAwareUtility computing the cost-transformed
              utility from a candidate set and samples of increases in utility.
          project: A callable mapping a `batch_shape x q x d` tensor of design
              points to a tensor of the same shape projected to the desired
              target set (e.g. the target fidelities in case of multi-fidelity
              optimization).
          expand: A callable mapping a `batch_shape x q x d` input tensor to
              a `batch_shape x (q + q_e)' x d`-dim output tensor, where the
              `q_e` additional points in each q-batch correspond to
              additional ("trace") observations.
      """
      super().__init__(
          model=model,
          candidate_set=candidate_set,
          num_fantasies=num_fantasies,
          num_mv_samples=num_mv_samples,
          num_y_samples=num_y_samples,
          posterior_transform=posterior_transform,
          use_gumbel=use_gumbel,
          maximize=maximize,
          X_pending=X_pending,
      )
  
      if cost_aware_utility is None:
          cost_model = AffineFidelityCostModel(
              fidelity_weights={-1: 1.0}
          )
          cost_aware_utility = InverseCostWeightedUtility(
              cost_model=cost_model
          )
  
      self.cost_aware_utility = cost_aware_utility
      self.expand = expand
      self.project = project
      self._cost_sampler = None
  
      # @TODO make sure fidelity_dims align in project, expand & cost_aware_utility
      # It seems very difficult due to the current way of handling project/expand
  
      # resample max values after initializing self.project
      # so that the max value samples are at the highest fidelity
      self._sample_max_values(self.num_mv_samples)
  
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 1 to create a new qMultiFidelityMaxValueEntropy object from inherited base classes: qMaxValueEntropy with example: obj = qMultiFidelityMaxValueEntropy(model, candidate_set, num_fantasies, num_mv_samples, num_y_samples, posterior_transform, use_gumbel, maximize, X_pending, cost_aware_utility, project, expand)