@@ -253,7 +253,7 @@ def sample(
253253 pickle_backend : str = "pickle" ,
254254 ** kwargs ,
255255):
256- """Draw samples from the posterior using the given step methods.
256+ r """Draw samples from the posterior using the given step methods.
257257
258258 Multiple step methods are supported via compound step methods.
259259
@@ -330,7 +330,6 @@ def sample(
330330 called with the trace and the current draw and will contain all samples for a single trace.
331331 the ``draw.chain`` argument can be used to determine which of the active chains the sample
332332 is drawn from.
333-
334333 Sampling can be interrupted by throwing a ``KeyboardInterrupt`` in the callback.
335334 return_inferencedata : bool, default=False
336335 Whether to return the trace as an :class:`arviz:arviz.InferenceData` (True) object or a `MultiTrace` (False)
@@ -353,7 +352,7 @@ def sample(
353352 Notes
354353 -----
355354 Optional keyword arguments can be passed to ``sample`` to be delivered to the
356- ``step_method``s used during sampling.
355+ ``step_method``\ s used during sampling.
357356
358357 If your model uses only one step method, you can address step method kwargs
359358 directly. In particular, the NUTS step method has several options including:
@@ -368,49 +367,52 @@ def sample(
368367 If your model uses multiple step methods, aka a Compound Step, then you have
369368 two ways to address arguments to each step method:
370369
371- A: If you let ``sample()`` automatically assign the ``step_method``s,
372- and you can correctly anticipate what they will be, then you can wrap
373- step method kwargs in a dict and pass that to sample() with a kwarg set
374- to the name of the step method.
375- e.g. for a CompoundStep comprising NUTS and BinaryGibbsMetropolis,
376- you could send:
377- 1. ``target_accept`` to NUTS: nuts={'target_accept':0.9}
378- 2. ``transit_p`` to BinaryGibbsMetropolis: binary_gibbs_metropolis={'transit_p':.7}
379-
380- Note that available names are:
381- ``nuts``, ``hmc``, ``metropolis``, ``binary_metropolis``,
382- ``binary_gibbs_metropolis``, ``categorical_gibbs_metropolis``,
383- ``DEMetropolis``, ``DEMetropolisZ``, ``slice``
384-
385- B: If you manually declare the ``step_method``s, within the ``step``
386- kwarg, then you can address the ``step_method`` kwargs directly.
387- e.g. for a CompoundStep comprising NUTS and BinaryGibbsMetropolis,
388- you could send:
389- step=[pm.NUTS([freeRV1, freeRV2], target_accept=0.9),
390- pm.BinaryGibbsMetropolis([freeRV3], transit_p=.7)]
370+ A. If you let ``sample()`` automatically assign the ``step_method``\ s,
371+ and you can correctly anticipate what they will be, then you can wrap
372+ step method kwargs in a dict and pass that to sample() with a kwarg set
373+ to the name of the step method.
374+ e.g. for a CompoundStep comprising NUTS and BinaryGibbsMetropolis,
375+ you could send:
376+
377+ 1. ``target_accept`` to NUTS: nuts={'target_accept':0.9}
378+ 2. ``transit_p`` to BinaryGibbsMetropolis: binary_gibbs_metropolis={'transit_p':.7}
379+
380+ Note that available names are:
381+
382+ ``nuts``, ``hmc``, ``metropolis``, ``binary_metropolis``,
383+ ``binary_gibbs_metropolis``, ``categorical_gibbs_metropolis``,
384+ ``DEMetropolis``, ``DEMetropolisZ``, ``slice``
385+
386+ B. If you manually declare the ``step_method``\ s, within the ``step``
387+ kwarg, then you can address the ``step_method`` kwargs directly.
388+ e.g. for a CompoundStep comprising NUTS and BinaryGibbsMetropolis,
389+ you could send ::
390+
391+ step=[pm.NUTS([freeRV1, freeRV2], target_accept=0.9),
392+ pm.BinaryGibbsMetropolis([freeRV3], transit_p=.7)]
391393
392394 You can find a full list of arguments in the docstring of the step methods.
393395
394396 Examples
395397 --------
396398 .. code:: ipython
397399
398- >>> import pymc3 as pm
399- ... n = 100
400- ... h = 61
401- ... alpha = 2
402- ... beta = 2
400+ In [1]: import pymc3 as pm
401+ ...: n = 100
402+ ...: h = 61
403+ ...: alpha = 2
404+ ...: beta = 2
403405
404- .. code:: ipython
406+ In [2]: with pm.Model() as model: # context management
407+ ...: p = pm.Beta("p", alpha=alpha, beta=beta)
408+ ...: y = pm.Binomial("y", n=n, p=p, observed=h)
409+ ...: trace = pm.sample()
405410
406- >>> with pm.Model() as model: # context management
407- ... p = pm.Beta('p', alpha=alpha, beta=beta)
408- ... y = pm.Binomial('y', n=n, p=p, observed=h)
409- ... trace = pm.sample()
410- >>> pm.summary(trace)
411- mean sd mc_error hpd_2.5 hpd_97.5
412- p 0.604625 0.047086 0.00078 0.510498 0.694774
411+ In [3]: pm.summary(trace, kind="stats")
413412
413+ Out[3]:
414+ mean sd hdi_3% hdi_97%
415+ p 0.609 0.047 0.528 0.699
414416 """
415417 model = modelcontext (model )
416418 if start is None :
@@ -1982,7 +1984,7 @@ def init_nuts(
19821984 * map: Use the MAP as starting point. This is discouraged.
19831985 * adapt_full: Adapt a dense mass matrix using the sample covariances. All chains use the
19841986 test value (usually the prior mean) as starting point.
1985- * jitter+adapt_full: Same as ``adapt_full`, but use test value plus a uniform jitter in
1987+ * jitter+adapt_full: Same as ``adapt_full`` , but use test value plus a uniform jitter in
19861988 [-1, 1] as starting point in each chain.
19871989
19881990 chains : int
0 commit comments