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","``","."]
docstr: Advance the chain as a generator
  
  Args:
      initial_state (State or ndarray[nwalkers, ndim]): The initial
          :class:`State` or positions of the walkers in the
          parameter space.
      iterations (Optional[int or NoneType]): The number of steps to generate.
          ``None`` generates an infinite stream (requires ``store=False``).
      tune (Optional[bool]): If ``True``, the parameters of some moves
          will be automatically tuned.
      thin_by (Optional[int]): If you only want to store and yield every
          ``thin_by`` samples in the chain, set ``thin_by`` to an
          integer greater than 1. When this is set, ``iterations *
          thin_by`` proposals will be made.
      store (Optional[bool]): By default, the sampler stores (in memory)
          the positions and log-probabilities of the samples in the
          chain. If you are using another method to store the samples to
          a file or if you don't need to analyze the samples after the
          fact (for burn-in for example) set ``store`` to ``False``.
      progress (Optional[bool or str]): If ``True``, a progress bar will
          be shown as the sampler progresses. If a string, will select a
          specific ``tqdm`` progress bar - most notable is
          ``'notebook'``, which shows a progress bar suitable for
          Jupyter notebooks.  If ``False``, no progress bar will be
          shown.
      progress_kwargs (Optional[dict]): A ``dict`` of keyword arguments
          to be passed to the tqdm call.
      skip_initial_state_check (Optional[bool]): If ``True``, a check
          that the initial_state can fully explore the space will be
          skipped. (default: ``False``)
  
  
  Every ``thin_by`` steps, this generator yields the
  :class:`State` of the ensemble.
code: def sample(
      self,
      initial_state,
      log_prob0=None,  # Deprecated
      rstate0=None,  # Deprecated
      blobs0=None,  # Deprecated
      iterations=1,
      tune=False,
      skip_initial_state_check=False,
      thin_by=1,
      thin=None,
      store=True,
      progress=False,
      progress_kwargs=None,
  ):
      """Advance the chain as a generator
  
      Args:
          initial_state (State or ndarray[nwalkers, ndim]): The initial
              :class:`State` or positions of the walkers in the
              parameter space.
          iterations (Optional[int or NoneType]): The number of steps to generate.
              ``None`` generates an infinite stream (requires ``store=False``).
          tune (Optional[bool]): If ``True``, the parameters of some moves
              will be automatically tuned.
          thin_by (Optional[int]): If you only want to store and yield every
              ``thin_by`` samples in the chain, set ``thin_by`` to an
              integer greater than 1. When this is set, ``iterations *
              thin_by`` proposals will be made.
          store (Optional[bool]): By default, the sampler stores (in memory)
              the positions and log-probabilities of the samples in the
              chain. If you are using another method to store the samples to
              a file or if you don't need to analyze the samples after the
              fact (for burn-in for example) set ``store`` to ``False``.
          progress (Optional[bool or str]): If ``True``, a progress bar will
              be shown as the sampler progresses. If a string, will select a
              specific ``tqdm`` progress bar - most notable is
              ``'notebook'``, which shows a progress bar suitable for
              Jupyter notebooks.  If ``False``, no progress bar will be
              shown.
          progress_kwargs (Optional[dict]): A ``dict`` of keyword arguments
              to be passed to the tqdm call.
          skip_initial_state_check (Optional[bool]): If ``True``, a check
              that the initial_state can fully explore the space will be
              skipped. (default: ``False``)
  
  
      Every ``thin_by`` steps, this generator yields the
      :class:`State` of the ensemble.
  
      """
      if iterations is None and store:
          raise ValueError(
              "'store' must be False when 'iterations' is None"
          )
      # Interpret the input as a walker state and check the dimensions.
      state = State(initial_state, copy=True)
      state_shape = np.shape(state.coords)
      if state_shape != (self.nwalkers, self.ndim):
          raise ValueError(
              f"incompatible input dimensions {state_shape}"
          )
      if (not skip_initial_state_check) and (
          not walkers_independent(state.coords)
      ):
          raise ValueError(
              "Initial state has a large condition number. "
              "Make sure that your walkers are linearly independent for the "
              "best performance"
          )
  
      # Try to set the initial value of the random number generator. This
      # fails silently if it doesn't work but that's what we want because
      # we'll just interpret any garbage as letting the generator stay in
      # it's current state.
      if rstate0 is not None:
          deprecation_warning(
              "The 'rstate0' argument is deprecated, use a 'State' "
              "instead"
          )
          state.random_state = rstate0
      self.random_state = state.random_state
  
      # If the initial log-probabilities were not provided, calculate them
      # now.
      if log_prob0 is not None:
          deprecation_warning(
              "The 'log_prob0' argument is deprecated, use a 'State' "
              "instead"
          )
          state.log_prob = log_prob0
      if blobs0 is not None:
          deprecation_warning(
              "The 'blobs0' argument is deprecated, use a 'State' instead"
          )
          state.blobs = blobs0
      if state.log_prob is None:
          state.log_prob, state.blobs = self.compute_log_prob(
              state.coords
          )
      if np.shape(state.log_prob) != (self.nwalkers,):
          raise ValueError("incompatible input dimensions")
  
      # Check to make sure that the probability function didn't return
      # ``np.nan``.
      if np.any(np.isnan(state.log_prob)):
          raise ValueError("The initial log_prob was NaN")
  
      # Deal with deprecated thin argument
      if thin is not None:
          deprecation_warning(
              "The 'thin' argument is deprecated. "
              "Use 'thin_by' instead."
          )
  
          # Check that the thin keyword is reasonable.
          thin = int(thin)
          if thin <= 0:
              raise ValueError("Invalid thinning argument")
  
          yield_step = 1
          checkpoint_step = thin
          if store:
              nsaves = iterations // checkpoint_step
              self.backend.grow(nsaves, state.blobs)
  
      else:
          # Check that the thin keyword is reasonable.
          thin_by = int(thin_by)
          if thin_by <= 0:
              raise ValueError("Invalid thinning argument")
  
          yield_step = thin_by
          checkpoint_step = thin_by
          if store:
              self.backend.grow(iterations, state.blobs)
  
      # Set up a wrapper around the relevant model functions
      if self.pool is not None:
          map_fn = self.pool.map
      else:
          map_fn = map
      model = Model(
          self.log_prob_fn, self.compute_log_prob, map_fn, self._random
      )
      if progress_kwargs is None:
          progress_kwargs = {}
  
      # Inject the progress bar
      total = None if iterations is None else iterations * yield_step
      with get_progress_bar(progress, total, **progress_kwargs) as pbar:
          i = 0
          for _ in count() if iterations is None else range(iterations):
              for _ in range(yield_step):
                  # Choose a random move
                  move = self._random.choice(
                      self._moves, p=self._weights
                  )
  
                  # Propose
                  state, accepted = move.propose(model, state)
                  state.random_state = self.random_state
  
                  if tune:
                      move.tune(state, accepted)
  
                  # Save the new step
                  if store and (i + 1) % checkpoint_step == 0:
                      self.backend.save_step(state, accepted)
  
                  pbar.update(1)
                  i += 1
  
              # Yield the result as an iterator so that the user can do all
              # sorts of fun stuff with the results so far.
              yield state
  
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 7 for calling the EnsembleSampler obj's underlying member method code with example usage: obj.sample(initial_state, log_prob0, rstate0, blobs0, iterations, tune, skip_initial_state_check, thin_by, thin, store, progress, progress_kwargs) without return types