code: def test_EnsemblePosterior(self):
      for shape, dtype in itertools.product(
          ((16, 5, 2), (2, 16, 5, 2)), (torch.float, torch.double)
      ):
          values = torch.randn(*shape, device=self.device, dtype=dtype)
          p = EnsemblePosterior(values)
          self.assertEqual(p.device.type, self.device.type)
          self.assertEqual(p.dtype, dtype)
          self.assertEqual(p.ensemble_size, 16)
          self.assertAllClose(
              p.weights,
              torch.tensor([1.0 / p.ensemble_size] * p.ensemble_size),
          )
          # test mean and variance
          self.assertTrue(torch.equal(p.mean, values.mean(dim=-3)))
          self.assertTrue(torch.equal(p.variance, values.var(dim=-3)))
          # test extended shape
          self.assertEqual(
              p._extended_shape(torch.Size((128,))),
              torch.Size((128, 5, 2))
              if len(shape) == 3
              else torch.Size((128, 2, 5, 2)),
          )
          # test rsample
          samples = p.rsample(torch.Size((1024,)))
          self.assertEqual(
              samples.shape, p._extended_shape(torch.Size((1024,)))
          )
          # test rsample from base samples
          # test that produced samples are correct
          samples = p.rsample_from_base_samples(
              sample_shape=torch.Size((16,)),
              base_samples=torch.arange(16),
          )
          self.assertEqual(
              samples.shape, p._extended_shape(torch.Size((16,)))
          )
          self.assertAllClose(p.mean, samples.mean(dim=0))
          self.assertAllClose(p.variance, samples.var(dim=0))
          # test error on base_samples, sample_shape mismatch
          with self.assertRaises(ValueError):
              p.rsample_from_base_samples(
                  sample_shape=torch.Size((17,)),
                  base_samples=torch.arange(16),
              )
  
file_path: botorch/test/posteriors/test_ensemble.py
imports: import itertools
  import torch
  from botorch.posteriors.ensemble import EnsemblePosterior
  from botorch.utils.testing import BotorchTestCase
label_desc: Use image node_id 3 for calling the TestEnsemblePosterior obj's underlying member method code with example usage: obj.test_EnsemblePosterior() without return types