class_docstr: This class represents a simulation of hypothetical machine learning algorithm hyper-parameter spaces.
  
  It is mostly used for conducting abstract research into hyper-parameter optimization.
class_docstr_tok: ["This","class","represents","a","simulation","of","hypothetical","machine","learning","algorithm","hyper-parameter","spaces",".","It","is","mostly","used","for","conducting","abstract","research","into","hyper-parameter","optimization","."]
code: def createSearchFunction(self):
      primaryParameters = [
          self.createHyperParameter(group="primary")
          for n in range(random.randint(1, 8))
      ]
  
      parameterSubGroups = random.randint(1, 3)
      probabilityOfInteraction = random.uniform(0.1, 0.5)
  
      contributions = []
      for parameter in primaryParameters:
          contributions.append(
              self.createHyperParameterContribution(
                  parameter, group="primary"
              )
          )
  
      interactions = []
      for param1Index, param1 in enumerate(primaryParameters):
          for param2Index, param2 in enumerate(
              primaryParameters[param1Index + 1 :]
          ):
              if (
                  param1["name"] != param2["name"]
                  and random.uniform(0, 1) <= probabilityOfInteraction
              ):
                  interactions.append(
                      self.createHyperParameterInteraction(
                          param1, param2, group="primary"
                      )
                  )
  
      allContributions = list(contributions)
      allInteractions = list(interactions)
  
      subGroups = []
      for n in range(parameterSubGroups):
          group = "group" + str(n + 1)
          subGroupParameters = [
              self.createHyperParameter(group=group)
              for n in range(random.randint(1, 5))
          ]
          subGroupContributions = [
              self.createHyperParameterContribution(
                  parameter, group=group
              )
              for parameter in subGroupParameters
          ]
  
          parametersForInteraction = (
              primaryParameters + subGroupParameters
          )
  
          subGroupInteractions = []
          for param1Index, param1 in enumerate(
              parametersForInteraction
          ):
              for param2Index, param2 in enumerate(
                  parametersForInteraction[param1Index + 1 :]
              ):
                  if (
                      param1["name"] != param2["name"]
                      and random.uniform(0, 1)
                      <= probabilityOfInteraction
                      and (
                          param1 in subGroupParameters
                          or param2 in subGroupParameters
                      )
                  ):
                      subGroupInteractions.append(
                          self.createHyperParameterInteraction(
                              param1, param2, group=group
                          )
                      )
          subGroups.append(
              {
                  "parameters": subGroupParameters,
                  "contributions": subGroupContributions,
                  "interactions": subGroupInteractions,
              }
          )
  
          allContributions = allContributions + subGroupContributions
          allInteractions = allInteractions + subGroupInteractions
  
      computeScript = ""
      computeScript += "from scipy.stats import norm\n"
      computeScript += "import math\n"
      computeScript += "import random\n"
      computeScript += "import scipy.interpolate\n"
      computeScript += "\n"
      computeScript += "contributions = []\n"
      for index, contribution in enumerate(allContributions):
          computeScript += (
              "contributions.append(" + contribution["func"] + ")\n"
          )
          contribution["index"] = index
      computeScript += "interactions = []\n"
      for index, interaction in enumerate(allInteractions):
          computeScript += (
              "interactions.append(" + interaction["func"] + ")\n"
          )
          interaction["index"] = index
      computeScript += "def computeLoss(params):\n"
      computeScript += "    #print(params)\n"
      computeScript += "    if random.uniform(0, 1.0) < {0}:\n".format(
          self.failRate
      )
      computeScript += '        return {"loss": 1.0, "status": "ok"}\n'
  
      def getParamFetcher(param):
          if param["group"] == "primary":
              return 'params["{0}"]'.format(param["name"])
          else:
              return 'params["group"]["{1}"]'.format(
                  param["group"], param["name"]
              )
  
      for index, subGroup in enumerate(subGroups):
          # Decide which sub-group is getting optimized
          computeScript += (
              "    if params['group']['group'] == 'group{0}':\n".format(
                  index + 1
              )
          )
          computeScript += "        loss = 0\n"
          totalParameterWeight = 0
          group = "group" + str(index + 1)
  
          contributionsForGroup = [
              contribution
              for contribution in allContributions
              if contribution["group"] == "primary"
              or contribution["group"] == group
          ]
          interactionsForGroup = [
              interaction
              for interaction in allInteractions
              if interaction["group"] == "primary"
              or interaction["group"] == group
          ]
          parametersForGroup = [
              (contribution["param"], contribution["index"])
              for contribution in contributionsForGroup
          ]
  
          for parameterIndex, parameter in enumerate(
              parametersForGroup
          ):
              computeScript += "        {0}_loss = 0\n".format(
                  parameter[0]["name"]
              )
              computeScript += "        {0}_contribution = contributions[{1}]({2})\n".format(
                  parameter[0]["name"],
                  parameter[1],
                  getParamFetcher(parameter[0]),
              )
  
              interactionsWeight = 0.0
              for index, interaction in enumerate(interactionsForGroup):
                  if (
                      interaction["param1"]["name"]
                      == parameter[0]["name"]
                      or interaction["param2"]["name"]
                      == parameter[0]["name"]
                  ):
                      computeScript += "        {0}_loss += interactions[{1}]({2}, {3}) * {4}\n".format(
                          parameter[0]["name"],
                          str(index),
                          getParamFetcher(interaction["param1"]),
                          getParamFetcher(interaction["param2"]),
                          interaction["weight"],
                      )
                      interactionsWeight += interaction["weight"]
  
              contributionWeight = random.uniform(0.1, 0.4)
              computeScript += (
                  "        loss += {0}_loss * {1}\n".format(
                      parameter[0]["name"],
                      parameter[0]["weight"]
                      / (
                          interactionsWeight
                          if interactionsWeight > 0
                          else 1.0
                      )
                      * (1.0 - contributionWeight),
                  )
              )
              computeScript += (
                  "        loss += {0}_contribution * {1}\n".format(
                      parameter[0]["name"],
                      parameter[0]["weight"] * contributionWeight,
                  )
              )
              totalParameterWeight += parameter[0]["weight"]
  
          computeScript += "        loss /= {0}\n".format(
              totalParameterWeight
          )
          # computeScript += "        print(loss)\n".format(totalParameterWeight)
          computeScript += (
              "        loss *= random.uniform(1.0, {0})\n".format(
                  self.noiseFactor
              )
          )
          computeScript += '        return {"loss":float(loss[0]) if not isinstance(loss, float) else loss, "status": "ok"}\n'
  
      groups = [
          {
              "type": "object",
              "properties": {
                  param["name"]: param["space"]
                  for param in group["parameters"]
              },
          }
          for group in subGroups
      ]
  
      parameterSpace = {
          param["name"]: param["space"] for param in primaryParameters
      }
      for index, group in enumerate(groups):
          parameterSpace["group" + str(index + 1)] = group
  
      search = {
          "ui": {"enabled": False},
          "hyperparameters": {
              "type": "object",
              "properties": parameterSpace,
          },
          "function": {
              "type": "python_function",
              "module": "test",
              "name": "computeLoss",
              "parallel": 25,
          },
          "search": {"method": "random", "iterations": 10000},
          "results": {"graphs": True, "directory": "results"},
      }
  
      self.computeScript = computeScript
      self.search = search
      self.subGroups = subGroups
  
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 5 for calling the AlgorithmSimulation obj's underlying member method code with example usage: obj.createSearchFunction() and returns: str, str