code: def prune_inferior_points(
      model: Model,
      X: Tensor,
      objective: Optional[MCAcquisitionObjective] = None,
      posterior_transform: Optional[PosteriorTransform] = None,
      constraints: Optional[List[Callable[[Tensor], Tensor]]] = None,
      num_samples: int = 2048,
      max_frac: float = 1.0,
      sampler: Optional[MCSampler] = None,
      marginalize_dim: Optional[int] = None,
  ) -> Tensor:
      r"""Prune points from an input tensor that are unlikely to be the best point.
  
      Given a model, an objective, and an input tensor `X`, this function returns
      the subset of points in `X` that have some probability of being the best
      point under the objective. This function uses sampling to estimate the
      probabilities, the higher the number of points `n` in `X` the higher the
      number of samples `num_samples` should be to obtain accurate estimates.
  
      Args:
          model: A fitted model. Batched models are currently not supported.
          X: An input tensor of shape `n x d`. Batched inputs are currently not
              supported.
          objective: The objective under which to evaluate the posterior.
          posterior_transform: A PosteriorTransform (optional).
          constraints: A list of constraint callables which map a Tensor of posterior
              samples of dimension `sample_shape x batch-shape x q x m`-dim to a
              `sample_shape x batch-shape x q`-dim Tensor. The associated constraints
              are satisfied if `constraint(samples) < 0`.
          num_samples: The number of samples used to compute empirical
              probabilities of being the best point.
          max_frac: The maximum fraction of points to retain. Must satisfy
              `0 < max_frac <= 1`. Ensures that the number of elements in the
              returned tensor does not exceed `ceil(max_frac * n)`.
          sampler: If provided, will use this customized sampler instead of
              automatically constructing one with `num_samples`.
          marginalize_dim: A batch dimension that should be marginalized.
              For example, this is useful when using a batched fully Bayesian
              model.
  
      Returns:
          A `n' x d` with subset of points in `X`, where
  
              n' = min(N_nz, ceil(max_frac * n))
  
          with `N_nz` the number of points in `X` that have non-zero (empirical,
          under `num_samples` samples) probability of being the best point.
      """
      if marginalize_dim is None and is_ensemble(model):
          # TODO: Properly deal with marginalizing fully Bayesian models
          marginalize_dim = MCMC_DIM
  
      if X.ndim > 2:
          # TODO: support batched inputs (req. dealing with ragged tensors)
          raise UnsupportedError(
              "Batched inputs `X` are currently unsupported by prune_inferior_points"
          )
      max_points = math.ceil(max_frac * X.size(-2))
      if max_points < 1 or max_points > X.size(-2):
          raise ValueError(
              f"max_frac must take values in (0, 1], is {max_frac}"
          )
      with torch.no_grad():
          posterior = model.posterior(
              X=X, posterior_transform=posterior_transform
          )
      if sampler is None:
          sampler = get_sampler(
              posterior=posterior,
              sample_shape=torch.Size([num_samples]),
          )
      samples = sampler(posterior)
      if objective is None:
          objective = IdentityMCObjective()
      obj_vals = objective(samples, X=X)
      if obj_vals.ndim > 2:
          if obj_vals.ndim == 3 and marginalize_dim is not None:
              if marginalize_dim < 0:
                  # we do this again in compute_feasibility_indicator, but that will
                  # have no effect since marginalize_dim will be non-negative
                  marginalize_dim = (
                      1
                      + normalize_indices(
                          [marginalize_dim], d=obj_vals.ndim
                      )[0]
                  )
              obj_vals = obj_vals.mean(dim=marginalize_dim)
          else:
              # TODO: support batched inputs (req. dealing with ragged tensors)
              raise UnsupportedError(
                  "Models with multiple batch dims are currently unsupported by"
                  " prune_inferior_points."
              )
      infeas = ~compute_feasibility_indicator(
          constraints=constraints,
          samples=samples,
          marginalize_dim=marginalize_dim,
      )
      if infeas.any():
          # set infeasible points to worse than worst objective
          # across all samples
          obj_vals[infeas] = obj_vals.min() - 1
  
      is_best = torch.argmax(obj_vals, dim=-1)
      idcs, counts = torch.unique(is_best, return_counts=True)
  
      if len(idcs) > max_points:
          counts, order_idcs = torch.sort(counts, descending=True)
          idcs = order_idcs[:max_points]
  
      return X[idcs]
  
imports: from __future__ import annotations
  import math
  from typing import Callable, Dict, List, Optional, Tuple
  import torch
  from botorch.acquisition.objective import IdentityMCObjective, MCAcquisitionObjective, PosteriorTransform
  from botorch.exceptions.errors import BotorchTensorDimensionError, DeprecationError, UnsupportedError
  from botorch.models.fully_bayesian import MCMC_DIM
  from botorch.models.model import Model
  from botorch.sampling.base import MCSampler
  from botorch.sampling.get_sampler import get_sampler
  from botorch.sampling.pathwise import draw_matheron_paths
  from botorch.utils.objective import compute_feasibility_indicator
  from botorch.utils.sampling import optimize_posterior_samples
  from botorch.utils.transforms import is_ensemble, normalize_indices
  from torch import Tensor
label_desc: Use image node_id 6 for calling a global function with example usage: prune_inferior_points(model, X, objective, posterior_transform, constraints, num_samples, max_frac, sampler, marginalize_dim) and returns: X