Skip to content

Commit 7874295

Browse files
authored
Add QuadPotentialFullAdapt in pm.sample init (#3858)
1 parent 4972258 commit 7874295

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

RELEASE-NOTES.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- Add `fast_sample_posterior_predictive`, a vectorized alternative to `sample_posterior_predictive`. This alternative is substantially faster for large models.
1111
- `sample_posterior_predictive` can now feed on `xarray.Dataset` - e.g. from `InferenceData.posterior`. (see [#3846](https://github.com/pymc-devs/pymc3/pull/3846))
1212
- `SamplerReport` (`MultiTrace.report`) now has properties `n_tune`, `n_draws`, `t_sampling` for increased convenience (see [#3827](https://github.com/pymc-devs/pymc3/pull/3827))
13+
- `pm.sample` now has support for adapting dense mass matrix using `QuadPotentialFullAdapt` (see [#3596](https://github.com/pymc-devs/pymc3/pull/3596), [#3705](https://github.com/pymc-devs/pymc3/pull/3705) and [#3858](https://github.com/pymc-devs/pymc3/pull/3858))
1314

1415
### Maintenance
1516
- Remove `sample_ppc` and `sample_ppc_w` that were deprecated in 3.6.

pymc3/sampling.py

+7
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ def sample(
275275
* advi_map: Initialize ADVI with MAP and use MAP as starting point.
276276
* map: Use the MAP as starting point. This is discouraged.
277277
* nuts: Run NUTS and estimate posterior mean and mass matrix from the trace.
278+
* adapt_full: Adapt a dense mass matrix using the sample covariances
278279
step: function or iterable of functions
279280
A step function or collection of functions. If there are variables without step methods,
280281
step methods for those variables will be assigned automatically. By default the NUTS step
@@ -1866,6 +1867,7 @@ def init_nuts(
18661867
* map: Use the MAP as starting point. This is discouraged.
18671868
* nuts: Run NUTS and estimate posterior mean and mass matrix from
18681869
the trace.
1870+
* adapt_full: Adapt a dense mass matrix using the sample covariances
18691871
chains: int
18701872
Number of jobs to start.
18711873
n_init: int
@@ -2006,6 +2008,11 @@ def init_nuts(
20062008
cov = np.atleast_1d(pm.trace_cov(init_trace))
20072009
start = list(np.random.choice(init_trace, chains))
20082010
potential = quadpotential.QuadPotentialFull(cov)
2011+
elif init == "adapt_full":
2012+
start = [model.test_point] * chains
2013+
mean = np.mean([model.dict_to_array(vals) for vals in start], axis=0)
2014+
cov = np.ones((model.ndim, model.ndim))
2015+
potential = quadpotential.QuadPotentialFullAdapt(model.ndim, mean, cov, 10)
20092016
else:
20102017
raise ValueError("Unknown initializer: {}.".format(init))
20112018

0 commit comments

Comments
 (0)