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"]
code: def optimize(self, f, maximize=True, pmap=map):
      best_pars = None
      f = static_key_order(self.parameter_tuples.keys())(f)
  
      if maximize:
          comp = lambda score, best: score > best
      else:
          comp = lambda score, best: score < best
  
      tuples = list(
          zip(
              *itertools.product(
                  *list(zip(*self.parameter_tuples.items()))[1]
              )
          )
      )
      scores = pmap(f, *tuples)
      scores = map(util.score, scores)
  
      if maximize:
          comp = max
      else:
          comp = min
      best_idx, _ = comp(enumerate(scores), key=op.itemgetter(1))
      best_pars = op.itemgetter(best_idx)(list(zip(*tuples)))
      return (
          dict(
              [
                  (k, v)
                  for k, v in zip(
                      self.parameter_tuples.keys(), best_pars
                  )
              ]
          ),
          None,
      )
  
file_path: optunity/wrappers/R/inst/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 5 for calling the GridSearch obj's underlying member method code with example usage: obj.optimize(f, maximize, pmap) and returns: dict,  None