class_docstr: Generator on parameters sampled from given distributions.
  If all parameters are presented as a list, sampling without replacement is
  performed. If at least one parameter is given as a scipy distribution,
  sampling with replacement is used. If all parameters are given as hyperopt
  distributions Tree of Parzen Estimators searching from hyperopt is computed.
  It is highly recommended to use continuous distributions for continuous
  parameters.
  
  Parameters
  ----------
  param_distributions : dict
      Dictionary with parameters names (`str`) as keys and distributions
      or lists of parameters to try. Distributions must provide a ``rvs``
      method for random sampling (such as those from scipy.stats.distributions)
      or be hyperopt distributions for bayesian searching.
      If a list is given, it is sampled uniformly.
  
  n_iter : integer, default=None
      Number of parameter configurations that are produced.
  
  random_state : int, default=None
      Pass an int for reproducible output across multiple
      function calls.
  
  Returns
  -------
  param_combi : list of dicts or dict of hyperopt distributions
      Parameter combinations.
  
  searching_type : str
      The searching algorithm used.
class_docstr_tok: ["Generator","on","parameters","sampled","from","given","distributions",".","If","all","parameters","are","presented","as","a","list",",","sampling","without","replacement","is","performed",".","If","at","least","one","parameter","is","given","as","a","scipy","distribution",",","sampling","with","replacement","is","used",".","If","all","parameters","are","given","as","hyperopt","distributions","Tree","of","Parzen","Estimators","searching","from","hyperopt","is","computed",".","It","is","highly","recommended","to","use","continuous","distributions","for","continuous","parameters",".","Parameters","--","--","--","--","--","param_distributions",":","dict","Dictionary","with","parameters","names","(","`","str","`",")","as","keys","and","distributions","or","lists","of","parameters","to","try",".","Distributions","must","provide","a","``","rvs","``","method","for","random","sampling","(","such","as","those","from","scipy.stats.distributions",")","or","be","hyperopt","distributions","for","bayesian","searching",".","If","a","list","is","given",",","it","is","sampled","uniformly",".","n_iter",":","integer",",","default=None","Number","of","parameter","configurations","that","are","produced",".","random_state",":","int",",","default=None","Pass","an","int","for","reproducible","output","across","multiple","function","calls",".","Returns","--","--","--","-","param_combi",":","list","of","dicts","or","dict","of","hyperopt","distributions","Parameter","combinations",".","searching_type",":","str","The","searching","algorithm","used","."]
docstr: Generator parameter combinations from given distributions.
docstr_tok: ["Generator","parameter","combinations","from","given","distributions","."]
code: def sample(self):
      """Generator parameter combinations from given distributions."""
  
      param_distributions = self.param_distributions.copy()
  
      is_grid = all(
          isinstance(p, list) for p in param_distributions.values()
      )
      is_random = all(
          isinstance(p, list) or "scipy" in str(type(p)).lower()
          for p in param_distributions.values()
      )
      is_hyperopt = all(
          "hyperopt" in str(type(p)).lower()
          or (len(p) < 2 if isinstance(p, list) else False)
          for p in param_distributions.values()
      )
  
      if is_grid:
          param_combi = list(product(*param_distributions.values()))
          param_combi = [
              dict(zip(param_distributions.keys(), combi))
              for combi in param_combi
          ]
          return param_combi, "grid"
  
      elif is_random:
          if self.n_iter is None:
              raise ValueError(
                  "n_iter must be an integer >0 when scipy parameter "
                  "distributions are provided. Get None."
              )
  
          seed = (
              random.randint(1, 100)
              if self.random_state is None
              else self.random_state + 1
          )
          random.seed(seed)
  
          param_combi = []
          k = self.n_iter
          for i in range(self.n_iter):
              dist = param_distributions.copy()
              combi = []
              for j, v in enumerate(dist.values()):
                  if "scipy" in str(type(v)).lower():
                      combi.append(v.rvs(random_state=seed * (k + j)))
                  else:
                      combi.append(v[random.randint(0, len(v) - 1)])
                  k += i + j
              param_combi.append(
                  dict(zip(param_distributions.keys(), combi))
              )
          np.random.mtrand._rand
  
          return param_combi, "random"
  
      elif is_hyperopt:
          if self.n_iter is None:
              raise ValueError(
                  "n_iter must be an integer >0 when hyperopt "
                  "search spaces are provided. Get None."
              )
          param_distributions = {
              k: p[0] if isinstance(p, list) else p
              for k, p in param_distributions.items()
          }
  
          return param_distributions, "hyperopt"
  
      else:
          raise ValueError(
              "Parameters not recognized. "
              "Pass lists, scipy distributions (also in conjunction "
              "with lists), or hyperopt search spaces."
          )
  
file_path: shap-hypetune/shaphypetune/utils.py
imports: import random
  import numpy
  from itertools import product
  from shap import TreeExplainer
label_desc: Use image node_id 2 for calling the ParameterSampler obj's underlying member method code with example usage: obj.sample() and returns: param_combi,  str, param_combi,  str, param_distributions,  str