class_docstr: An ensemble MCMC sampler
  
  If you are upgrading from an earlier version of emcee, you might notice
  that some arguments are now deprecated. The parameters that control the
  proposals have been moved to the :ref:`moves-user` interface (``a`` and
  ``live_dangerously``), and the parameters related to parallelization can
  now be controlled via the ``pool`` argument (:ref:`parallel`).
  
  Args:
      nwalkers (int): The number of walkers in the ensemble.
      ndim (int): Number of dimensions in the parameter space.
      log_prob_fn (callable): A function that takes a vector in the
          parameter space as input and returns the natural logarithm of the
          posterior probability (up to an additive constant) for that
          position.
      moves (Optional): This can be a single move object, a list of moves,
          or a "weighted" list of the form ``[(emcee.moves.StretchMove(),
          0.1), ...]``. When running, the sampler will randomly select a
          move from this list (optionally with weights) for each proposal.
          (default: :class:`StretchMove`)
      args (Optional): A list of extra positional arguments for
          ``log_prob_fn``. ``log_prob_fn`` will be called with the sequence
          ``log_prob_fn(p, *args, **kwargs)``.
      kwargs (Optional): A dict of extra keyword arguments for
          ``log_prob_fn``. ``log_prob_fn`` will be called with the sequence
          ``log_prob_fn(p, *args, **kwargs)``.
      pool (Optional): An object with a ``map`` method that follows the same
          calling sequence as the built-in ``map`` function. This is
          generally used to compute the log-probabilities for the ensemble
          in parallel.
      backend (Optional): Either a :class:`backends.Backend` or a subclass
          (like :class:`backends.HDFBackend`) that is used to store and
          serialize the state of the chain. By default, the chain is stored
          as a set of numpy arrays in memory, but new backends can be
          written to support other mediums.
      vectorize (Optional[bool]): If ``True``, ``log_prob_fn`` is expected
          to accept a list of position vectors instead of just one. Note
          that ``pool`` will be ignored if this is ``True``.
          (default: ``False``)
      parameter_names (Optional[Union[List[str], Dict[str, List[int]]]]):
          names of individual parameters or groups of parameters. If
          specified, the ``log_prob_fn`` will recieve a dictionary of
          parameters, rather than a ``np.ndarray``.
