code: def best_in_sample_point(
      Xs: Union[List[torch.Tensor], List[np.ndarray]],
      model: TorchModelLike,
      bounds: List[Tuple[float, float]],
      objective_weights: Optional[Tensoray],
      outcome_constraints: Optional[Tuple[Tensoray, Tensoray]] = None,
      linear_constraints: Optional[Tuple[Tensoray, Tensoray]] = None,
      fixed_features: Optional[Dict[int, float]] = None,
      risk_measure: Optional[RiskMeasureMCObjective] = None,
      options: Optional[TConfig] = None,
  ) -> Optional[Tuple[Tensoray, float]]:
      """Select the best point that has been observed.
  
      Implements two approaches to selecting the best point.
  
      For both approaches, only points that satisfy parameter space constraints
      (bounds, linear_constraints, fixed_features) will be returned. Points must
      also be observed for all objective and constraint outcomes. Returned
      points may violate outcome constraints, depending on the method below.
  
      1: Select the point that maximizes the expected utility
      (objective_weights^T posterior_objective_means - baseline) * Prob(feasible)
      Here baseline should be selected so that at least one point has positive
      utility. It can be specified in the options dict, otherwise
      min (objective_weights^T posterior_objective_means)
      will be used, where the min is over observed points.
  
      2: Select the best-objective point that is feasible with at least
      probability p.
  
      The following quantities may be specified in the options dict:
  
      - best_point_method: 'max_utility' (default) or 'feasible_threshold'
        to select between the two approaches described above.
      - utility_baseline: Value for the baseline used in max_utility approach. If
        not provided, defaults to min objective value.
      - probability_threshold: Threshold for the feasible_threshold approach.
        Defaults to p=0.95.
      - feasibility_mc_samples: Number of MC samples used for estimating the
        probability of feasibility (defaults 10k).
  
      Args:
          Xs: Training data for the points, among which to select the best.
          model: A Torch model or Surrogate.
          bounds: A list of (lower, upper) tuples for each feature.
          objective_weights: The objective is to maximize a weighted sum of
              the columns of f(x). These are the weights.
          outcome_constraints: A tuple of (A, b). For k outcome constraints
              and m outputs at f(x), A is (k x m) and b is (k x 1) such that
              A f(x) <= b.
          linear_constraints: A tuple of (A, b). For k linear constraints on
              d-dimensional x, A is (k x d) and b is (k x 1) such that
              A x <= b.
          fixed_features: A map {feature_index: value} for features that
              should be fixed to a particular value in the best point.
          risk_measure: An optional risk measure for reporting best robust point.
          options: A config dictionary with settings described above.
  
      Returns:
          A two-element tuple or None if no feasible point exist. In tuple:
          - d-array of the best point,
          - utility at the best point.
      """
      if risk_measure is not None:
          # TODO[T131759268]: We need to apply the risk measure. Instead of doing obj_w @,
          # we could use `get_botorch_objective_and_transform` to get the objective
          # then apply it, though we also need to decide how to deal with constraints.
          raise NotImplementedError
      # Parse options
      if options is None:
          options = {}
      method: str = options.get("best_point_method", "max_utility")
      B: Optional[float] = options.get("utility_baseline", None)
      threshold: float = options.get("probability_threshold", 0.95)
      nsamp: int = options.get("feasibility_mc_samples", 10000)
      # Get points observed for all objective and constraint outcomes
      if objective_weights is None:
          return None
      objective_weights_np = checked_cast(
          np.ndarray, as_array(objective_weights)
      )
      X_obs = get_observed(
          Xs=Xs,
          objective_weights=objective_weights,
          outcome_constraints=outcome_constraints,
      )
      # Filter to those that satisfy constraints.
      X_obs = filter_constraints_and_fixed_features(
          X=X_obs,
          bounds=bounds,
          linear_constraints=linear_constraints,
          fixed_features=fixed_features,
      )
      if len(X_obs) == 0:
          # No feasible points
          return None
      # Predict objective and P(feas) at these points for Torch models.
      if isinstance(Xs[0], torch.Tensor):
          X_obs = X_obs.detach().clone()
      f, cov = as_array(model.predict(X_obs))
      obj = objective_weights_np @ f.transpose()
      pfeas = np.ones_like(obj)
      if outcome_constraints is not None:
          A, b = as_array(outcome_constraints)  # (m x j) and (m x 1)
          # Use Monte Carlo to compute pfeas, to properly handle covariance
          # across outcomes.
          for i, _ in enumerate(X_obs):
              z = np.random.multivariate_normal(
                  mean=f[i, :], cov=cov[i, :, :], size=nsamp
              )  # (nsamp x j)
              pfeas[i] = (A @ z.transpose() <= b).all(axis=0).mean()
      # Identify best point
      if method == "feasible_threshold":
          utility = obj
          utility[pfeas < threshold] = -np.Inf
      elif method == "max_utility":
          if B is None:
              B = obj.min()
          utility = (obj - B) * pfeas
      else:  # pragma: no cover
          raise UnsupportedError(f"Unknown best point method {method}.")
      i = np.argmax(utility)
      if utility[i] == -np.Inf:
          return None
      else:
          return X_obs[i, :], utility[i]
  
imports: from __future__ import annotations
  import itertools
  import warnings
  from typing import Callable, Dict, List, Optional, Protocol, Set, Tuple, Union
  import numpy
  import torch
  from ax.core.search_space import SearchSpaceDigest
  from ax.exceptions.core import SearchSpaceExhausted, UnsupportedError
  from ax.models.types import TConfig
  from ax.utils.common.typeutils import checked_cast
  from botorch.acquisition.risk_measures import RiskMeasureMCObjective
  from torch import Tensor
label_desc: Use image node_id 8 for calling a global function with example usage: best_in_sample_point(Xs, model, bounds, objective_weights, outcome_constraints, linear_constraints, fixed_features, risk_measure, options) and returns: None, None, None, X_obs,  utility