@@ -253,7 +253,7 @@ def sample(
253
253
pickle_backend : str = "pickle" ,
254
254
** kwargs ,
255
255
):
256
- """Draw samples from the posterior using the given step methods.
256
+ r """Draw samples from the posterior using the given step methods.
257
257
258
258
Multiple step methods are supported via compound step methods.
259
259
@@ -330,7 +330,6 @@ def sample(
330
330
called with the trace and the current draw and will contain all samples for a single trace.
331
331
the ``draw.chain`` argument can be used to determine which of the active chains the sample
332
332
is drawn from.
333
-
334
333
Sampling can be interrupted by throwing a ``KeyboardInterrupt`` in the callback.
335
334
return_inferencedata : bool, default=False
336
335
Whether to return the trace as an :class:`arviz:arviz.InferenceData` (True) object or a `MultiTrace` (False)
@@ -353,7 +352,7 @@ def sample(
353
352
Notes
354
353
-----
355
354
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.
357
356
358
357
If your model uses only one step method, you can address step method kwargs
359
358
directly. In particular, the NUTS step method has several options including:
@@ -368,49 +367,52 @@ def sample(
368
367
If your model uses multiple step methods, aka a Compound Step, then you have
369
368
two ways to address arguments to each step method:
370
369
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)]
391
393
392
394
You can find a full list of arguments in the docstring of the step methods.
393
395
394
396
Examples
395
397
--------
396
398
.. code:: ipython
397
399
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
403
405
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()
405
410
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")
413
412
413
+ Out[3]:
414
+ mean sd hdi_3% hdi_97%
415
+ p 0.609 0.047 0.528 0.699
414
416
"""
415
417
model = modelcontext (model )
416
418
if start is None :
@@ -1982,7 +1984,7 @@ def init_nuts(
1982
1984
* map: Use the MAP as starting point. This is discouraged.
1983
1985
* adapt_full: Adapt a dense mass matrix using the sample covariances. All chains use the
1984
1986
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
1986
1988
[-1, 1] as starting point in each chain.
1987
1989
1988
1990
chains : int
0 commit comments