Skip to content

Commit

Permalink
Add QuadPotentialFullAdapt in pm.sample init
Browse files Browse the repository at this point in the history
  • Loading branch information
techytushar committed Mar 27, 2020
1 parent 6699447 commit 7699f58
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pymc3/sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ def sample(
* advi_map: Initialize ADVI with MAP and use MAP as starting point.
* map: Use the MAP as starting point. This is discouraged.
* nuts: Run NUTS and estimate posterior mean and mass matrix from the trace.
* adapt_full: Adapt a dense mass matrix using the sample covariances
step: function or iterable of functions
A step function or collection of functions. If there are variables without step methods,
step methods for those variables will be assigned automatically. By default the NUTS step
Expand Down Expand Up @@ -1866,6 +1867,7 @@ def init_nuts(
* map: Use the MAP as starting point. This is discouraged.
* nuts: Run NUTS and estimate posterior mean and mass matrix from
the trace.
* adapt_full: Adapt a dense mass matrix using the sample covariances
chains: int
Number of jobs to start.
n_init: int
Expand Down Expand Up @@ -2006,6 +2008,14 @@ def init_nuts(
cov = np.atleast_1d(pm.trace_cov(init_trace))
start = list(np.random.choice(init_trace, chains))
potential = quadpotential.QuadPotentialFull(cov)
elif init == "adapt_full":
start = [model.test_point] * chains
mean = np.mean([model.dict_to_array(vals) for vals in start], axis=0)
init_trace = pm.sample(
draws=n_init, step=pm.NUTS(), tune=n_init // 2, random_seed=random_seed
)
cov = np.atleast_1d(pm.trace_cov(init_trace))
potential = quadpotential.QuadPotentialFullAdapt(model.ndim, mean, cov, 10)
else:
raise ValueError("Unknown initializer: {}.".format(init))

Expand Down

0 comments on commit 7699f58

Please sign in to comment.