class_docstr: .. include:: /global.rst
  
  Please refer to |gridsearch| for more information about this algorithm.
  
  Exhaustive search over the Cartesian product of parameter tuples.
  Returns x (the tuple which maximizes f) and its score f(x).
  
  >>> s = GridSearch(x=[1,2,3], y=[-1,0,1])
  >>> best_pars, _ = s.optimize(lambda x, y: x*y)
  >>> best_pars['x']
  3
  >>> best_pars['y']
  1
class_docstr_tok: ["..","include",":",":","\/global.rst","Please","refer","to","|gridsearch|","for","more","information","about","this","algorithm",".","Exhaustive","search","over","the","Cartesian","product","of","parameter","tuples",".","Returns","x","(","the","tuple","which","maximizes","f",")","and","its","score","f","(","x",")",".",">",">",">","s","=","GridSearch","(","x=","[","1,2,3","]",",","y=","[","-1,0,1","]",")",">",">",">","best_pars",",","_","=","s.optimize","(","lambda","x",",","y",":","x","*","y",")",">",">",">","best_pars","[","'","x","'","]","3",">",">",">","best_pars","[","'","y","'","]","1"]
docstr: Creates a GridSearch solver that uses less than num_evals evaluations
  within given bounds (lb, ub). The bounds are first tightened, resulting in
  new bounds covering 99% of the area.
  
  The resulting solver will use an equally spaced grid with the same number
  of points in every dimension. The amount of points that is used is per
  dimension is the nth root of num_evals, rounded down, where n is the number
  of hyperparameters.
  
  >>> s = GridSearch.suggest_from_box(30, x=[0, 1], y=[-1, 0], z=[-1, 1])
  >>> s['x'] #doctest:+SKIP
  [0.005, 0.5, 0.995]
  >>> s['y'] #doctest:+SKIP
  [-0.995, -0.5, -0.005]
  >>> s['z'] #doctest:+SKIP
  [-0.99, 0.0, 0.99]
  
  
  Verify that we can effectively make a solver from box.
  
  >>> s = GridSearch.suggest_from_box(30, x=[0, 1], y=[-1, 0], z=[-1, 1])
  >>> solver = GridSearch(**s)
docstr_tok: ["Creates","a","GridSearch","solver","that","uses","less","than","num_evals","evaluations","within","given","bounds","(","lb",",","ub",")",".","The","bounds","are","first","tightened",",","resulting","in","new","bounds","covering","99","%","of","the","area",".","The","resulting","solver","will","use","an","equally","spaced","grid","with","the","same","number","of","points","in","every","dimension",".","The","amount","of","points","that","is","used","is","per","dimension","is","the","nth","root","of","num_evals",",","rounded","down",",","where","n","is","the","number","of","hyperparameters",".",">",">",">","s","=","GridSearch.suggest_from_box","(","30",",","x=","[","0",",","1","]",",","y=","[","-1",",","0","]",",","z=","[","-1",",","1","]",")",">",">",">","s","[","'","x","'","]","#","doctest",":","+SKIP","[","0.005",",","0.5",",","0.995","]",">",">",">","s","[","'","y","'","]","#","doctest",":","+SKIP","[","-0.995",",","-0.5",",","-0.005","]",">",">",">","s","[","'","z","'","]","#","doctest",":","+SKIP","[","-0.99",",","0.0",",","0.99","]","Verify","that","we","can","effectively","make","a","solver","from","box",".",">",">",">","s","=","GridSearch.suggest_from_box","(","30",",","x=","[","0",",","1","]",",","y=","[","-1",",","0","]",",","z=","[","-1",",","1","]",")",">",">",">","solver","=","GridSearch","(","*","*","s",")"]
code: def suggest_from_box(num_evals, **kwargs):
      """Creates a GridSearch solver that uses less than num_evals evaluations
      within given bounds (lb, ub). The bounds are first tightened, resulting in
      new bounds covering 99% of the area.
  
      The resulting solver will use an equally spaced grid with the same number
      of points in every dimension. The amount of points that is used is per
      dimension is the nth root of num_evals, rounded down, where n is the number
      of hyperparameters.
  
      >>> s = GridSearch.suggest_from_box(30, x=[0, 1], y=[-1, 0], z=[-1, 1])
      >>> s['x'] #doctest:+SKIP
      [0.005, 0.5, 0.995]
      >>> s['y'] #doctest:+SKIP
      [-0.995, -0.5, -0.005]
      >>> s['z'] #doctest:+SKIP
      [-0.99, 0.0, 0.99]
  
  
      Verify that we can effectively make a solver from box.
  
      >>> s = GridSearch.suggest_from_box(30, x=[0, 1], y=[-1, 0], z=[-1, 1])
      >>> solver = GridSearch(**s)
  
      """
      bounds = shrink_bounds(kwargs)
      num_pars = len(bounds)
  
      # number of grid points in each dimension
      # so we get density^num_par grid points in total
      density = nth_root(num_evals, num_pars)
      grid = dict(
          [
              (k, GridSearch.assign_grid_points(b[0], b[1], density))
              for k, b in bounds.items()
          ]
      )
      return grid
  
file_path: optunity/optunity/solvers/GridSearch.py
imports: import operator
  import itertools
  from ..functions import static_key_order
  from .solver_registry import register_solver
  from .util import Solver, _copydoc, shrink_bounds
  from .None import util
label_desc: Use image node_id 3 for calling the GridSearch obj's underlying member method code with example usage: obj.suggest_from_box(num_evals) and returns: grid