class_docstr: The Value-at-Risk risk measure.
  
  Value-at-Risk measures the smallest possible reward (or largest possible loss)
  after excluding the worst outcomes with a total probability of `1 - alpha`. It
  is commonly used in financial risk management, and it corresponds to the
  `1 - alpha` quantile of a given random variable.
class_docstr_tok: ["The","Value-at-Risk","risk","measure",".","Value-at-Risk","measures","the","smallest","possible","reward","(","or","largest","possible","loss",")","after","excluding","the","worst","outcomes","with","a","total","probability","of","`","1","-","alpha","`",".","It","is","commonly","used","in","financial","risk","management",",","and","it","corresponds","to","the","`","1","-","alpha","`","quantile","of","a","given","random","variable","."]
docstr: Calculate the VaR corresponding to the given samples.
  
  Args:
      samples: A `sample_shape x batch_shape x (q * n_w) x m`-dim tensor of
          posterior samples. The q-batches should be ordered so that each
          `n_w` block of samples correspond to the same input.
      X: A `batch_shape x q x d`-dim tensor of inputs. Ignored.
  
  Returns:
      A `sample_shape x batch_shape x q`-dim tensor of VaR samples.
docstr_tok: ["Calculate","the","VaR","corresponding","to","the","given","samples",".","Args",":","samples",":","A","`","sample_shape","x","batch_shape","x","(","q","*","n_w",")","x","m","`","-dim","tensor","of","posterior","samples",".","The","q-batches","should","be","ordered","so","that","each","`","n_w","`","block","of","samples","correspond","to","the","same","input",".","X",":","A","`","batch_shape","x","q","x","d","`","-dim","tensor","of","inputs",".","Ignored",".","Returns",":","A","`","sample_shape","x","batch_shape","x","q","`","-dim","tensor","of","VaR","samples","."]
code: def forward(
      self, samples: Tensor, X: Optional[Tensor] = None
  ) -> Tensor:
      r"""Calculate the VaR corresponding to the given samples.
  
      Args:
          samples: A `sample_shape x batch_shape x (q * n_w) x m`-dim tensor of
              posterior samples. The q-batches should be ordered so that each
              `n_w` block of samples correspond to the same input.
          X: A `batch_shape x q x d`-dim tensor of inputs. Ignored.
  
      Returns:
          A `sample_shape x batch_shape x q`-dim tensor of VaR samples.
      """
      prepared_samples = self._prepare_samples(samples)
      # this is equivalent to sorting along dim=-1 in descending order
      # and taking the values at index self.alpha_idx. E.g.
      # >>> sorted_res = prepared_samples.sort(dim=-1, descending=True)
      # >>> sorted_res.values[..., self.alpha_idx]
      # Using quantile is far more memory efficient since `torch.sort`
      # produces values and indices tensors with shape
      # `sample_shape x batch_shape x (q * n_w) x m`
      return torch.quantile(
          input=prepared_samples,
          q=self._q,
          dim=-1,
          keepdim=False,
          interpolation="lower",
      )
  
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 2 for calling the VaR obj's underlying member method code with example usage: obj.forward(samples, X) and returns: torch