class_docstr: Tests that MutualInformation returns the correct AMI value.
class_docstr_tok: ["Tests","that","MutualInformation","returns","the","correct","AMI","value","."]
code: def test_mi_with_multivalent_categorical_label(self):
      np.random.seed(0)
      # Generate 100 examples of randomly variable length features with random
      # discrete values of "0", "1", "2"
      feat_array = pa.array(
          [
              [
                  str(np.random.randint(3))
                  for _ in range(np.random.randint(10))
              ]
              for _ in range(100)
          ]
      )
      label_array = pa.array(
          [
              [
                  str(np.random.randint(3))
                  for _ in range(np.random.randint(10))
              ]
              for _ in range(100)
          ]
      )
      batch = pa.RecordBatch.from_arrays(
          [label_array, feat_array, label_array],
          ["label_key", "fa", "perfect_feat"],
      )
  
      schema = text_format.Parse(
          """
            feature {
              name: "fa"
              type: BYTES
              value_count {
                min: 0
                max: 10
              }
            }
            feature {
              name: "perfect_feat"
              type: BYTES
              value_count {
                min: 0
                max: 10
              }
            }
            feature {
              name: "label_key"
              type: BYTES
              value_count {
                min: 0
                max: 10
              }
            }
            """,
          schema_pb2.Schema(),
      )
  
      expected = text_format.Parse(
          """
          features {
            path {
              step: "fa"
            }
            custom_stats {
              name: 'adjusted_mutual_information'
              num: 0
            }
          }
          features {
            path {
              step: "perfect_feat"
            }
            custom_stats {
              name: 'adjusted_mutual_information'
              num: 4.1630335
            }
          }""",
          statistics_pb2.DatasetFeatureStatistics(),
      )
      self._assert_ami_output_equal(
          batch, expected, schema, types.FeaturePath(["label_key"])
      )
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from absl.testing import absltest
  from absl.testing import parameterized
  import apache_beam
  from apache_beam.testing import util
  import numpy
  import pyarrow
  from tensorflow_data_validation import types
  from tensorflow_data_validation.statistics.generators import mutual_information
  from tensorflow_data_validation.statistics.generators import partitioned_stats_generator
  from tensorflow_data_validation.utils import test_util
  from tfx_bsl.arrow import table_util
  from google.protobuf import text_format
  from tensorflow_metadata.proto.v0 import schema_pb2
  from tensorflow_metadata.proto.v0 import statistics_pb2
label_desc: Use image node_id 13 for calling the MutualInformationTest obj's underlying member method code with example usage: obj.test_mi_with_multivalent_categorical_label() without return types