class_docstr_tok: ["An","ensemble","MCMC","sampler","If","you","are","upgrading","from","an","earlier","version","of","emcee",",","you","might","notice","that","some","arguments","are","now","deprecated",".","The","parameters","that","control","the","proposals","have","been","moved","to","the",":","ref",":","`","moves-user","`","interface","(","``","a","``","and","``","live_dangerously","``",")",",","and","the","parameters","related","to","parallelization","can","now","be","controlled","via","the","``","pool","``","argument","(",":","ref",":","`","parallel","`",")",".","Args",":","nwalkers","(","int",")",":","The","number","of","walkers","in","the","ensemble",".","ndim","(","int",")",":","Number","of","dimensions","in","the","parameter","space",".","log_prob_fn","(","callable",")",":","A","function","that","takes","a","vector","in","the","parameter","space","as","input","and","returns","the","natural","logarithm","of","the","posterior","probability","(","up","to","an","additive","constant",")","for","that","position",".","moves","(","Optional",")",":","This","can","be","a","single","move","object",",","a","list","of","moves",",","or","a","``","weighted","''","list","of","the","form","``","[","(","emcee.moves.StretchMove","(",")",",","0.1",")",",","...","]","``",".","When","running",",","the","sampler","will","randomly","select","a","move","from","this","list","(","optionally","with","weights",")","for","each","proposal",".","(","default",":",":","class",":","`","StretchMove","`",")","args","(","Optional",")",":","A","list","of","extra","positional","arguments","for","``","log_prob_fn","``",".","``","log_prob_fn","``","will","be","called","with","the","sequence","``","log_prob_fn","(","p",",","*","args",",","*","*","kwargs",")","``",".","kwargs","(","Optional",")",":","A","dict","of","extra","keyword","arguments","for","``","log_prob_fn","``",".","``","log_prob_fn","``","will","be","called","with","the","sequence","``","log_prob_fn","(","p",",","*","args",",","*","*","kwargs",")","``",".","pool","(","Optional",")",":","An","object","with","a","``","map","``","method","that","follows","the","same","calling","sequence","as","the","built-in","``","map","``","function",".","This","is","generally","used","to","compute","the","log-probabilities","for","the","ensemble","in","parallel",".","backend","(","Optional",")",":","Either","a",":","class",":","`","backends.Backend","`","or","a","subclass","(","like",":","class",":","`","backends.HDFBackend","`",")","that","is","used","to","store","and","serialize","the","state","of","the","chain",".","By","default",",","the","chain","is","stored","as","a","set","of","numpy","arrays","in","memory",",","but","new","backends","can","be","written","to","support","other","mediums",".","vectorize","(","Optional","[","bool","]",")",":","If","``","True","``",",","``","log_prob_fn","``","is","expected","to","accept","a","list","of","position","vectors","instead","of","just","one",".","Note","that","``","pool","``","will","be","ignored","if","this","is","``","True","``",".","(","default",":","``","False","``",")","parameter_names","(","Optional","[","Union","[","List","[","str","]",",","Dict","[","str",",","List","[","int","]","]","]","]",")",":","names","of","individual","parameters","or","groups","of","parameters",".","If","specified",",","the","``","log_prob_fn","``","will","recieve","a","dictionary","of","parameters",",","rather","than","a","``","np.ndarray","``","."]
code: def __init__(
      self,
      nwalkers,
      ndim,
      log_prob_fn,
      pool=None,
      moves=None,
      args=None,
      kwargs=None,
      backend=None,
      vectorize=False,
      blobs_dtype=None,
      parameter_names: Optional[
          Union[Dict[str, int], List[str]]
      ] = None,
      # Deprecated...
      a=None,
      postargs=None,
      threads=None,
      live_dangerously=None,
      runtime_sortingfn=None,
  ):
      # Warn about deprecated arguments
      if a is not None:
          deprecation_warning(
              "The 'a' argument is deprecated, use 'moves' instead"
          )
      if threads is not None:
          deprecation_warning("The 'threads' argument is deprecated")
      if runtime_sortingfn is not None:
          deprecation_warning(
              "The 'runtime_sortingfn' argument is deprecated"
          )
      if live_dangerously is not None:
          deprecation_warning(
              "The 'live_dangerously' argument is deprecated"
          )
  
      # Parse the move schedule
      if moves is None:
          self._moves = [StretchMove()]
          self._weights = [1.0]
      elif isinstance(moves, Iterable):
          try:
              self._moves, self._weights = zip(*moves)
          except TypeError:
              self._moves = moves
              self._weights = np.ones(len(moves))
      else:
          self._moves = [moves]
          self._weights = [1.0]
      self._weights = np.atleast_1d(self._weights).astype(float)
      self._weights /= np.sum(self._weights)
  
      self.pool = pool
      self.vectorize = vectorize
      self.blobs_dtype = blobs_dtype
  
      self.ndim = ndim
      self.nwalkers = nwalkers
      self.backend = Backend() if backend is None else backend
  
      # Deal with re-used backends
      if not self.backend.initialized:
          self._previous_state = None
          self.reset()
          state = np.random.get_state()
      else:
          # Check the backend shape
          if self.backend.shape != (self.nwalkers, self.ndim):
              raise ValueError(
                  (
                      "the shape of the backend ({0}) is incompatible with the "
                      "shape of the sampler ({1})"
                  ).format(
                      self.backend.shape, (self.nwalkers, self.ndim)
                  )
              )
  
          # Get the last random state
          state = self.backend.random_state
          if state is None:
              state = np.random.get_state()
  
          # Grab the last step so that we can restart
          it = self.backend.iteration
          if it > 0:
              self._previous_state = self.get_last_sample()
  
      # This is a random number generator that we can easily set the state
      # of without affecting the numpy-wide generator
      self._random = np.random.mtrand.RandomState()
      self._random.set_state(state)
  
      # Do a little bit of _magic_ to make the likelihood call with
      # ``args`` and ``kwargs`` pickleable.
      self.log_prob_fn = _FunctionWrapper(log_prob_fn, args, kwargs)
  
      # Save the parameter names
      self.params_are_named: bool = parameter_names is not None
      if self.params_are_named:
          assert isinstance(parameter_names, (list, dict))
  
          # Don't support vectorizing yet
          msg = (
              "named parameters with vectorization unsupported for now"
          )
          assert not self.vectorize, msg
  
          # Check for duplicate names
          dupes = set()
          uniq = []
          for name in parameter_names:
              if name not in dupes:
                  uniq.append(name)
                  dupes.add(name)
          msg = f"duplicate parameters: {dupes}"
          assert len(uniq) == len(parameter_names), msg
  
          if isinstance(parameter_names, list):
              # Check for all named
              msg = "name all parameters or set `parameter_names` to `None`"
              assert len(parameter_names) == ndim, msg
              # Convert a list to a dict
              parameter_names: Dict[str, int] = {
                  name: i for i, name in enumerate(parameter_names)
              }
  
          # Check not too many names
          msg = "too many names"
          assert len(parameter_names) <= ndim, msg
  
          # Check all indices appear
          values = [
              v if isinstance(v, list) else [v]
              for v in parameter_names.values()
          ]
          values = [item for sublist in values for item in sublist]
          values = set(values)
          msg = f"not all values appear -- set should be 0 to {ndim-1}"
          assert values == set(np.arange(ndim)), msg
          self.parameter_names = parameter_names
  
imports: import warnings
  from itertools import count
  from typing import Dict, List, Optional, Union
  import numpy
  from .backends import Backend
  from .model import Model
  from .moves import StretchMove
  from .pbar import get_progress_bar
  from .state import State
  from .utils import deprecated, deprecation_warning
label_desc: Use image node_id 1 to create a new EnsembleSampler object from inherited base classes: object with example: obj = EnsembleSampler(nwalkers, ndim, log_prob_fn, pool, moves, args, kwargs, backend, vectorize, blobs_dtype, parameter_names, a, postargs, threads, live_dangerously, runtime_sortingfn)