Code:
with pm.Model() as m:
prior_mu = 30
prior_sd = 15
prior_size = -prior_mu**2 / (prior_mu - prior_sd ** 2)
n_socks = pm.NegativeBinomial('n_socks', prior_mu, prior_size)
prop_pairs = pm.Beta('prop_pairs', 15, 2)
n_pairs = pm.Deterministic('n_pairs', pm.math.floor(pm.math.floor(n_socks / 2) * prop_pairs))
n_odd = pm.Deterministic('n_odd', n_socks - (n_pairs * 2))
post = pm.sample(500, target_accept=0.95)
Same error happens with:
post = pm.sample(500, nuts_kwargs=dict(target_accept=0.95))
If I don't specify the target_accept, it runs fine:
Sequential sampling (2 chains in 1 job)
CompoundStep
>Metropolis: [n_socks]
>NUTS: [prop_pairs]
100%|鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅| 1000/1000 [00:00<00:00, 1376.44it/s]
100%|鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅| 1000/1000 [00:00<00:00, 1485.11it/s]
The gelman-rubin statistic is larger than 1.05 for some parameters. This indicates slight problems during sampling.
The estimated number of effective samples is smaller than 200 for some parameters.
Full traceback:
ValueError Traceback (most recent call last)
<ipython-input-21-f8cb4dc74d3d> in <module>()
10 n_odd = pm.Deterministic('n_odd', n_socks - (n_pairs * 2))
11
---> 12 post = pm.sample(500, target_accept=.95)
2 frames
/usr/local/lib/python3.6/dist-packages/pymc3/sampling.py in sample(draws, step, init, n_init, start, trace, chain_idx, chains, cores, tune, progressbar, model, random_seed, discard_tuned_samples, compute_convergence_checks, **kwargs)
404 step = assign_step_methods(model, step, step_kwargs=kwargs)
405 else:
--> 406 step = assign_step_methods(model, step, step_kwargs=kwargs)
407
408 if isinstance(step, list):
/usr/local/lib/python3.6/dist-packages/pymc3/sampling.py in assign_step_methods(model, step, methods, step_kwargs)
153 selected_steps[selected].append(var)
154
--> 155 return instantiate_steppers(model, steps, selected_steps, step_kwargs)
156
157
/usr/local/lib/python3.6/dist-packages/pymc3/sampling.py in instantiate_steppers(model, steps, selected_steps, step_kwargs)
79 unused_args = set(step_kwargs).difference(used_keys)
80 if unused_args:
---> 81 raise ValueError('Unused step method arguments: %s' % unused_args)
82
83 if len(steps) == 1:
ValueError: Unused step method arguments: {'target_accept'}
Hi Ricardo,
Yeah, it's because of the Compound Step, so you need to access NUTS step method directly, with a dict set to a lower case version of the step method's name.
Current docs are indeed unclear about that, but @jonsedar brought nice clarifications to the docstrings in a recent PR.
Basically, post = pm.sample(500, nuts={'target_accept':0.95}) should do the trick.
Tell me if this works, and if yes I'll close 馃枛
Yes, that solves it!
Indeed - see the diff here :) https://github.com/pymc-devs/pymc3/pull/3908/files#diff-7eb6c4a83cfe45b9fc0eac76b57e2175
Most helpful comment
Indeed - see the diff here :) https://github.com/pymc-devs/pymc3/pull/3908/files#diff-7eb6c4a83cfe45b9fc0eac76b57e2175