Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError: Unused step method arguments: {'target_accept'} #3914

Closed
ricardoV94 opened this issue May 6, 2020 · 3 comments
Closed

ValueError: Unused step method arguments: {'target_accept'} #3914

ricardoV94 opened this issue May 6, 2020 · 3 comments

Comments

@ricardoV94
Copy link
Member

ricardoV94 commented May 6, 2020

Sampling fails when I specify target_accept

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'}

Versions and main components

  • PyMC3 Version: 3.7 and 3.8
  • Theano Version:1.0.4
  • Python Version: 3.6.9
  • Platform: Google Colab
@AlexAndorra
Copy link
Contributor

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 🖖

@ricardoV94
Copy link
Member Author

Yes, that solves it!

@jonsedar
Copy link
Contributor

jonsedar commented May 6, 2020

Indeed - see the diff here :) https://github.com/pymc-devs/pymc3/pull/3908/files#diff-7eb6c4a83cfe45b9fc0eac76b57e2175

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants