docstr: Use the hyperparameter tuning method specified by our datarun to choose
  a set of hyperparameters from the potential space.
docstr_tok: ["Use","the","hyperparameter","tuning","method","specified","by","our","datarun","to","choose","a","set","of","hyperparameters","from","the","potential","space","."]
code: def tune_hyperparameters(self, hyperpartition):
      """
      Use the hyperparameter tuning method specified by our datarun to choose
      a set of hyperparameters from the potential space.
      """
      # Get parameter metadata for this hyperpartition
      tunables = hyperpartition.tunables
  
      # If there aren't any tunable parameters, we're done. Return the vector
      # of values in the hyperpartition and mark the set as finished.
      if not len(tunables):
          LOGGER.warning(
              "No tunables for hyperpartition %d" % hyperpartition.id
          )
          self.db.mark_hyperpartition_gridding_done(hyperpartition.id)
          return update_params(
              params=[],
              tunables=tunables,
              categoricals=hyperpartition.categoricals,
              constants=hyperpartition.constants,
          )
  
      # Get previously-used parameters: every classifier should either be
      # completed or have thrown an error
      all_clfs = self.db.get_classifiers(
          hyperpartition_id=hyperpartition.id
      )
      classifiers = [
          c for c in all_clfs if c.status == ClassifierStatus.COMPLETE
      ]
  
      X = [c.hyperparameter_values for c in classifiers]
      y = np.array(
          [
              float(getattr(c, self.datarun.score_target))
              for c in classifiers
          ]
      )
  
      # Initialize the tuner and propose a new set of parameters
      # this has to be initialized with information from the hyperpartition, so we
      # need to do it fresh for each classifier (not in load_tuner)
      tuner = get_instance(
          self.Tuner,
          tunables=tunables,
          gridding=self.datarun.gridding,
          r_minimum=self.datarun.r_minimum,
      )
      if len(X) > 0:
          tuner.add(X, y)
  
      params = tuner.propose()
      if params is None and self.datarun.gridding:
          LOGGER.info(
              "Gridding done for hyperpartition %d" % hyperpartition.id
          )
          self.db.mark_hyperpartition_gridding_done(hyperpartition.id)
          return None
  
      # Append categorical and constants to the params.
      return update_params(
          params=params,
          categoricals=hyperpartition.categoricals,
          constants=hyperpartition.constants,
      )
  
imports: from __future__ import absolute_import, unicode_literals
  import datetime
  import imp
  import logging
  import os
  import re
  import socket
  import traceback
  import warnings
  from builtins import object, str
  from collections import defaultdict
  import boto3
  import numpy
  from atm.classifier import Model
  from atm.constants import CUSTOM_CLASS_REGEX, SELECTORS, TUNERS
  from atm.database import ClassifierStatus, DBSession
  from atm.utilities import ensure_directory, get_instance, save_metrics, save_model, update_params
label_desc: Use image node_id 5 for calling the Worker obj's underlying member method code with example usage: obj.tune_hyperparameters(hyperpartition) and returns: update_params, update_params, None