class_docstr: The Conditional Value-at-Risk risk measure.
  
  The Conditional Value-at-Risk measures the expectation of the worst outcomes
  (small rewards or large losses) with a total probability of `1 - alpha`. It
  is commonly defined as the conditional expectation of the reward function,
  with the condition that the reward is smaller than the corresponding
  Value-at-Risk (also defined below).
  
  Note: Due to the use of a discrete `w_set` of samples, the VaR and CVaR
      calculated here are (possibly biased) Monte-Carlo approximations of
      the true risk measures.
class_docstr_tok: ["The","Conditional","Value-at-Risk","risk","measure",".","The","Conditional","Value-at-Risk","measures","the","expectation","of","the","worst","outcomes","(","small","rewards","or","large","losses",")","with","a","total","probability","of","`","1","-","alpha","`",".","It","is","commonly","defined","as","the","conditional","expectation","of","the","reward","function",",","with","the","condition","that","the","reward","is","smaller","than","the","corresponding","Value-at-Risk","(","also","defined","below",")",".","Note",":","Due","to","the","use","of","a","discrete","`","w_set","`","of","samples",",","the","VaR","and","CVaR","calculated","here","are","(","possibly","biased",")","Monte-Carlo","approximations","of","the","true","risk","measures","."]
docstr: Transform the posterior samples to samples of a risk measure.
  
  Args:
      alpha: The risk level, float in `(0.0, 1.0]`.
      n_w: The size of the `w_set` to calculate the risk measure over.
      preprocessing_function: A preprocessing function to apply to the samples
          before computing the risk measure. This can be used to scalarize
          multi-output samples before calculating the risk measure.
          For constrained optimization, this should also apply
          feasibility-weighting to samples. Given a `batch x m`-dim
          tensor of samples, this should return a `batch`-dim tensor.
docstr_tok: ["Transform","the","posterior","samples","to","samples","of","a","risk","measure",".","Args",":","alpha",":","The","risk","level",",","float","in","`","(","0.0",",","1.0","]","`",".","n_w",":","The","size","of","the","`","w_set","`","to","calculate","the","risk","measure","over",".","preprocessing_function",":","A","preprocessing","function","to","apply","to","the","samples","before","computing","the","risk","measure",".","This","can","be","used","to","scalarize","multi-output","samples","before","calculating","the","risk","measure",".","For","constrained","optimization",",","this","should","also","apply","feasibility-weighting","to","samples",".","Given","a","`","batch","x","m","`","-dim","tensor","of","samples",",","this","should","return","a","`","batch","`","-dim","tensor","."]
code: def __init__(
      self,
      alpha: float,
      n_w: int,
      preprocessing_function: Optional[
          Callable[[Tensor], Tensor]
      ] = None,
  ) -> None:
      r"""Transform the posterior samples to samples of a risk measure.
  
      Args:
          alpha: The risk level, float in `(0.0, 1.0]`.
          n_w: The size of the `w_set` to calculate the risk measure over.
          preprocessing_function: A preprocessing function to apply to the samples
              before computing the risk measure. This can be used to scalarize
              multi-output samples before calculating the risk measure.
              For constrained optimization, this should also apply
              feasibility-weighting to samples. Given a `batch x m`-dim
              tensor of samples, this should return a `batch`-dim tensor.
      """
      super().__init__(
          n_w=n_w, preprocessing_function=preprocessing_function
      )
      if not 0 < alpha <= 1:
          raise ValueError("alpha must be in (0.0, 1.0]")
      self.alpha = alpha
      self.alpha_idx = ceil(n_w * alpha) - 1
  
imports: from abc import ABC, abstractmethod
  from math import ceil
  from typing import Callable, Optional
  import torch
  from botorch.acquisition.multi_objective.objective import IdentityMCMultiOutputObjective
  from botorch.acquisition.objective import IdentityMCObjective, MCAcquisitionObjective
  from torch import Tensor
label_desc: Use image node_id 1 to create a new CVaR object from inherited base classes: RiskMeasureMCObjective with example: obj = CVaR(alpha, n_w, preprocessing_function)