code: def test_ei_calc_via_monte_carlo(self):
      for maximize in [True, False]:
          train_X = torch.rand(10, 1, device=self.device)
          posterior = self.previous_model.posterior(train_X)
          mean = posterior.mean.squeeze(-2).squeeze(-1)
          sigma = posterior.variance.sqrt().view(mean.shape)
          normal = torch.distributions.Normal(mean, sigma)
          samples = normal.sample([1_000_000])
          if maximize:
              baseline = torch.min(mean)
              ei = torch.clamp(samples - baseline, min=0.0).mean(axis=0)
          else:
              baseline = torch.max(mean)
              ei = torch.clamp(baseline - samples, min=0.0).mean(axis=0)
  
          quality_function = ExpectedImprovementQualityFunction(
              self.previous_model, maximize
          )
  
          self.assertAllClose(
              ei, quality_function(train_X), atol=0.01, rtol=0.01
          )
  
imports: import gc
  import torch
  from botorch.exceptions.errors import UnsupportedError
  from botorch.models.approximate_gp import SingleTaskVariationalGP
  from botorch.models.utils.inducing_point_allocators import _pivoted_cholesky_init, ExpectedImprovementQualityFunction, GreedyImprovementReduction, GreedyVarianceReduction, UnitQualityFunction
  from botorch.utils.testing import BotorchTestCase
  from gpytorch.kernels import MaternKernel, ScaleKernel
  from gpytorch.likelihoods import GaussianLikelihood
  from gpytorch.mlls import VariationalELBO
label_desc: Use image node_id 5 for calling the TestExpectedImprovementQualityFunction obj's underlying member method code with example usage: obj.test_ei_calc_via_monte_carlo() without return types