class_docstr: Oracle class for Hyperband.
  
  Note that to use this Oracle with your own subclassed Tuner, your Tuner
  class must be able to handle in `Tuner.run_trial` three special
  hyperparameters that will be set by this Tuner:
  
  - "tuner/trial_id": String, optionally set. The trial_id of the Trial to
      load from when starting this trial.
  - "tuner/initial_epoch": Int, always set. The initial epoch the Trial should
      be started from.
  - "tuner/epochs": Int, always set. The cumulative number of epochs this
      Trial should be trained.
  
  These hyperparameters will be set during the "successive halving" portion
  of the Hyperband algorithm.
  
  Examples:
  
  ```python
  def run_trial(self, trial, *args, **kwargs):
      hp = trial.hyperparameters
      if "tuner/trial_id" in hp:
          past_trial = self.oracle.get_trial(hp['tuner/trial_id'])
          model = self.load_model(past_trial)
      else:
          model = self.hypermodel.build(hp)
  
      initial_epoch = hp['tuner/initial_epoch']
      last_epoch = hp['tuner/epochs']
  
      for epoch in range(initial_epoch, last_epoch):
          self.on_epoch_begin(...)
          for step in range(...):
              # Run model training step here.
          self.on_epoch_end(...)
  ```
  
  Args:
      objective: A string, `keras_tuner.Objective` instance, or a list of
          `keras_tuner.Objective`s and strings. If a string, the direction of
          the optimization (min or max) will be inferred. If a list of
          `keras_tuner.Objective`, we will minimize the sum of all the
          objectives to minimize subtracting the sum of all the objectives to
          maximize. The `objective` argument is optional when
          `Tuner.run_trial()` or `HyperModel.fit()` returns a single float as
          the objective to minimize.
      max_epochs: Integer, the maximum number of epochs to train one model.
          It is recommended to set this to a value slightly higher than the
          expected epochs to convergence for your largest Model, and to use
          early stopping during training (for example, via
          `tf.keras.callbacks.EarlyStopping`). Defaults to 100.
      factor: Integer, the reduction factor for the number of epochs
          and number of models for each bracket. Defaults to 3.
      hyperband_iterations: Integer, at least 1, the number of times to
          iterate over the full Hyperband algorithm. One iteration will run
          approximately `max_epochs * (math.log(max_epochs, factor) ** 2)`
          cumulative epochs across all trials. It is recommended to set this
          to as high a value as is within your resource budget. Defaults to
          1.
      seed: Optional integer, the random seed.
      hyperparameters: Optional HyperParameters instance. Can be used to
          override (or register in advance) hyperparameters in the search
          space.
      tune_new_entries: Boolean, whether hyperparameter entries that are
          requested by the hypermodel but that were not specified in
          `hyperparameters` should be added to the search space, or not. If
          not, then the default value for these parameters will be used.
          Defaults to True.
      allow_new_entries: Boolean, whether the hypermodel is allowed to
          request hyperparameter entries not listed in `hyperparameters`.
          Defaults to True.
      max_retries_per_trial: Integer. Defaults to 0. The maximum number of
          times to retry a `Trial` if the trial crashed or the results are
          invalid.
      max_consecutive_failed_trials: Integer. Defaults to 3. The maximum
          number of consecutive failed `Trial`s. When this number is reached,
          the search will be stopped. A `Trial` is marked as failed when none
          of the retries succeeded.
