code: def test_detect_poison(self):
      # Get MNIST
      (x_train, _), (_, _), (_, _) = self.mnist
  
      _, is_clean_lst = self.defence.detect_poison(
          nb_clusters=2, nb_dims=10, reduce="PCA", ex_re_threshold=1
      )
      sum_clean1 = sum(is_clean_lst)
  
      _, is_clean_lst_gen = self.defence_gen.detect_poison(
          nb_clusters=2, nb_dims=10, reduce="PCA", ex_re_threshold=1
      )
      sum_clean1_gen = sum(is_clean_lst_gen)
  
      # Check number of items in is_clean
      self.assertEqual(len(x_train), len(is_clean_lst))
      self.assertEqual(len(x_train), len(is_clean_lst_gen))
  
      # Test right number of clusters
      found_clusters = len(np.unique(self.defence.clusters_by_class[0]))
      found_clusters_gen = len(
          np.unique(self.defence_gen.clusters_by_class[0])
      )
      self.assertEqual(found_clusters, 2)
      self.assertEqual(found_clusters_gen, 2)
  
      _, is_clean_lst = self.defence.detect_poison(
          nb_clusters=3,
          nb_dims=10,
          reduce="PCA",
          cluster_analysis="distance",
          ex_re_threshold=1,
      )
      _, is_clean_lst_gen = self.defence_gen.detect_poison(
          nb_clusters=3,
          nb_dims=10,
          reduce="PCA",
          cluster_analysis="distance",
          ex_re_threshold=1,
      )
      self.assertEqual(len(x_train), len(is_clean_lst))
      self.assertEqual(len(x_train), len(is_clean_lst_gen))
  
      # Test change of state to new number of clusters:
      found_clusters = len(np.unique(self.defence.clusters_by_class[0]))
      found_clusters_gen = len(
          np.unique(self.defence_gen.clusters_by_class[0])
      )
      self.assertEqual(found_clusters, 3)
      self.assertEqual(found_clusters_gen, 3)
  
      # Test clean data has changed
      sum_clean2 = sum(is_clean_lst)
      sum_clean2_gen = sum(is_clean_lst_gen)
      self.assertNotEqual(sum_clean1, sum_clean2)
      self.assertNotEqual(sum_clean1_gen, sum_clean2_gen)
  
      kwargs = {
          "nb_clusters": 2,
          "nb_dims": 10,
          "reduce": "PCA",
          "cluster_analysis": "distance",
          "ex_re_threshold": None,
      }
      _, is_clean_lst = self.defence.detect_poison(**kwargs)
      _, is_clean_lst_gen = self.defence_gen.detect_poison(**kwargs)
      sum_dist = sum(is_clean_lst)
      sum_dist_gen = sum(is_clean_lst_gen)
      kwargs = {
          "nb_clusters": 2,
          "nb_dims": 10,
          "reduce": "PCA",
          "cluster_analysis": "smaller",
          "ex_re_threshold": None,
      }
      _, is_clean_lst = self.defence.detect_poison(**kwargs)
      _, is_clean_lst_gen = self.defence_gen.detect_poison(**kwargs)
      sum_size = sum(is_clean_lst)
      sum_size_gen = sum(is_clean_lst_gen)
      self.assertNotEqual(sum_dist, sum_size)
      self.assertNotEqual(sum_dist_gen, sum_size_gen)
  
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
  import unittest
  from keras.preprocessing.image import ImageDataGenerator
  import numpy
  from art.data_generators import KerasDataGenerator
  from art.defences.detector.poison import ActivationDefence
  from art.utils import load_mnist
  from art.visualization import convert_to_rgb
  from tests.utils import master_seed
label_desc: Use image node_id 10 for calling the TestActivationDefence obj's underlying member method code with example usage: obj.test_detect_poison() without return types