code: def _get_in_sample_arms(
      model: ModelBridge,
      metric_names: Set[str],
      fixed_features: Optional[ObservationFeatures] = None,
      data_selector: Optional[Callable[[Observation], bool]] = None,
      scalarized_metric_config: Optional[
          List[Dict[str, Dict[str, float]]]
      ] = None,
  ) -> Tuple[
      Dict[str, PlotInSampleArm], RawData, Dict[str, TParameterization]
  ]:
      """Get in-sample arms from a model with observed and predicted values
      for specified metrics.
  
      Returns a PlotInSampleArm object in which repeated observations are merged
      with IVW, and a RawData object in which every observation is listed.
  
      Fixed features input can be used to override fields of the insample arms
      when making model predictions.
  
      Args:
          model: An instance of the model bridge.
          metric_names: Restrict predictions to these metrics. If None, uses all
              metrics in the model.
          fixed_features: Features that should be fixed in the arms this function
              will obtain predictions for.
          data_selector: Function for selecting observations for plotting.
  
      Returns:
          A tuple containing
  
          - Map from arm name to PlotInSampleArm.
          - List of the data for each observation like::
  
              {'metric_name': 'likes', 'arm_name': '0_0', 'mean': 1., 'sem': 0.1}
  
          - Map from arm name to parameters
      """
      observations = model.get_training_data()
      training_in_design = model.training_in_design
      if data_selector is not None:
          observations = [
              obs for obs in observations if data_selector(obs)
          ]
          training_in_design = [
              model.training_in_design[i]
              for i, obs in enumerate(observations)
              if data_selector(obs)
          ]
      trial_selector = None
      if fixed_features is not None:
          trial_selector = fixed_features.trial_index
      # Calculate raw data
      raw_data = []
      arm_name_to_parameters = {}
      for obs in observations:
          arm_name_to_parameters[obs.arm_name] = obs.features.parameters
          for j, metric_name in enumerate(obs.data.metric_names):
              if metric_name in metric_names:
                  raw_data.append(
                      {
                          "metric_name": metric_name,
                          "arm_name": obs.arm_name,
                          "mean": obs.data.means[j],
                          "sem": np.sqrt(obs.data.covariance[j, j]),
                      }
                  )
  
      # Check that we have one ObservationFeatures per arm name since we
      # key by arm name and the model is not Multi-task.
      # If "TrialAsTask" is present, one of the arms is chosen based on the selected
      # trial index in the fixed_features.
      if (
          "TrialAsTask" not in model.transforms.keys()
          or trial_selector is None
      ) and (len(arm_name_to_parameters) != len(observations)):
          logger.error(
              "Have observations of arms with different features but same"
              " name. Arbitrary one will be plotted."
          )
  
      # Merge multiple measurements within each Observation with IVW to get
      # un-modeled prediction
      t = IVW(None, [])
      observations = t.transform_observations(observations)
      # Start filling in plot data
      in_sample_plot: Dict[str, PlotInSampleArm] = {}
      for i, obs in enumerate(observations):
          if obs.arm_name is None:
              raise ValueError(
                  "Observation must have arm name for plotting."
              )
  
          # Extract raw measurement
          obs_y = {}  # Observed metric means.
          obs_se = {}  # Observed metric standard errors.
          for j, metric_name in enumerate(obs.data.metric_names):
              if metric_name in metric_names:
                  obs_y[metric_name] = obs.data.means[j]
                  obs_se[metric_name] = np.sqrt(
                      obs.data.covariance[j, j]
                  )
          # Obtain aggregated outcomes if scalarized_metric_config is provided
          if scalarized_metric_config is not None:
              for agg_metric in scalarized_metric_config:
                  agg_metric_name = agg_metric["name"]
                  if agg_metric_name in metric_names:
                      agg_mean, agg_var = _compute_scalarized_outcome(
                          mean_dict=obs.data.means_dict,
                          cov_dict=obs.data.covariance_matrix,
                          agg_metric_weight_dict=agg_metric["weight"],
                      )
                      obs_y[agg_metric_name] = agg_mean
                      obs_se[agg_metric_name] = np.sqrt(agg_var)
          if training_in_design[i]:
              # Update with the input fixed features
              features = obs.features
              if fixed_features is not None:
                  features.update_features(fixed_features)
              # Make a prediction.
              pred_y, pred_se = predict_at_point(
                  model,
                  features,
                  metric_names,
                  scalarized_metric_config,
              )
          elif (trial_selector is not None) and (
              obs.features.trial_index != trial_selector
          ):
              # check whether the observation is from the right trial
              # need to use raw data in the selected trial for out-of-design points
              continue
          else:
              pred_y = obs_y
              pred_se = obs_se
          in_sample_plot[not_none(obs.arm_name)] = PlotInSampleArm(
              name=not_none(obs.arm_name),
              y=obs_y,
              se=obs_se,
              parameters=obs.features.parameters,
              y_hat=pred_y,
              se_hat=pred_se,
              context_stratum=None,
          )
      return in_sample_plot, raw_data, arm_name_to_parameters
  
imports: import math
  from collections import Counter
  from logging import Logger
  from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Union
  import numpy
  from ax.core.generator_run import GeneratorRun
  from ax.core.observation import Observation, ObservationFeatures
  from ax.core.parameter import ChoiceParameter, FixedParameter, Parameter, ParameterType, RangeParameter
  from ax.core.types import TParameterization
  from ax.modelbridge.base import ModelBridge
  from ax.modelbridge.prediction_utils import _compute_scalarized_outcome, predict_at_point
  from ax.modelbridge.transforms.ivw import IVW
  from ax.plot.base import DECIMALS, PlotData, PlotInSampleArm, PlotOutOfSampleArm, Z
  from ax.utils.common.logger import get_logger
  from ax.utils.common.typeutils import not_none
label_desc: Use image node_id 9 for calling a global function with example usage: _get_in_sample_arms(model, metric_names, fixed_features, data_selector, scalarized_metric_config) and returns: in_sample_plot,  raw_data,  arm_name_to_parameters