class_docstr_tok: ["Oracle","class","for","Hyperband",".","Note","that","to","use","this","Oracle","with","your","own","subclassed","Tuner",",","your","Tuner","class","must","be","able","to","handle","in","`","Tuner.run_trial","`","three","special","hyperparameters","that","will","be","set","by","this","Tuner",":","-","``","tuner\/trial_id","''",":","String",",","optionally","set",".","The","trial_id","of","the","Trial","to","load","from","when","starting","this","trial",".","-","``","tuner\/initial_epoch","''",":","Int",",","always","set",".","The","initial","epoch","the","Trial","should","be","started","from",".","-","``","tuner\/epochs","''",":","Int",",","always","set",".","The","cumulative","number","of","epochs","this","Trial","should","be","trained",".","These","hyperparameters","will","be","set","during","the","``","successive","halving","''","portion","of","the","Hyperband","algorithm",".","Examples",":","``","`","python","def","run_trial","(","self",",","trial",",","*","args",",","*","*","kwargs",")",":","hp","=","trial.hyperparameters","if","``","tuner\/trial_id","''","in","hp",":","past_trial","=","self.oracle.get_trial","(","hp","[","'tuner\/trial_id","'","]",")","model","=","self.load_model","(","past_trial",")","else",":","model","=","self.hypermodel.build","(","hp",")","initial_epoch","=","hp","[","'tuner\/initial_epoch","'","]","last_epoch","=","hp","[","'tuner\/epochs","'","]","for","epoch","in","range","(","initial_epoch",",","last_epoch",")",":","self.on_epoch_begin","(","...",")","for","step","in","range","(","...",")",":","#","Run","model","training","step","here",".","self.on_epoch_end","(","...",")","``","`","Args",":","objective",":","A","string",",","`","keras_tuner.Objective","`","instance",",","or","a","list","of","`","keras_tuner.Objective","`","s","and","strings",".","If","a","string",",","the","direction","of","the","optimization","(","min","or","max",")","will","be","inferred",".","If","a","list","of","`","keras_tuner.Objective","`",",","we","will","minimize","the","sum","of","all","the","objectives","to","minimize","subtracting","the","sum","of","all","the","objectives","to","maximize",".","The","`","objective","`","argument","is","optional","when","`","Tuner.run_trial","(",")","`","or","`","HyperModel.fit","(",")","`","returns","a","single","float","as","the","objective","to","minimize",".","max_epochs",":","Integer",",","the","maximum","number","of","epochs","to","train","one","model",".","It","is","recommended","to","set","this","to","a","value","slightly","higher","than","the","expected","epochs","to","convergence","for","your","largest","Model",",","and","to","use","early","stopping","during","training","(","for","example",",","via","`","tf.keras.callbacks.EarlyStopping","`",")",".","Defaults","to","100.","factor",":","Integer",",","the","reduction","factor","for","the","number","of","epochs","and","number","of","models","for","each","bracket",".","Defaults","to","3.","hyperband_iterations",":","Integer",",","at","least","1",",","the","number","of","times","to","iterate","over","the","full","Hyperband","algorithm",".","One","iteration","will","run","approximately","`","max_epochs","*","(","math.log","(","max_epochs",",","factor",")","*","*","2",")","`","cumulative","epochs","across","all","trials",".","It","is","recommended","to","set","this","to","as","high","a","value","as","is","within","your","resource","budget",".","Defaults","to","1.","seed",":","Optional","integer",",","the","random","seed",".","hyperparameters",":","Optional","HyperParameters","instance",".","Can","be","used","to","override","(","or","register","in","advance",")","hyperparameters","in","the","search","space",".","tune_new_entries",":","Boolean",",","whether","hyperparameter","entries","that","are","requested","by","the","hypermodel","but","that","were","not","specified","in","`","hyperparameters","`","should","be","added","to","the","search","space",",","or","not",".","If","not",",","then","the","default","value","for","these","parameters","will","be","used",".","Defaults","to","True",".","allow_new_entries",":","Boolean",",","whether","the","hypermodel","is","allowed","to","request","hyperparameter","entries","not","listed","in","`","hyperparameters","`",".","Defaults","to","True",".","max_retries_per_trial",":","Integer",".","Defaults","to","0",".","The","maximum","number","of","times","to","retry","a","`","Trial","`","if","the","trial","crashed","or","the","results","are","invalid",".","max_consecutive_failed_trials",":","Integer",".","Defaults","to","3",".","The","maximum","number","of","consecutive","failed","`","Trial","`","s",".","When","this","number","is","reached",",","the","search","will","be","stopped",".","A","`","Trial","`","is","marked","as","failed","when","none","of","the","retries","succeeded","."]
docstr: Fill the hyperparameter space with values.
  
  Args:
      trial_id: A string, the ID for this Trial.
  
  Returns:
      A dictionary with keys "values" and "status", where "values" is
      a mapping of parameter names to suggested values, and "status"
      should be one of "RUNNING" (the trial can start normally), "IDLE"
      (the oracle is waiting on something and cannot create a trial), or
      "STOPPED" (the oracle has finished searching and no new trial should
      be created).
