code: def test_size_analyzer_three(self):
      nb_clusters = 3
      nb_classes = 3
      clusters_by_class = [
          [[] for x in range(nb_clusters)] for y in range(nb_classes)
      ]
  
      clusters_by_class[0] = [0, 1, 1, 2, 2]  # Class 0
      clusters_by_class[1] = [1, 0, 0, 2, 2]  # Class 1
      clusters_by_class[2] = [0, 0, 0, 2, 1, 1]  # Class 2
      analyzer = ClusteringAnalyzer()
      (
          assigned_clean_by_class,
          poison_clusters,
          report,
      ) = analyzer.analyze_by_size(clusters_by_class)
  
      # print("clusters_by_class")
      # print(clusters_by_class)
      # print("assigned_clean_by_class")
      # print(assigned_clean_by_class)
      # print("poison_clusters")
      # print(poison_clusters)
  
      clean = 0
      poison = 1
      # For class 0, cluster 0 should be marked as poison.
      self.assertEqual(poison_clusters[0][0], poison)
      # For class 0, cluster 1 and 2 should be marked as clean.
      self.assertEqual(poison_clusters[0][1], clean)
      self.assertEqual(poison_clusters[0][2], clean)
      self.assertEqual(
          report["Class_0"]["cluster_0"]["suspicious_cluster"], True
      )
      self.assertEqual(
          report["Class_0"]["cluster_1"]["suspicious_cluster"], False
      )
      self.assertEqual(
          report["Class_0"]["cluster_2"]["suspicious_cluster"], False
      )
      total = len(clusters_by_class[0])
      counts = np.bincount(clusters_by_class[0])
      self.assertEqual(
          report["Class_0"]["cluster_0"]["ptc_data_in_cluster"],
          counts[0] / total,
      )
      self.assertEqual(
          report["Class_0"]["cluster_1"]["ptc_data_in_cluster"],
          counts[1] / total,
      )
      self.assertEqual(
          report["Class_0"]["cluster_2"]["ptc_data_in_cluster"],
          counts[2] / total,
      )
  
      self.assertEqual(poison_clusters[1][0], clean)
      self.assertEqual(poison_clusters[1][1], poison)
      self.assertEqual(poison_clusters[1][2], clean)
      self.assertEqual(
          report["Class_1"]["cluster_0"]["suspicious_cluster"], False
      )
      self.assertEqual(
          report["Class_1"]["cluster_1"]["suspicious_cluster"], True
      )
      self.assertEqual(
          report["Class_1"]["cluster_2"]["suspicious_cluster"], False
      )
      total = len(clusters_by_class[1])
      counts = np.bincount(clusters_by_class[1])
      self.assertEqual(
          report["Class_1"]["cluster_0"]["ptc_data_in_cluster"],
          counts[0] / total,
      )
      self.assertEqual(
          report["Class_1"]["cluster_1"]["ptc_data_in_cluster"],
          counts[1] / total,
      )
      self.assertEqual(
          report["Class_1"]["cluster_2"]["ptc_data_in_cluster"],
          counts[2] / total,
      )
  
      self.assertEqual(poison_clusters[2][0], clean)
      self.assertEqual(poison_clusters[2][1], clean)
      self.assertEqual(poison_clusters[2][2], poison)
      self.assertEqual(
          report["Class_2"]["cluster_0"]["suspicious_cluster"], False
      )
      self.assertEqual(
          report["Class_2"]["cluster_1"]["suspicious_cluster"], False
      )
      self.assertEqual(
          report["Class_2"]["cluster_2"]["suspicious_cluster"], True
      )
      total = len(clusters_by_class[2])
      counts = np.bincount(clusters_by_class[2])
      self.assertEqual(
          report["Class_2"]["cluster_0"]["ptc_data_in_cluster"],
          round(counts[0] / total, 2),
      )
      self.assertEqual(
          report["Class_2"]["cluster_1"]["ptc_data_in_cluster"],
          round(counts[1] / total, 2),
      )
      self.assertEqual(
          report["Class_2"]["cluster_2"]["ptc_data_in_cluster"],
          round(counts[2] / total, 2),
      )
  
      poison = 0
      self.assertEqual(assigned_clean_by_class[0][0], poison)
      self.assertEqual(assigned_clean_by_class[1][0], poison)
      self.assertEqual(assigned_clean_by_class[2][3], poison)
  
file_path: adversarial-robustness-toolbox/tests/defences/detector/poison/test_clustering_analyzer.py
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
  import unittest
  import numpy
  from art.defences.detector.poison import ClusteringAnalyzer
label_desc: Use image node_id 2 for calling the TestActivationDefence obj's underlying member method code with example usage: obj.test_size_analyzer_three() without return types