class_docstr: Linear Elliptical Slice Sampler.
  
  Ideas:
  - Add batch support, broadcasting over parallel chains.
  - Optimize computations if possible, potentially with torch.compile.
  - Extend fixed features constraint to general linear equality constraints.
class_docstr_tok: ["Linear","Elliptical","Slice","Sampler",".","Ideas",":","-","Add","batch","support",",","broadcasting","over","parallel","chains",".","-","Optimize","computations","if","possible",",","potentially","with","torch.compile",".","-","Extend","fixed","features","constraint","to","general","linear","equality","constraints","."]
docstr: Initialize LinearEllipticalSliceSampler.
  
  Args:
      inequality_constraints: Tensors `(A, b)` describing inequality constraints
           `A @ x <= b`, where `A` is an `n_ineq_con x d`-dim Tensor and `b` is
           an `n_ineq_con x 1`-dim Tensor, with `n_ineq_con` the number of
           inequalities and `d` the dimension of the sample space. If omitted,
           must provide `bounds` instead.
      bounds: A `2 x d`-dim tensor of box bounds. If omitted, must provide
          `inequality_constraints` instead.
      interior_point: A `d x 1`-dim Tensor presenting a point in the (relative)
          interior of the polytope. If omitted, an interior point is determined
          automatically by solving a Linear Program. Note: It is crucial that
          the point lie in the interior of the feasible set (rather than on the
          boundary), otherwise the sampler will produce invalid samples.
      fixed_indices: Integer list or `d`-dim Tensor representing the indices of
          dimensions that are constrained to be fixed to the values specified in
          the `interior_point`, which is required to be passed in conjunction with
          `fixed_indices`.
      mean: The `d x 1`-dim mean of the MVN distribution (if omitted, use zero).
      covariance_matrix: The `d x d`-dim covariance matrix of the MVN
          distribution (if omitted, use the identity).
      covariance_root: A `d x d`-dim root of the covariance matrix such that
          covariance_root @ covariance_root.T = covariance_matrix. NOTE: This
          matrix is assumed to be lower triangular.
      check_feasibility: If True, raise an error if the sampling results in an
          infeasible sample. This creates some overhead and so is switched off
          by default.
      burnin: Number of samples to generate upon initialization to warm up the
          sampler.
      thinning: Number of samples to skip before returning a sample in `draw`.
  
  This sampler samples from a multivariante Normal `N(mean, covariance_matrix)`
  subject to linear domain constraints `A x <= b` (intersected with box bounds,
  if provided).