docstr_tok: ["Fill","the","hyperparameter","space","with","values",".","Args",":","trial_id",":","A","string",",","the","ID","for","this","Trial",".","Returns",":","A","dictionary","with","keys","``","values","''","and","``","status","''",",","where","``","values","''","is","a","mapping","of","parameter","names","to","suggested","values",",","and","``","status","''","should","be","one","of","``","RUNNING","''","(","the","trial","can","start","normally",")",",","``","IDLE","''","(","the","oracle","is","waiting","on","something","and","can","not","create","a","trial",")",",","or","``","STOPPED","''","(","the","oracle","has","finished","searching","and","no","new","trial","should","be","created",")","."]
code: def populate_space(self, trial_id):
      """Fill the hyperparameter space with values.
  
      Args:
          trial_id: A string, the ID for this Trial.
  
      Returns:
          A dictionary with keys "values" and "status", where "values" is
          a mapping of parameter names to suggested values, and "status"
          should be one of "RUNNING" (the trial can start normally), "IDLE"
          (the oracle is waiting on something and cannot create a trial), or
          "STOPPED" (the oracle has finished searching and no new trial should
          be created).
      """
      self._remove_completed_brackets()
  
      for bracket in self._brackets:
          bracket_num = bracket["bracket_num"]
          rounds = bracket["rounds"]
  
          if len(rounds[0]) < self._get_size(bracket_num, round_num=0):
              # Populate the initial random trials for this bracket.
              return self._random_trial(trial_id, bracket)
          # Try to populate incomplete rounds for this bracket.
          for round_num in range(1, len(rounds)):
              round_info = rounds[round_num]
              past_round_info = rounds[round_num - 1]
              size = self._get_size(bracket_num, round_num)
              past_size = self._get_size(bracket_num, round_num - 1)
  
              # If more trials from the last round are ready than will be
              # thrown out, we can select the best to run for the next round.
              already_selected = [
                  info["past_id"] for info in round_info
              ]
              candidates = [
                  self.trials[info["id"]]
                  for info in past_round_info
                  if info["id"] not in already_selected
              ]
              candidates = [
                  t for t in candidates if t.status == "COMPLETED"
              ]
              if len(candidates) > past_size - size:
                  sorted_candidates = sorted(
                      candidates,
                      key=lambda t: t.score,
                      reverse=self.objective.direction == "max",
                  )
                  best_trial = sorted_candidates[0]
  
                  values = best_trial.hyperparameters.values.copy()
                  values["tuner/trial_id"] = best_trial.trial_id
                  values["tuner/epochs"] = self._get_epochs(
                      bracket_num, round_num
                  )
                  values["tuner/initial_epoch"] = self._get_epochs(
                      bracket_num, round_num - 1
                  )
                  values["tuner/bracket"] = self._current_bracket
                  values["tuner/round"] = round_num
  
                  round_info.append(
                      {"past_id": best_trial.trial_id, "id": trial_id}
                  )
                  return {"status": "RUNNING", "values": values}
  
      # This is reached if no trials from current brackets can be run.
  
      # Max sweeps has been reached, no more brackets should be created.
      if (
          self._current_bracket == 0
          and self._current_iteration + 1 == self.hyperband_iterations
      ):
          # Stop creating new brackets, but wait to complete other brackets.
          if self.ongoing_trials:
              return {"status": "IDLE"}
          return {"status": "STOPPED"}
      # Create a new bracket.
      else:
          self._increment_bracket_num()
          self._start_new_bracket()
          return self._random_trial(trial_id, self._brackets[-1])
  
imports: import copy
  import math
  from keras_tuner import backend
  from keras_tuner import utils
  from keras_tuner.api_export import keras_tuner_export
  from keras_tuner.engine import oracle
  from keras_tuner.engine import tuner
label_desc: Use image node_id 2 for calling the HyperbandOracle obj's underlying member method code with example usage: obj.populate_space(trial_id) and returns: dict, self, self, dict, dict