class_docstr: Merge the bootstrap values and fit a T-distribution to get confidence.
docstr: Merge the bootstrap values.
  
  Args:
    element: The element is the tuple that contains slice key and a list of
      the metrics dict. It's the output of the GroupByKey step. All the
      metrics that under the same slice key are generated by
      poisson-bootstrap.
    unsampled_results: The unsampled_results is passed in as a side input.
      It's a tuple that contains the slice key and the metrics dict from a run
      of the slice with no sampling (ie, all examples in the set are
      represented exactly once.) This should be identical to the values
      obtained without sampling.
  
  Yields:
    A tuple of slice key and the metrics dict which contains the unsampled
    value, as well as parameters about t distribution. If the metric is a
    proto only the unsampled value will be returned.
  
  Raises:
    ValueError if the key of metrics inside element does not equal to the
    key of metrics in unsampled_results.
docstr_tok: ["Merge","the","bootstrap","values",".","Args",":","element",":","The","element","is","the","tuple","that","contains","slice","key","and","a","list","of","the","metrics","dict",".","It","'s","the","output","of","the","GroupByKey","step",".","All","the","metrics","that","under","the","same","slice","key","are","generated","by","poisson-bootstrap",".","unsampled_results",":","The","unsampled_results","is","passed","in","as","a","side","input",".","It","'s","a","tuple","that","contains","the","slice","key","and","the","metrics","dict","from","a","run","of","the","slice","with","no","sampling","(","ie",",","all","examples","in","the","set","are","represented","exactly","once",".",")","This","should","be","identical","to","the","values","obtained","without","sampling",".","Yields",":","A","tuple","of","slice","key","and","the","metrics","dict","which","contains","the","unsampled","value",",","as","well","as","parameters","about","t","distribution",".","If","the","metric","is","a","proto","only","the","unsampled","value","will","be","returned",".","Raises",":","ValueError","if","the","key","of","metrics","inside","element","does","not","equal","to","the","key","of","metrics","in","unsampled_results","."]
code: def process(
      self,
      element: Tuple[slicer.SliceKeyType, Iterable[_MetricsDict]],
      unsampled_results: Dict[slicer.SliceKeyType, _MetricsDict],
  ) -> Iterator[Tuple[slicer.SliceKeyType, _MetricsDict]]:
      """Merge the bootstrap values.
  
      Args:
        element: The element is the tuple that contains slice key and a list of
          the metrics dict. It's the output of the GroupByKey step. All the
          metrics that under the same slice key are generated by
          poisson-bootstrap.
        unsampled_results: The unsampled_results is passed in as a side input.
          It's a tuple that contains the slice key and the metrics dict from a run
          of the slice with no sampling (ie, all examples in the set are
          represented exactly once.) This should be identical to the values
          obtained without sampling.
  
      Yields:
        A tuple of slice key and the metrics dict which contains the unsampled
        value, as well as parameters about t distribution. If the metric is a
        proto only the unsampled value will be returned.
  
      Raises:
        ValueError if the key of metrics inside element does not equal to the
        key of metrics in unsampled_results.
      """
      slice_key, metrics = element
      # metrics should be a list of dicts, but the dataflow runner has a quirk
      # that requires specific casting.
      metrics = list(metrics)
      if len(metrics) == 1:
          yield slice_key, metrics[0]
          return
  
      # Group the same metrics into one list.
      metrics_dict = {}
      for metric in metrics:
          for metrics_name in metric:
              if metrics_name not in metrics_dict:
                  metrics_dict[metrics_name] = []
              metrics_dict[metrics_name].append(metric[metrics_name])
  
      unsampled_metrics_dict = unsampled_results.get(slice_key, {})
  
      # The key set of the two metrics dicts must be identical.
      if set(metrics_dict.keys()) != set(unsampled_metrics_dict.keys()):
          raise ValueError(
              "Keys of two metrics do not match: sampled_metrics: %s. "
              "unsampled_metrics: %s"
              % (metrics_dict.keys(), unsampled_metrics_dict.keys())
          )
  
      metrics_with_confidence = {}
      for metrics_name in metrics_dict:
          # If metric is a proto, return as is.
          unsampled_value = unsampled_metrics_dict[metrics_name]
          if isinstance(unsampled_value, message.Message):
              metrics_with_confidence[metrics_name] = unsampled_value
          else:
              metrics_with_confidence[
                  metrics_name
              ] = _calculate_t_distribution(
                  metrics_dict[metrics_name], unsampled_value
              )
  
      yield slice_key, metrics_with_confidence
  
file_path: model-analysis/tensorflow_model_analysis/evaluators/legacy_poisson_bootstrap.py
imports: from typing import Any, Dict, Iterable, Iterator, List, Optional, Tuple, Type, Union
  import apache_beam
  import numpy
  from tensorflow_model_analysis.api import types
  from tensorflow_model_analysis.slicer import slicer_lib
  from google.protobuf import message
label_desc: Use image node_id 1 for calling the _MergeBootstrap obj's underlying member method code with example usage: obj.process(element, unsampled_results) without return types