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).
  
  Based on the sample shape, base samples are generated and passed to
  `rsample_from_base_samples`.
  
  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])`.
  
  Returns:
      Samples from the posterior, a tensor of shape
      `self._extended_shape(sample_shape=sample_shape)`.
docstr_tok: ["Sample","from","the","posterior","(","with","gradients",")",".","Based","on","the","sample","shape",",","base","samples","are","generated","and","passed","to","`","rsample_from_base_samples","`",".","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","]",")","`",".","Returns",":","Samples","from","the","posterior",",","a","tensor","of","shape","`","self._extended_shape","(","sample_shape=sample_shape",")","`","."]
code: def rsample(
      self,
      sample_shape: Optional[torch.Size] = None,
  ) -> Tensor:
      r"""Sample from the posterior (with gradients).
  
      Based on the sample shape, base samples are generated and passed to
      `rsample_from_base_samples`.
  
      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])`.
  
      Returns:
          Samples from the posterior, a tensor of shape
          `self._extended_shape(sample_shape=sample_shape)`.
      """
      if sample_shape is None:
          sample_shape = torch.Size([1])
      # get indices as base_samples
      base_samples = (
          torch.multinomial(
              self.weights,
              num_samples=sample_shape.numel(),
              replacement=True,
          )
          .reshape(sample_shape)
          .to(device=self.device)
      )
      return self.rsample_from_base_samples(
          sample_shape=sample_shape, base_samples=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 9 for calling the EnsemblePosterior obj's underlying member method code with example usage: obj.rsample(sample_shape) and returns: self