code: def downselect_clusters(s):
      # Right now we have a lot of clusters, but they probably overlap. Let's remove that.
      # We want to find disjoint clusters, so we'll greedily add them until we have
      # 100 distjoint clusters.
  
      ss = [set(x) for x in s]
  
      keep = []
      keep_set = []
      for iteration in range(2):
          for this_set in s:
              # MAGIC NUMBERS...!
              # We want clusters of size 50 because it works
              # Except on iteration 2 where we'll settle for 25 if we haven't
              # found clusters with 50 neighbors that work.
              cur = set(this_set[: 50 - 25 * iteration])
              intersections = np.array([len(cur & x) for x in ss])
              good = np.sum(intersections == 50) > 2
              # Good means that this cluster isn't a fluke and some other cluster
              # is like this one.
              if good or iteration == 1:
                  print("N")
                  # And also make sure we haven't found this cluster (or one like it).
                  already_found = np.array(
                      [len(cur & x) for x in keep_set]
                  )
                  if np.all(already_found < len(cur) / 2):
                      print("And is new")
                      keep.append(this_set)
                      keep_set.append(set(this_set))
              if len(keep) == 100:
                  break
          print("Found", len(keep))
          if len(keep) == 100:
              break
  
      # Keep should now have 100 items.
      # If it doesn't go and change the 2000 in make_many_clusters to a bigger number.
      return keep
  
file_path: privacy/research/instahide_attack_2020/step_2_color_graph.py
imports: import multiprocessing
  import pickle
  import random
  import collections
  import numpy
label_desc: Use image node_id 4 for calling a global function with example usage: downselect_clusters(s) and returns: keep