class_docstr: Ensemble posterior, that should be used for ensemble models that compute
  eagerly a finite number of samples per X value as for example a deep ensemble
  or a random forest.
class_docstr_tok: ["Ensemble","posterior",",","that","should","be","used","for","ensemble","models","that","compute","eagerly","a","finite","number","of","samples","per","X","value","as","for","example","a","deep","ensemble","or","a","random","forest","."]
docstr: Sample from the posterior (with gradients) using base samples.
  
  This is intended to be used with a sampler that produces the corresponding base
  samples, and enables acquisition optimization via Sample Average Approximation.
  
  Args:
      sample_shape: A `torch.Size` object specifying the sample shape. To
          draw `n` samples, set to `torch.Size([n])`. To draw `b` batches
          of `n` samples each, set to `torch.Size([b, n])`.
      base_samples: A Tensor of indices as base samples of shape
          `sample_shape`, typically obtained from `IndexSampler`.
          This is used for deterministic optimization. The predictions of
          the ensemble corresponding to the indices are then sampled.
  
  
  Returns:
      Samples from the posterior, a tensor of shape
      `self._extended_shape(sample_shape=sample_shape)`.
docstr_tok: ["Sample","from","the","posterior","(","with","gradients",")","using","base","samples",".","This","is","intended","to","be","used","with","a","sampler","that","produces","the","corresponding","base","samples",",","and","enables","acquisition","optimization","via","Sample","Average","Approximation",".","Args",":","sample_shape",":","A","`","torch.Size","`","object","specifying","the","sample","shape",".","To","draw","`","n","`","samples",",","set","to","`","torch.Size","(","[","n","]",")","`",".","To","draw","`","b","`","batches","of","`","n","`","samples","each",",","set","to","`","torch.Size","(","[","b",",","n","]",")","`",".","base_samples",":","A","Tensor","of","indices","as","base","samples","of","shape","`","sample_shape","`",",","typically","obtained","from","`","IndexSampler","`",".","This","is","used","for","deterministic","optimization",".","The","predictions","of","the","ensemble","corresponding","to","the","indices","are","then","sampled",".","Returns",":","Samples","from","the","posterior",",","a","tensor","of","shape","`","self._extended_shape","(","sample_shape=sample_shape",")","`","."]
code: def rsample_from_base_samples(
      self, sample_shape: torch.Size, base_samples: Tensor
  ) -> Tensor:
      r"""Sample from the posterior (with gradients) using base samples.
  
      This is intended to be used with a sampler that produces the corresponding base
      samples, and enables acquisition optimization via Sample Average Approximation.
  
      Args:
          sample_shape: A `torch.Size` object specifying the sample shape. To
              draw `n` samples, set to `torch.Size([n])`. To draw `b` batches
              of `n` samples each, set to `torch.Size([b, n])`.
          base_samples: A Tensor of indices as base samples of shape
              `sample_shape`, typically obtained from `IndexSampler`.
              This is used for deterministic optimization. The predictions of
              the ensemble corresponding to the indices are then sampled.
  
  
      Returns:
          Samples from the posterior, a tensor of shape
          `self._extended_shape(sample_shape=sample_shape)`.
      """
      if base_samples.shape != sample_shape:
          raise ValueError("Base samples do not match sample shape.")
      # move sample axis to front
      values = self.values.movedim(-3, 0)
      # sample from the first dimension of values
      return values[base_samples, ...]
  
file_path: botorch/botorch/posteriors/ensemble.py
imports: from __future__ import annotations
  from typing import Optional
  import torch
  from botorch.posteriors.posterior import Posterior
  from torch import Tensor
label_desc: Use image node_id 10 for calling the EnsemblePosterior obj's underlying member method code with example usage: obj.rsample_from_base_samples(sample_shape, base_samples) and returns: values