code: def optimizeLightGBMModel(
      gamma=None,
      nEICandidates=None,
      secondaryCutoff=None,
      initializationRounds=None,
      model=None,
  ):
      space = None
      log10_cardinality = None
      if model == "textextraction":
          space = {
              "layer_0.max_depth": hyperopt.hp.quniform(
                  "layer_0.max_depth", 8, 16, 1
              ),
              "layer_0.num_leaves": hyperopt.hp.quniform(
                  "layer_0.num_leaves", 5, 50, 1
              ),
              "layer_0.min_data_in_leaf": hyperopt.hp.quniform(
                  "layer_0.min_data_in_leaf", 20, 80, 1
              ),
              "layer_0.learning_rate": hyperopt.hp.loguniform(
                  "layer_0.learning_rate", 0.08, 0.5
              ),
              "layer_0.boosting_rounds": hyperopt.hp.quniform(
                  "layer_0.boosting_rounds", 5, 75, 1
              ),
              "layer_0.input_window": hyperopt.hp.quniform(
                  "layer_0.input_window", 0, 3, 1
              ),
              "layer_0.feature_fraction": hyperopt.hp.uniform(
                  "layer_0.feature_fraction", 0.5, 1.0
              ),
              "layer_0.bagging_fraction": hyperopt.hp.uniform(
                  "layer_0.bagging_fraction", 0.1, 1.0
              ),
              "layer_1.max_depth": hyperopt.hp.quniform(
                  "layer_1.max_depth", 2, 16, 1
              ),
              "layer_1.num_leaves": hyperopt.hp.quniform(
                  "layer_1.num_leaves", 5, 50, 1
              ),
              "layer_1.min_data_in_leaf": hyperopt.hp.quniform(
                  "layer_1.min_data_in_leaf", 1, 100, 1
              ),
              "layer_1.learning_rate": hyperopt.hp.loguniform(
                  "layer_1.learning_rate", 0.01, 0.3
              ),
              "layer_1.boosting_rounds": hyperopt.hp.quniform(
                  "layer_1.boosting_rounds", 5, 75, 1
              ),
              "layer_1.input_window": hyperopt.hp.quniform(
                  "layer_1.input_window", 3, 5, 1
              ),
          }
          log10_cardinality = 16.013760489
      elif model == "cifar_resnet":
          space = {
              "learning_rate": hyperopt.hp.uniform(
                  "learning_rate", 0.1, 3.0
              ),
              "weight_decay": hyperopt.hp.loguniform(
                  "weight_decay", math.log(2e-5), math.log(2e-3)
              ),
              "activation": hyperopt.hp.choice(
                  "activation", ["relu", "elu", "selu", "rrelu"]
              ),
              "layer1_size": hyperopt.hp.quniform(
                  "layer1_size", 32, 96, 16
              ),
              "layer1_layers": hyperopt.hp.quniform(
                  "layer1_layers", 1, 3, 1
              ),
              "layer2_size": hyperopt.hp.quniform(
                  "layer2_size", 64, 192, 32
              ),
              "layer2_layers": hyperopt.hp.quniform(
                  "layer2_layers", 1, 3, 1
              ),
              "layer3_size": hyperopt.hp.quniform(
                  "layer3_size", 128, 384, 64
              ),
              "layer3_layers": hyperopt.hp.quniform(
                  "layer3_layers", 1, 3, 1
              ),
              "layer4_size": hyperopt.hp.quniform(
                  "layer4_size", 256, 768, 128
              ),
              "layer4_layers": hyperopt.hp.quniform(
                  "layer4_layers", 1, 3, 1
              ),
          }
          log10_cardinality = 7.908485019
  
      losses = []
      for length in [100, 250]:
          for n in range(10):
              random.seed(time.time())
              if nEICandidates is None:
                  nEICandidates = 24
  
              if gamma is None:
                  gamma = 0.25
  
              if secondaryCutoff is None:
                  secondaryCutoff = 0.0
  
              if initializationRounds is None:
                  initializationRounds = 20
  
              currentResults = []
  
              def computePrimarySecondary():
                  if len(currentResults) < 20:
                      return (
                          list(sorted(space.keys())),
                          [],
                      )  # Put all parameters as primary
  
                  if (
                      len(
                          set(
                              "{:.3E}".format(result["loss"])
                              for result in currentResults
                          )
                      )
                      < 5
                  ):
                      return (
                          list(sorted(space.keys())),
                          [],
                      )  # Put all parameters as primary
  
                  cutoffForTrial = secondaryCutoff
                  if secondaryCutoff == "auto":
                      cutoffForTrial = (
                          adaptiveSecondaryGivenCardinality(
                              currentResults, log10_cardinality
                          )
                      )
  
                  totalWeight = 0
                  correlations = {}
                  for parameter in space.keys():
                      if (
                          len(
                              set(
                                  result[parameter]
                                  for result in currentResults
                              )
                          )
                          < 2
                      ):
                          correlations[parameter] = 0
                      else:
                          correlation = abs(
                              scipy.stats.spearmanr(
                                  numpy.array(
                                      [
                                          result[parameter]
                                          for result in currentResults
                                      ]
                                  ),
                                  numpy.array(
                                      [
                                          result["loss"]
                                          for result in currentResults
                                      ]
                                  ),
                              )[0]
                          )
                          correlations[parameter] = correlation
                          totalWeight += correlation
  
                  threshold = totalWeight * cutoffForTrial
  
                  primaryParameters = []
                  secondaryParameters = []
                  cumulative = totalWeight
                  # Sort properties by their weight
                  sortedParameters = sorted(
                      space.keys(),
                      key=lambda parameter: -correlations[parameter],
                  )
                  for parameter in sortedParameters:
                      if cumulative < threshold:
                          secondaryParameters.append(parameter)
                      else:
                          primaryParameters.append(parameter)
  
                      cumulative -= correlations[parameter]
                  return primaryParameters, secondaryParameters
  
              best = None
              bestLoss = None
  
              while len(currentResults) < length:
                  next = {}
  
                  def sample(parameters):
                      nonlocal next
                      next = parameters
                      return {"loss": 0.5, "status": "ok"}
  
                  (
                      primaryParameters,
                      secondaryParameters,
                  ) = computePrimarySecondary()
  
                  spaceForTrial = {
                      key: param for key, param in space.items()
                  }
  
                  if best is not None:
                      # Any secondary parameters have a 50-50 chance of being locked to their current best value.
                      for secondary in secondaryParameters:
                          if random.uniform(0, 1) < 0.5:
                              spaceForTrial[secondary] = best[secondary]
  
                  gammaForTrial = gamma
                  if isinstance(gamma, str):
                      n_startup_trials = int(
                          gamma[gamma.find("_") + 1 :]
                      )
                      gammaForTrial = adaptiveGammaGivenCardinality(
                          currentResults,
                          log10_cardinality=log10_cardinality,
                          n_startup_trials=n_startup_trials,
                      )
  
                  nEICandidatesForTrial = nEICandidates
                  if isinstance(nEICandidates, str):
                      nEICandidatesForTrial = (
                          adaptiveNCandidatesGivenCardinality(
                              log10_cardinality=log10_cardinality
                          )
                      )
  
                  hyperopt.fmin(
                      fn=sample,
                      space=spaceForTrial,
                      algo=functools.partial(
                          hyperopt.tpe.suggest,
                          n_startup_jobs=initializationRounds,
                          gamma=gammaForTrial,
                          n_EI_candidates=nEICandidatesForTrial,
                      ),
                      max_evals=1,
                      trials=convertResultsToTrials(
                          space.keys(),
                          currentResults,
                          lossFunc="identity",
                      ),
                      rstate=numpy.random.RandomState(
                          seed=int(random.randint(1, 2**32 - 1))
                      ),
                  )
  
                  result = executeLightGBMModel(next, model)
  
                  loss = result["loss"]
                  data = dict(next)  # Clone the next dict
                  data["loss"] = loss
                  currentResults.append(data)
  
                  if best is None or loss < bestLoss:
                      best = data
                      bestLoss = loss
  
              losses.append(bestLoss)
              sys.stdout.flush()
  
      return numpy.mean(losses)
  
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 12 for calling a global function with example usage: optimizeLightGBMModel(gamma, nEICandidates, secondaryCutoff, initializationRounds, model) and returns: numpy, primaryParameters,  secondaryParameters, list,  list, list,  list, dict