code: def chooseAlgorithmsForTest(
      total, shrinkage=0.1, processExecutor=None
  ):
      parameterSpacesToConsider = int(
          math.ceil(float(total) / shrinkage)
      )
      numberFinalParameterSpaces = total
  
      resultFutures = []
      for n in range(parameterSpacesToConsider):
          algo = AlgorithmSimulation()
          resultFutures.append(
              processExecutor.submit(computeStats, algo)
          )
  
      results = []
      for n, future in enumerate(
          concurrent.futures.as_completed(resultFutures)
      ):
          stats, algo = future.result()
          fileName = "algo" + str(n) + ".bin"
          stats["fileName"] = fileName
          with open(fileName, "wb") as file:
              algo.computeLoss = None
              pickle.dump({"algo": algo, "stats": stats}, file)
  
          results.append(stats)
  
          with open("algorithms.csv", "wt") as file:
              writer = csv.DictWriter(file, fieldnames=stats.keys())
              writer.writeheader()
              writer.writerows(results)
          print("Completed algorithm " + str(n))
          sys.stdout.flush()
          sys.stderr.flush()
  
      statKeys = [
          stat for stat in results[0].keys() if stat != "fileName"
      ]
  
      # Prepare our vectors
      vectors = []
      for result in results:
          vector = [result[stat] for stat in statKeys]
          vectors.append(vector)
  
      # Normalize
      vectors = sklearn.preprocessing.scale(vectors, axis=0)
  
      # Add weights
      for index, stat in enumerate(statKeys):
          if stat == "log10_cardinality":
              vectors[:, index] *= 25
          elif stat == "num_parameters":
              vectors[:, index] *= 10
          elif stat == "noise":
              vectors[:, index] *= 10
          elif stat == "fail_rate":
              vectors[:, index] *= 5
          elif "interaction" in stat:
              vectors[:, index] *= 2
          elif "contribution" in stat:
              vectors[:, index] *= 2
          else:
              base = None
              if "all_" in stat or "top_10%" in stat:
                  base = 3
              if (
                  "recent_10" in stat
                  or "recent_25" in stat
                  or "top_20%" in stat
              ):
                  base = 2
              if "top_30%" in stat in stat or "recent_15%" in stat:
                  base = 1
              if base is None:
                  print(stat)
  
              if "correlation" in stat:
                  base = base * 3
  
              if "skew" in stat or "kurtosis" in stat:
                  vectors[:, index] *= 3 * base
              elif "stddev" in stat:
                  vectors[:, index] *= 2 * base
              else:
                  vectors[:, index] *= 1 * base
  
      print("Clustering the hyper-parameter spaces")
      # Cluster
      cluster = sklearn.cluster.AgglomerativeClustering(
          n_clusters=numberFinalParameterSpaces,
          affinity="euclidean",
          linkage="complete",
      )
      labels = cluster.fit_predict(vectors)
  
      grouped = {}
      for index, result in enumerate(results):
          label = labels[index]
  
          if label not in grouped:
              grouped[label] = [result]
          else:
              grouped[label].append(result)
  
      chosenSpaces = []
      for key, group in grouped.items():
          chosenSpaces.append(random.choice(group))
  
      with open("chosen_algorithms.csv", "wt") as file:
          writer = csv.DictWriter(file, fieldnames=results[0].keys())
          writer.writeheader()
          writer.writerows(chosenSpaces)
  
      #
      # fig, axes = plt.subplots(2)
      #
      #
      # skews = [result['all_loss_skew'] for result in chosenSpaces]
      # kurtosis = [result['all_loss_kurtosis'] for result in chosenSpaces]
      #
      # axes[0].scatter(skews, kurtosis)
      #
      # skews = [result['all_loss_skew'] for result in results]
      # kurtosis = [result['all_loss_kurtosis'] for result in results]
      #
      # axes[1].scatter(skews, kurtosis)
      # plt.show()
  
      print("Finished deciding hyperparameter spaces for test")
  
      return chosenSpaces
  
imports: import hyperopt
  import math
  import json
  import random
  import numpy
  import functools
  import concurrent.futures
  import os
  import sys
  import time
  import datetime
  import subprocess
  import scipy.stats
  import csv
  import pickle
  import matplotlib.pyplot
  from scipy.stats import norm
  import scipy.interpolate
  import copy
  import sklearn.preprocessing
  import sklearn.cluster
  from hypermax.utils import roundPrecision
  from hypermax.hyperparameter import Hyperparameter
  from pprint import pprint
  import psutil
  import lightgbm
label_desc: Use image node_id 4 for calling a global function with example usage: chooseAlgorithmsForTest(total, shrinkage, processExecutor) and returns: chosenSpaces