code: def ComputeWithConfidenceIntervals(  # pylint: disable=invalid-name
      sliced_extracts: beam.pvalue.PCollection,
      compute_per_slice_metrics_cls: Type[beam.PTransform],
      num_bootstrap_samples: Optional[
          int
      ] = DEFAULT_NUM_BOOTSTRAP_SAMPLES,
      random_seed_for_testing: Optional[int] = None,
      **kwargs,
  ) -> beam.pvalue.PCollection:
      """PTransform for computing metrics using T-Distribution values.
  
      Args:
        sliced_extracts: Incoming PCollection consisting of slice key and extracts.
        compute_per_slice_metrics_cls: PTransform class that takes a PCollection of
          (slice key, extracts) as input and returns (slice key, dict of metrics) as
          output. The class will be instantiated multiple times to compute metrics
          both with and without sampling. The class will be initialized using kwargs
          'compute_with_sampling' and 'random_seed_for_testing' along with any
          kwargs passed in **kwargs.
        num_bootstrap_samples: Number of replicas to use in calculating uncertainty
          using bootstrapping. If 1 is provided (default), aggregate metrics will be
          calculated with no uncertainty. If num_bootstrap_samples is > 0, multiple
          samples of each slice will be calculated using the Poisson bootstrap
          method. To calculate standard errors, num_bootstrap_samples should be 20
          or more in order to provide useful data. More is better, but you pay a
          performance cost.
        random_seed_for_testing: Seed to use for unit testing, because
          nondeterministic tests stink. Each partition will use this value + i.
        **kwargs: Additional args to pass to compute_per_slice_metrics_cls init.
  
      Returns:
        PCollection of (slice key, dict of metrics)
      """
      if not num_bootstrap_samples:
          num_bootstrap_samples = 1
      # TODO(ckuhn): Cap the number of bootstrap samples at 20.
      if num_bootstrap_samples < 1:
          raise ValueError(
              "num_bootstrap_samples should be > 0, got %d"
              % num_bootstrap_samples
          )
  
      output_results = (
          sliced_extracts
          | "ComputeUnsampledMetrics"
          >> compute_per_slice_metrics_cls(
              compute_with_sampling=False,
              random_seed_for_testing=None,
              **kwargs,
          )
      )
  
      if num_bootstrap_samples > 1:
          multicombine = []
          for i in range(num_bootstrap_samples):
              seed = (
                  None
                  if random_seed_for_testing is None
                  else random_seed_for_testing + i
              )
              multicombine.append(
                  sliced_extracts
                  | "ComputeSampledMetrics%d" % i
                  >> compute_per_slice_metrics_cls(
                      compute_with_sampling=True,
                      random_seed_for_testing=seed,
                      **kwargs,
                  )
              )
          output_results = (
              multicombine
              | "FlattenBootstrapPartitions" >> beam.Flatten()
              | "GroupBySlice" >> beam.GroupByKey()
              | "MergeBootstrap"
              >> beam.ParDo(
                  _MergeBootstrap(), beam.pvalue.AsDict(output_results)
              )
          )
      return output_results
  
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 a global function with example usage: ComputeWithConfidenceIntervals(sliced_extracts, compute_per_slice_metrics_cls, num_bootstrap_samples, random_seed_for_testing) and returns: output_results