code: def testFlipCountWitEvalConfig(self):
      eval_config = text_format.Parse(
          """
          model_specs: {
            name: "original"
          }
          model_specs: {
            name: "counterfactual"
            is_baseline: true
          }
          """,
          config_pb2.EvalConfig(),
      )
      computations = flip_count.FlipCount(
          thresholds=[0.3], example_id_key="example_id_key"
      ).computations(
          eval_config=eval_config,
          example_weighted=True,
          model_names=["original", "counterfactual"],
          output_names=[""],
      )
      binary_confusion_matrix = computations[0]
      matrices = computations[1]
      metrics = computations[2]
      original_model_name = "original"
      counterfactual_model_name = "counterfactual"
      examples = [
          {
              "labels": None,
              "predictions": {
                  original_model_name: np.array([0.5]),
                  counterfactual_model_name: np.array([0.7]),
              },
              "example_weights": np.array([1.0]),
              "features": {
                  "example_id_key": np.array(["id_1"]),
              },
          },
          {
              "labels": None,
              "predictions": {
                  original_model_name: np.array(
                      [0.1, 0.7]
                  ),  # to test flattening
                  counterfactual_model_name: np.array([1.0, 0.1]),
              },
              "example_weights": np.array([3.0]),
              "features": {
                  "example_id_key": np.array(["id_2"]),
              },
          },
          {
              "labels": None,
              "predictions": {
                  original_model_name: np.array([0.5, 0.2]),
                  counterfactual_model_name: np.array([0.2, 0.4]),
              },
              "example_weights": np.array([2.0]),
              "features": {
                  "example_id_key": np.array(["id_3"]),
              },
          },
          {
              "labels": None,
              "predictions": {
                  original_model_name: np.array([0.2, 0.1]),
                  counterfactual_model_name: np.array([0.4, 0.5]),
              },
              "example_weights": np.array([1.0]),
              "features": {
                  "example_id_key": np.array(["id_4"]),
              },
          },
      ]
  
      with beam.Pipeline() as pipeline:
          # pylint: disable=no-value-for-parameter
          result = (
              pipeline
              | "Create" >> beam.Create(examples)
              | "Process"
              >> beam.Map(metric_util.to_standard_metric_inputs, True)
              | "AddSlice" >> beam.Map(lambda x: ((), x))
              | "ComputeBinaryConfusionMatrix"
              >> beam.CombinePerKey(binary_confusion_matrix.combiner)
              | "ComputeMatrices"
              >> beam.Map(lambda x: (x[0], matrices.result(x[1])))
              | "ComputeMetrics"
              >> beam.Map(lambda x: (x[0], metrics.result(x[1])))
          )
  
          # pylint: enable=no-value-for-parameter
          def check_result(got):
              try:
                  self.assertLen(got, 1)
                  got_slice_key, got_metrics = got[0]
                  self.assertEqual(got_slice_key, ())
                  self.assertLen(got_metrics, 6)
                  self.assertDictElementsAlmostEqual(
                      got_metrics,
                      {
                          metric_types.MetricKey(
                              name="flip_count/positive_to_negative@0.3",
                              model_name="original",
                              example_weighted=True,
                          ): 5.0,
                          metric_types.MetricKey(
                              name="flip_count/negative_to_positive@0.3",
                              model_name="original",
                              example_weighted=True,
                          ): 7.0,
                          metric_types.MetricKey(
                              name="flip_count/positive_examples_count@0.3",
                              model_name="original",
                              example_weighted=True,
                          ): 6.0,
                          metric_types.MetricKey(
                              name="flip_count/negative_examples_count@0.3",
                              model_name="original",
                              example_weighted=True,
                          ): 7.0,
                      },
                  )
                  self.assertAllEqual(
                      got_metrics[
                          metric_types.MetricKey(
                              name="flip_count/positive_to_negative_examples_ids@0.3",
                              model_name="original",
                              example_weighted=True,
                          )
                      ],
                      np.array([["id_2"], ["id_3"]]),
                  )
                  self.assertAllEqual(
                      got_metrics[
                          metric_types.MetricKey(
                              name="flip_count/negative_to_positive_examples_ids@0.3",
                              model_name="original",
                              example_weighted=True,
                          )
                      ],
                      np.array([["id_2"], ["id_3"], ["id_4"]]),
                  )
              except AssertionError as err:
                  raise util.BeamAssertException(err)
  
          util.assert_that(result, check_result, label="result")
  
file_path: model-analysis/tensorflow_model_analysis/addons/fairness/metrics/counterfactual_fairness/flip_count_test.py
imports: import apache_beam
  from apache_beam.testing import util
  import numpy
  import tensorflow
  from tensorflow_model_analysis.addons.fairness.metrics.counterfactual_fairness import flip_count
  from tensorflow_model_analysis.eval_saved_model import testutil
  from tensorflow_model_analysis.metrics import metric_types
  from tensorflow_model_analysis.metrics import metric_util
  from tensorflow_model_analysis.proto import config_pb2
  from google.protobuf import text_format
label_desc: Use image node_id 2 for calling the FlipCountTest obj's underlying member method code with example usage: obj.testFlipCountWitEvalConfig() without return types