code: def output_average(
      metric_name: str,
      output_weights: Dict[str, float],
      eval_config: Optional[config_pb2.EvalConfig] = None,
      model_name: str = "",
      sub_key: Optional[metric_types.SubKey] = None,
      example_weighted: bool = False,
  ) -> metric_types.MetricComputations:
      """Returns metric computations for computing output average of given metric.
  
      Args:
        metric_name: Name of underlying metric average is being computed for.
        output_weights: Output weights to use to compute metric.
        eval_config: Eval config.
        model_name: Optional model name.
        sub_key: Optional sub key associated with metric (e.g. top_k).
        example_weighted: True if example weights should be applied.
  
      Returns:
        Computation for performing the output average.
      """
      del eval_config
  
      key = metric_types.MetricKey(
          name=metric_name,
          model_name=model_name,
          sub_key=sub_key,
          example_weighted=example_weighted,
      )
  
      def result(
          metrics: Dict[metric_types.MetricKey, float]
      ) -> Dict[metric_types.MetricKey, float]:
          """Returns output average."""
          total_value = 0.0
          total_weight = 0.0
          for output_name, output_weight in output_weights.items():
              child_key = metric_types.MetricKey(
                  name=metric_name,
                  model_name=model_name,
                  output_name=output_name,
                  sub_key=sub_key,
                  example_weighted=example_weighted,
              )
              total_value += (
                  _to_float(metrics[child_key]) * output_weight
              )
              total_weight += output_weight
          average = (
              total_value / total_weight
              if total_weight
              else float("nan")
          )
          return {key: average}
  
      return [
          metric_types.DerivedMetricComputation(
              keys=[key], result=result
          )
      ]
  
file_path: model-analysis/tensorflow_model_analysis/metrics/aggregation.py
imports: from typing import Any, Dict, Iterable, List, Optional
  import apache_beam
  from tensorflow_model_analysis.metrics import metric_types
  from tensorflow_model_analysis.metrics import metric_util
  from tensorflow_model_analysis.proto import config_pb2
label_desc: Use image node_id 1 for calling a global function with example usage: output_average(metric_name, output_weights, eval_config, model_name, sub_key, example_weighted) and returns: list, dict