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):
      parameters = [
          self.createHyperParameter()
          for n in range(random.randint(3, 16))
      ]
  
      probabilityOfInteraction = 0.3
  
      contributions = []
      for parameter in parameters:
          contributions.append(
              self.createHyperParameterContribution(parameter)
          )
  
      # We make two completely separate distributions. One for the first half of parameters, one for the second half.
      nameSortedParameters = sorted(
          parameter["name"] for parameter in parameters
      )
      cutoff = int(len(nameSortedParameters) / 2)
      group1ParametersNames = nameSortedParameters[:cutoff]
      group2ParametersNames = nameSortedParameters[cutoff:]
      group1Parameters = [
          [p for p in parameters if p["name"] == parameter][0]
          for parameter in group1ParametersNames
      ]
      group2Parameters = [
          [p for p in parameters if p["name"] == parameter][0]
          for parameter in group2ParametersNames
      ]
  
      interactions = []
      if self.independentInteractions:
          for param1 in group1Parameters:
              for param2 in group1Parameters:
                  if (
                      param1["name"] != param2["name"]
                      and random.uniform(0, 1)
                      <= probabilityOfInteraction
                  ):
                      interactions.append(
                          self.createHyperParameterInteraction(
                              param1, param2
                          )
                      )
          for param1 in group2Parameters:
              for param2 in group2Parameters:
                  if (
                      param1["name"] != param2["name"]
                      and random.uniform(0, 1)
                      <= probabilityOfInteraction
                  ):
                      interactions.append(
                          self.createHyperParameterInteraction(
                              param1, param2
                          )
                      )
      else:
          for param1 in parameters:
              for param2 in parameters:
                  if (
                      param1["name"] != param2["name"]
                      and random.uniform(0, 1)
                      <= probabilityOfInteraction
                  ):
                      interactions.append(
                          self.createHyperParameterInteraction(
                              param1, param2
                          )
                      )
  
      computeScript = ""
      computeScript += "from scipy.stats import norm\n"
      computeScript += "import math\n"
      computeScript += "import scipy.interpolate\n"
      computeScript += "\n"
      computeScript += "contributions = []\n"
      for contribution in contributions:
          computeScript += (
              "contributions.append(" + contribution["func"] + ")\n"
          )
      computeScript += "interactions = []\n"
      for interaction in interactions:
          computeScript += (
              "interactions.append(" + interaction["func"] + ")\n"
          )
      computeScript += "def computeLoss(params):\n"
      computeScript += "    loss = 0\n"
      totalParameterWeight = 0
      for parameterIndex, parameter in enumerate(parameters):
          computeScript += "    {0}_loss = 0\n".format(
              parameter["name"]
          )
          computeScript += '    {0}_contribution = contributions[{1}](params["{2}"])\n'.format(
              parameter["name"], parameterIndex, parameter["name"]
          )
          # computeScript += "    print(\"{0}_contribution\", {0}_contribution)\n".format(parameter['name'], parameter['name'])
          interactionsWeight = 0.0
          for index, interaction in enumerate(interactions):
              if (
                  interaction["param1"]["name"] == parameter["name"]
                  or interaction["param2"]["name"] == parameter["name"]
              ):
                  computeScript += '    {0}_loss += interactions[{1}](params["{2}"], params["{3}"]) * {4}\n'.format(
                      parameter["name"],
                      str(index),
                      interaction["param1"]["name"],
                      interaction["param2"]["name"],
                      interaction["weight"],
                  )
                  interactionsWeight += interaction["weight"]
                  # computeScript += "    print(\"interactions[{0}]\", interactions[{1}](params[\"{2}\"], params[\"{3}\"]) * {4})\n".format(str(index), str(index), interaction['param1']['name'], interaction['param2']['name'], interaction['weight'])
          contributionWeight = random.uniform(0.1, 0.4)
          computeScript += "    loss += {0}_loss * {1}\n".format(
              parameter["name"],
              parameter["weight"]
              / (interactionsWeight if interactionsWeight > 0 else 1.0)
              * (1.0 - contributionWeight),
          )
          computeScript += (
              "    loss += {0}_contribution * {1}\n".format(
                  parameter["name"],
                  parameter["weight"] * contributionWeight,
              )
          )
          totalParameterWeight += parameter["weight"]
  
      computeScript += "    loss /= {0}\n".format(totalParameterWeight)
      # computeScript += "    print(loss)\n".format(totalParameterWeight)
      computeScript += '    return {"loss":float(loss[0]) if not isinstance(loss, float) else loss, "status": "ok"}\n'
  
      search = {
          "ui": {"enabled": False},
          "hyperparameters": {
              "type": "object",
              "properties": {
                  param["name"]: param["space"] for param in parameters
              },
          },
          "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
  
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
  from scipy.stats import norm
  import scipy.interpolate
  from hypermax.utils import roundPrecision
  from hypermax.hyperparameter import Hyperparameter
  from pprint import pprint
  import lightgbm
label_desc: Use image node_id 5 for calling the AlgorithmSimulation obj's underlying member method code with example usage: obj.createSearchFunction() without return types