docstr_tok: ["Initialize","LinearEllipticalSliceSampler",".","Args",":","inequality_constraints",":","Tensors","`","(","A",",","b",")","`","describing","inequality","constraints","`","A","@","x","<","=","b","`",",","where","`","A","`","is","an","`","n_ineq_con","x","d","`","-dim","Tensor","and","`","b","`","is","an","`","n_ineq_con","x","1","`","-dim","Tensor",",","with","`","n_ineq_con","`","the","number","of","inequalities","and","`","d","`","the","dimension","of","the","sample","space",".","If","omitted",",","must","provide","`","bounds","`","instead",".","bounds",":","A","`","2","x","d","`","-dim","tensor","of","box","bounds",".","If","omitted",",","must","provide","`","inequality_constraints","`","instead",".","interior_point",":","A","`","d","x","1","`","-dim","Tensor","presenting","a","point","in","the","(","relative",")","interior","of","the","polytope",".","If","omitted",",","an","interior","point","is","determined","automatically","by","solving","a","Linear","Program",".","Note",":","It","is","crucial","that","the","point","lie","in","the","interior","of","the","feasible","set","(","rather","than","on","the","boundary",")",",","otherwise","the","sampler","will","produce","invalid","samples",".","fixed_indices",":","Integer","list","or","`","d","`","-dim","Tensor","representing","the","indices","of","dimensions","that","are","constrained","to","be","fixed","to","the","values","specified","in","the","`","interior_point","`",",","which","is","required","to","be","passed","in","conjunction","with","`","fixed_indices","`",".","mean",":","The","`","d","x","1","`","-dim","mean","of","the","MVN","distribution","(","if","omitted",",","use","zero",")",".","covariance_matrix",":","The","`","d","x","d","`","-dim","covariance","matrix","of","the","MVN","distribution","(","if","omitted",",","use","the","identity",")",".","covariance_root",":","A","`","d","x","d","`","-dim","root","of","the","covariance","matrix","such","that","covariance_root","@","covariance_root.T","=","covariance_matrix",".","NOTE",":","This","matrix","is","assumed","to","be","lower","triangular",".","check_feasibility",":","If","True",",","raise","an","error","if","the","sampling","results","in","an","infeasible","sample",".","This","creates","some","overhead","and","so","is","switched","off","by","default",".","burnin",":","Number","of","samples","to","generate","upon","initialization","to","warm","up","the","sampler",".","thinning",":","Number","of","samples","to","skip","before","returning","a","sample","in","`","draw","`",".","This","sampler","samples","from","a","multivariante","Normal","`","N","(","mean",",","covariance_matrix",")","`","subject","to","linear","domain","constraints","`","A","x","<","=","b","`","(","intersected","with","box","bounds",",","if","provided",")","."]
code: def __init__(
      self,
      inequality_constraints: Optional[Tuple[Tensor, Tensor]] = None,
      bounds: Optional[Tensor] = None,
      interior_point: Optional[Tensor] = None,
      fixed_indices: Optional[Union[List[int], Tensor]] = None,
      mean: Optional[Tensor] = None,
      covariance_matrix: Optional[Tensor] = None,
      covariance_root: Optional[Tensor] = None,
      check_feasibility: bool = False,
      burnin: int = 0,
      thinning: int = 0,
  ) -> None:
      r"""Initialize LinearEllipticalSliceSampler.
  
      Args:
          inequality_constraints: Tensors `(A, b)` describing inequality constraints
               `A @ x <= b`, where `A` is an `n_ineq_con x d`-dim Tensor and `b` is
               an `n_ineq_con x 1`-dim Tensor, with `n_ineq_con` the number of
               inequalities and `d` the dimension of the sample space. If omitted,
               must provide `bounds` instead.
          bounds: A `2 x d`-dim tensor of box bounds. If omitted, must provide
              `inequality_constraints` instead.
          interior_point: A `d x 1`-dim Tensor presenting a point in the (relative)
              interior of the polytope. If omitted, an interior point is determined
              automatically by solving a Linear Program. Note: It is crucial that
              the point lie in the interior of the feasible set (rather than on the
              boundary), otherwise the sampler will produce invalid samples.
          fixed_indices: Integer list or `d`-dim Tensor representing the indices of
              dimensions that are constrained to be fixed to the values specified in
              the `interior_point`, which is required to be passed in conjunction with
              `fixed_indices`.
          mean: The `d x 1`-dim mean of the MVN distribution (if omitted, use zero).
          covariance_matrix: The `d x d`-dim covariance matrix of the MVN
              distribution (if omitted, use the identity).
          covariance_root: A `d x d`-dim root of the covariance matrix such that
              covariance_root @ covariance_root.T = covariance_matrix. NOTE: This
              matrix is assumed to be lower triangular.
          check_feasibility: If True, raise an error if the sampling results in an
              infeasible sample. This creates some overhead and so is switched off
              by default.
          burnin: Number of samples to generate upon initialization to warm up the
              sampler.
          thinning: Number of samples to skip before returning a sample in `draw`.
  
      This sampler samples from a multivariante Normal `N(mean, covariance_matrix)`
      subject to linear domain constraints `A x <= b` (intersected with box bounds,
      if provided).
      """
      super().__init__(
          inequality_constraints=inequality_constraints,
          # TODO: Support equality constraints?
          interior_point=interior_point,
          bounds=bounds,
      )
      tkwargs = {"device": self.x0.device, "dtype": self.x0.dtype}
      if covariance_matrix is not None and covariance_root is not None:
          raise ValueError(
              "Provide either covariance_matrix or covariance_root, not both."
          )
  
      # can't unpack inequality constraints directly if bounds are passed
      A, b = self.A, self.b
      self._Az, self._bz = A, b
      self._is_fixed, self._not_fixed = None, None
      if fixed_indices is not None:
          mean, covariance_matrix = self._fixed_features_initialization(
              A=A,
              b=b,
              interior_point=interior_point,
              fixed_indices=fixed_indices,
              mean=mean,
              covariance_matrix=covariance_matrix,
              covariance_root=covariance_root,
          )
  
      self._mean = mean
      # Have to delay factorization until after fixed features initialization.
      if covariance_matrix is not None:  # implies root is None
          covariance_root, info = torch.linalg.cholesky_ex(
              covariance_matrix
          )
          not_psd = torch.any(info)
          if not_psd:
              raise ValueError(
                  "Covariance matrix is not positive definite. "
                  "Currently only non-degenerate distributions are supported."
              )
      self._covariance_root = covariance_root
  
      # Rewrite the constraints as a system that constrains a standard Normal.
      self._standardization_initialization()
  
      # state of the sampler ("current point")
      self._x = self.x0.clone()
      self._z = self._transform(self._x)
  
      # We will need the following repeatedly, let's allocate them once
      self._zero = torch.zeros(1, **tkwargs)
      self._nan = torch.tensor(float("nan"), **tkwargs)
      self._full_angular_range = torch.tensor([0.0, _twopi], **tkwargs)
      self.check_feasibility = check_feasibility
      self._lifetime_samples = 0
      if burnin > 0:
          self.thinning = 0
          self.draw(burnin)
      self.thinning = thinning
  
imports: from __future__ import annotations
  import math
  from typing import List, Optional, Tuple, Union
  import torch
  from botorch.utils.sampling import PolytopeSampler
  from torch import Tensor
label_desc: Use image node_id 1 to create a new LinearEllipticalSliceSampler object from inherited base classes: PolytopeSampler with example: obj = LinearEllipticalSliceSampler(inequality_constraints, bounds, interior_point, fixed_indices, mean, covariance_matrix, covariance_root, check_feasibility, burnin, thinning)