class_docstr: Generator on parameters sampled from given distributions.
  
  Non-deterministic iterable over random candidate combinations for hyper-
  parameter search. If all parameters are presented as a list,
  sampling without replacement is performed. If at least one parameter
  is given as a distribution, sampling with replacement is used.
  It is highly recommended to use continuous distributions for continuous
  parameters.
  
  Note that before SciPy 0.16, the ``scipy.stats.distributions`` do not
  accept a custom RNG instance and always use the singleton RNG from
  ``numpy.random``. Hence setting ``random_state`` will not guarantee a
  deterministic iteration whenever ``scipy.stats`` distributions are used to
  define the parameter search space. Deterministic behavior is however
  guaranteed from SciPy 0.16 onwards.
  
  Read more in the :ref:`User Guide <search>`.
  
  Parameters
  ----------
  param_distributions : dict
      Dictionary where the keys are parameters and values
      are distributions from which a parameter is to be sampled.
      Distributions either have to provide a ``rvs`` function
      to sample from them, or can be given as a list of values,
      where a uniform distribution is assumed.
  
  n_iter : integer
      Number of parameter settings that are produced.
  
  random_state : int or RandomState
      Pseudo random number generator state used for random uniform sampling
      from lists of possible values instead of scipy.stats distributions.
  
  Returns
  -------
  params : dict of string to any
      **Yields** dictionaries mapping each estimator parameter to
      as sampled value.
  
  Examples
  --------
  >>> from sklearn.model_selection import ParameterSampler
  >>> from scipy.stats.distributions import expon
  >>> import numpy as np
  >>> np.random.seed(0)
  >>> param_grid = {'a':[1, 2], 'b': expon()}
  >>> param_list = list(ParameterSampler(param_grid, n_iter=4))
  >>> rounded_list = [dict((k, round(v, 6)) for (k, v) in d.items())
  ...                 for d in param_list]
  >>> rounded_list == [{'b': 0.89856, 'a': 1},
  ...                  {'b': 0.923223, 'a': 1},
  ...                  {'b': 1.878964, 'a': 2},
  ...                  {'b': 1.038159, 'a': 2}]
  True
class_docstr_tok: ["Generator","on","parameters","sampled","from","given","distributions",".","Non-deterministic","iterable","over","random","candidate","combinations","for","hyper-","parameter","search",".","If","all","parameters","are","presented","as","a","list",",","sampling","without","replacement","is","performed",".","If","at","least","one","parameter","is","given","as","a","distribution",",","sampling","with","replacement","is","used",".","It","is","highly","recommended","to","use","continuous","distributions","for","continuous","parameters",".","Note","that","before","SciPy","0.16",",","the","``","scipy.stats.distributions","``","do","not","accept","a","custom","RNG","instance","and","always","use","the","singleton","RNG","from","``","numpy.random","``",".","Hence","setting","``","random_state","``","will","not","guarantee","a","deterministic","iteration","whenever","``","scipy.stats","``","distributions","are","used","to","define","the","parameter","search","space",".","Deterministic","behavior","is","however","guaranteed","from","SciPy","0.16","onwards",".","Read","more","in","the",":","ref",":","`","User","Guide","<","search",">","`",".","Parameters","--","--","--","--","--","param_distributions",":","dict","Dictionary","where","the","keys","are","parameters","and","values","are","distributions","from","which","a","parameter","is","to","be","sampled",".","Distributions","either","have","to","provide","a","``","rvs","``","function","to","sample","from","them",",","or","can","be","given","as","a","list","of","values",",","where","a","uniform","distribution","is","assumed",".","n_iter",":","integer","Number","of","parameter","settings","that","are","produced",".","random_state",":","int","or","RandomState","Pseudo","random","number","generator","state","used","for","random","uniform","sampling","from","lists","of","possible","values","instead","of","scipy.stats","distributions",".","Returns","--","--","--","-","params",":","dict","of","string","to","any","*","*","Yields","*","*","dictionaries","mapping","each","estimator","parameter","to","as","sampled","value",".","Examples","--","--","--","--",">",">",">","from","sklearn.model_selection","import","ParameterSampler",">",">",">","from","scipy.stats.distributions","import","expon",">",">",">","import","numpy","as","np",">",">",">","np.random.seed","(","0",")",">",">",">","param_grid","=","{","'","a","'",":","[","1",",","2","]",",","'","b","'",":","expon","(",")","}",">",">",">","param_list","=","list","(","ParameterSampler","(","param_grid",",","n_iter=4",")",")",">",">",">","rounded_list","=","[","dict","(","(","k",",","round","(","v",",","6",")",")","for","(","k",",","v",")","in","d.items","(",")",")","...","for","d","in","param_list","]",">",">",">","rounded_list","==","[","{","'","b","'",":","0.89856",",","'","a","'",":","1","}",",","...","{","'","b","'",":","0.923223",",","'","a","'",":","1","}",",","...","{","'","b","'",":","1.878964",",","'","a","'",":","2","}",",","...","{","'","b","'",":","1.038159",",","'","a","'",":","2","}","]","True"]
code: def __iter__(self):
      # check if all distributions are given as lists
      # in this case we want to sample without replacement
      all_lists = np.all(
          [
              not hasattr(v, "rvs")
              for v in self.param_distributions.values()
          ]
      )
      rnd = check_random_state(self.random_state)
  
      if all_lists:
          # look up sampled parameter settings in parameter grid
          param_grid = ParameterGrid(self.param_distributions)
          grid_size = len(param_grid)
  
          if grid_size < self.n_iter:
              raise ValueError(
                  "The total space of parameters %d is smaller "
                  "than n_iter=%d. For exhaustive searches, use "
                  "GridSearchCV." % (grid_size, self.n_iter)
              )
          for i in sample_without_replacement(
              grid_size, self.n_iter, random_state=rnd
          ):
              yield param_grid[i]
  
      else:
          # Always sort the keys of a dictionary, for reproducibility
          items = sorted(self.param_distributions.items())
          for _ in six.moves.range(self.n_iter):
              params = dict()
              for k, v in items:
                  if hasattr(v, "rvs"):
                      if sp_version < (0, 16):
                          params[k] = v.rvs()
                      else:
                          params[k] = v.rvs(random_state=rnd)
                  else:
                      params[k] = v[rnd.randint(len(v))]
              yield params
  
imports: from __future__ import print_function
  from __future__ import division
  from abc import ABCMeta, abstractmethod
  from collections import Mapping, namedtuple, Sized, defaultdict, Sequence
  from functools import partial, reduce
  from itertools import product
  import operator
  import warnings
  import numpy
  from ..base import BaseEstimator, is_classifier, clone
  from ..base import MetaEstimatorMixin
  from ._split import check_cv
  from ._validation import _fit_and_score
  from ..exceptions import NotFittedError
  from ..externals.joblib import Parallel, delayed
  from ..externals import six
  from ..utils import check_random_state
  from ..utils.fixes import sp_version
  from ..utils.fixes import rankdata
  from ..utils.fixes import MaskedArray
  from ..utils.random import sample_without_replacement
  from ..utils.validation import indexable, check_is_fitted
  from ..utils.metaestimators import if_delegate_has_method
  from ..metrics.scorer import check_scoring
label_desc: Use image node_id 2 for calling the ParameterSampler obj's underlying member method code with example usage: obj.__iter__() without return types