class_docstr: This algorithm combines our ATPE optimizer with Hyperband
class_docstr_tok: ["This","algorithm","combines","our","ATPE","optimizer","with","Hyperband"]
code: def recommendNextParameters(
      self,
      hyperparameterSpace,
      results,
      currentTrials,
      lockedValues=None,
  ):
      runs = self.createBudgetSchedule()
  
      space = Hyperparameter(hyperparameterSpace)
  
      finishedAndRunningResults = [
          result for result in results if result["loss"] is not None
      ] + [
          space.convertToFlatValues(trial["params"])
          for trial in currentTrials
      ]
  
      runsNeeded = []
      loopResults = []
      loop = None
  
      # Find which is the largest $loop we find in the results
      if len(finishedAndRunningResults) == 0:
          loop = 0
          runsNeeded = sorted(runs, key=lambda run: run["budget"])
      else:
          maxLoop = max(
              [result["$loop"] for result in finishedAndRunningResults]
          )
  
          for loopToTest in range(maxLoop + 1):
              loopResults = [
                  result
                  for result in finishedAndRunningResults
                  if result["$loop"] == loopToTest
              ]
  
              # Define which secondary halving runs have enough data to operate
              runsNeeded = []
              for run in runs:
                  if run["input_round"] != -1:
                      inputResultsForRun = [
                          result
                          for result in loopResults
                          if (
                              result["$group"] == run["group"]
                              and result["$round"] == run["input_round"]
                              and ("loss" in result)
                          )
                      ]
  
                      if len(inputResultsForRun) < run["input_configs"]:
                          continue
  
                  resultsForRun = [
                      result
                      for result in loopResults
                      if (
                          result["$group"] == run["group"]
                          and result["$round"] == run["round"]
                      )
                  ]
  
                  if len(resultsForRun) < run["configs_start"]:
                      runsNeeded.append(run)
  
              runsNeeded = sorted(
                  runsNeeded,
                  key=lambda run: (-run["group"], -run["budget"]),
              )
              if len(runsNeeded) > 0:
                  loop = loopToTest
                  break
          if loop is None:
              loop = maxLoop
  
      if len(runsNeeded) == 0:
          runsNeeded = sorted(runs, key=lambda run: run["budget"])
          loop += 1
  
      run = runsNeeded[0]
  
      if run["input_round"] == -1:
          resultsForReccomendation = [
              result
              for result in results
              if result["$budget"] == run["budget"]
          ]
  
          if random.uniform(0, 1) < 0.3:
              params = self.randomOptimizer.recommendNextParameters(
                  hyperparameterSpace,
                  resultsForReccomendation,
                  currentTrials,
              )
          else:
              params = self.baseOptimizer.recommendNextParameters(
                  hyperparameterSpace,
                  resultsForReccomendation,
                  currentTrials,
              )
  
          params["$budget"] = run["budget"]
          params["$loop"] = loop
          params["$group"] = run["group"]
          params["$round"] = run["round"]
          return params
      else:
          inputResultsForRun = [
              result
              for result in loopResults
              if (
                  result["$group"] == run["group"]
                  and result["$round"] == run["input_round"]
              )
          ]
          inputResultsForRun = sorted(
              inputResultsForRun, key=lambda result: result["loss"]
          )[0 : run["configs_start"]]
  
          existingResultsForRun = [
              result
              for result in loopResults
              if (
                  result["$group"] == run["group"]
                  and result["$round"] == run["round"]
              )
          ]
  
          inputCanonicalStrings = [
              self.createCanonicalStringFromResult(
                  result, hyperparameterSpace
              )
              for result in inputResultsForRun
          ]
          existingCanonicalStrings = [
              self.createCanonicalStringFromResult(
                  result, hyperparameterSpace
              )
              for result in existingResultsForRun
          ]
  
          neededCanonicalStrings = set(
              inputCanonicalStrings
          ).difference(existingCanonicalStrings)
          neededResults = [
              inputResultsForRun[
                  inputCanonicalStrings.index(resultString)
              ]
              for resultString in neededCanonicalStrings
          ]
  
          chosenResult = random.choice(neededResults)
          params = space.convertToStructuredValues(chosenResult)
          params["$budget"] = run["budget"]
          params["$loop"] = loop
          params["$group"] = run["group"]
          params["$round"] = run["round"]
  
          return params
  
file_path: hypermax/hypermax/algorithms/adaptive_bayesian_hyperband_optimizer.py
imports: import numpy
  import random
  from math import log, ceil
  from time import time, ctime
  from .optimization_algorithm_base import OptimizationAlgorithmBase
  from .random_search_optimizer import RandomSearchOptimizer
  from pprint import pprint
  from ..hyperparameter import Hyperparameter
  import hyperopt
  import json
  import functools
  import copy
label_desc: Use image node_id 6 for calling the AdaptiveBayesianHyperband obj's underlying member method code with example usage: obj.recommendNextParameters(hyperparameterSpace, results, currentTrials, lockedValues) and returns: params, params