code: def test_independence_unmasked_computation(self, device: str):
      independence = Independence(4, 2)
      A = torch.eye(3, device=device).long()
      C = 2 * A
  
      # P(C) = [0.667, 0.0, 0.333, 0.0]
      # P(C | A = 0) = [1.0, 0.0, 0.0, 0.0]
      # P(C | A = 1) = [0.0, 0.0, 1.0, 0.0]
      # KL(P(C | A = 0) || P(C)) = 0.4055
      # KL(P(C | A = 1) || P(C)) = 1.0986
      expected_kl_divs = {0: 0.4055, 1: 1.0986}
  
      independence(C, A)
      test_kl_divs = {
          k: v.item() for k, v in independence.get_metric().items()
      }
      assert expected_kl_divs == pytest.approx(test_kl_divs, abs=1e-3)
  
      independence(C, A)
      test_kl_divs = {
          k: v.item()
          for k, v in independence.get_metric(reset=True).items()
      }
      assert expected_kl_divs == pytest.approx(test_kl_divs, abs=1e-3)
  
      test_kl_divs = {
          k: (v.item() if not math.isnan(v.item()) else np.nan)
          for k, v in independence.get_metric().items()
      }
      assert test_kl_divs == {0: np.nan, 1: np.nan}
  
imports: import pytest
  import torch
  import math
  import numpy
  from allennlp.common.checks import ConfigurationError
  from allennlp.common.testing import AllenNlpTestCase, multi_device, global_distributed_metric, run_distributed_test
  from allennlp.fairness.fairness_metrics import Independence, Separation, Sufficiency
label_desc: Use image node_id 3 for calling the IndependenceTest obj's underlying member method code with example usage: obj.test_independence_unmasked_computation(device) without return types