class_docstr: This class is created to test the three stopping conditions for randomized gridsearch using
  GLM Binomial family.  The three stopping conditions are :
  
  1. max_runtime_secs:
  2. max_models:
  3. metrics.  We will be picking 2 stopping metrics to test this stopping condition with.  One metric
  will be optimized if it increases and the other one should be optimized if it decreases.
  
  I have written 4 tests:
  1. test1_glm_random_grid_search_model_number: this test will not put any stopping conditions
  on randomized search.  The purpose here is to make sure that randomized search will give us all possible
  hyper-parameter combinations.
  2. test2_glm_random_grid_search_max_model: this test the stopping condition of setting the max_model in
  search criteria;
  3. test3_glm_random_grid_search_max_runtime_secs: this test the stopping condition max_runtime_secs
  in search criteria;
  4. test4_glm_random_grid_search_metric: this test the stopping condition of using a metric which can be
  increasing or decreasing.
class_docstr_tok: ["This","class","is","created","to","test","the","three","stopping","conditions","for","randomized","gridsearch","using","GLM","Binomial","family",".","The","three","stopping","conditions","are",":","1.","max_runtime_secs",":","2.","max_models",":","3.","metrics",".","We","will","be","picking","2","stopping","metrics","to","test","this","stopping","condition","with",".","One","metric","will","be","optimized","if","it","increases","and","the","other","one","should","be","optimized","if","it","decreases",".","I","have","written","4","tests",":","1.","test1_glm_random_grid_search_model_number",":","this","test","will","not","put","any","stopping","conditions","on","randomized","search",".","The","purpose","here","is","to","make","sure","that","randomized","search","will","give","us","all","possible","hyper-parameter","combinations",".","2.","test2_glm_random_grid_search_max_model",":","this","test","the","stopping","condition","of","setting","the","max_model","in","search","criteria",";","3.","test3_glm_random_grid_search_max_runtime_secs",":","this","test","the","stopping","condition","max_runtime_secs","in","search","criteria",";","4.","test4_glm_random_grid_search_metric",":","this","test","the","stopping","condition","of","using","a","metric","which","can","be","increasing","or","decreasing","."]
docstr: This function setup the randomized gridsearch parameters that will be used later on:
  
  1. It will first try to grab all the parameters that are griddable and parameters used by GLM.
  2. It will find the intersection of parameters that are both griddable and used by GLM.
  3. There are several extra parameters that are used by GLM that are denoted as griddable but actually is not.
  These parameters have to be discovered manually and they These are captured in self.exclude_parameter_lists.
  4. We generate the gridsearch hyper-parameter.  For numerical parameters, we will generate those randomly.
  For enums, we will include all of them.
  
  :return: None
docstr_tok: ["This","function","setup","the","randomized","gridsearch","parameters","that","will","be","used","later","on",":","1",".","It","will","first","try","to","grab","all","the","parameters","that","are","griddable","and","parameters","used","by","GLM",".","2",".","It","will","find","the","intersection","of","parameters","that","are","both","griddable","and","used","by","GLM",".","3",".","There","are","several","extra","parameters","that","are","used","by","GLM","that","are","denoted","as","griddable","but","actually","is","not",".","These","parameters","have","to","be","discovered","manually","and","they","These","are","captured","in","self.exclude_parameter_lists",".","4",".","We","generate","the","gridsearch","hyper-parameter",".","For","numerical","parameters",",","we","will","generate","those","randomly",".","For","enums",",","we","will","include","all","of","them",".",":","return",":","None"]
code: def setup_grid_params(self):
      """
      This function setup the randomized gridsearch parameters that will be used later on:
  
      1. It will first try to grab all the parameters that are griddable and parameters used by GLM.
      2. It will find the intersection of parameters that are both griddable and used by GLM.
      3. There are several extra parameters that are used by GLM that are denoted as griddable but actually is not.
      These parameters have to be discovered manually and they These are captured in self.exclude_parameter_lists.
      4. We generate the gridsearch hyper-parameter.  For numerical parameters, we will generate those randomly.
      For enums, we will include all of them.
  
      :return: None
      """
      # build bare bone model to get all parameters
      model = H2OGeneralizedLinearEstimator(
          family=self.family, nfolds=self.nfolds
      )
      model.train(
          x=self.x_indices,
          y=self.y_index,
          training_frame=self.training1_data,
      )
  
      self.one_model_time = pyunit_utils.find_grid_runtime(
          [model]
      )  # find model train time
      print(
          "Time taken to build a base barebone model is {0}".format(
              self.one_model_time
          )
      )
  
      # grab all gridable parameters and its type
      (
          self.gridable_parameters,
          self.gridable_types,
          self.gridable_defaults,
      ) = pyunit_utils.get_gridables(model._model_json["parameters"])
  
      # give the user opportunity to pre-assign hyper parameters for fixed values
      self.hyper_params = {}
      self.hyper_params["fold_assignment"] = [
          "AUTO",
          "Random",
          "Modulo",
      ]
      self.hyper_params["missing_values_handling"] = [
          "MeanImputation",
          "Skip",
      ]
  
      # randomly generate griddable parameters
      (
          self.hyper_params,
          self.gridable_parameters,
          self.gridable_types,
          self.gridable_defaults,
      ) = pyunit_utils.gen_grid_search(
          model.full_parameters.keys(),
          self.hyper_params,
          self.exclude_parameter_lists,
          self.gridable_parameters,
          self.gridable_types,
          self.gridable_defaults,
          random.randint(1, self.max_int_number),
          self.max_int_val,
          self.min_int_val,
          random.randint(1, self.max_real_number),
          self.max_real_val,
          self.min_real_val,
      )
  
      # change the value of lambda parameters to be from 0 to self.lambda_scale instead of 0 to 1.
      if "lambda" in list(self.hyper_params):
          self.hyper_params["lambda"] = [
              self.lambda_scale * x for x in self.hyper_params["lambda"]
          ]
  
      time_scale = self.max_runtime_scale * self.one_model_time
      # change the value of runtime parameters to be from 0 to self.lambda_scale instead of 0 to 1.
      if "max_runtime_secs" in list(self.hyper_params):
          self.hyper_params["max_runtime_secs"] = [
              time_scale * x
              for x in self.hyper_params["max_runtime_secs"]
          ]
  
      # number of possible models being built:
      self.possible_number_models = pyunit_utils.count_models(
          self.hyper_params
      )
  
      # save hyper-parameters in sandbox and current test directories.
      pyunit_utils.write_hyper_parameters_json(
          self.current_dir,
          self.sandbox_dir,
          self.json_filename,
          self.hyper_params,
      )
  
file_path: h2o-3/h2o-py/dynamic_tests/testdir_algos/glm/pyunit_glm_gaussian_gridsearch_randomdiscrete_large.py
imports: import sys
  import random
  import os
  from builtins import range
  import time
  import json
  import h2o
  from tests import pyunit_utils
  from h2o.estimators.glm import H2OGeneralizedLinearEstimator
  from h2o.grid.grid_search import H2OGridSearch
label_desc: Use image node_id 3 for calling the Test_glm_random_grid_search obj's underlying member method code with example usage: obj.setup_grid_params() without return types