Skip to content

Create helper pm.draw() to take draws from a given variable #5311

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

Closed
ricardoV94 opened this issue Jan 5, 2022 · 3 comments · Fixed by #5340
Closed

Create helper pm.draw() to take draws from a given variable #5311

ricardoV94 opened this issue Jan 5, 2022 · 3 comments · Fixed by #5340

Comments

@ricardoV94
Copy link
Member

ricardoV94 commented Jan 5, 2022

eval() should be aliased to something more intuitive like sample() or draw() where appropriate.

We have been using eval in our examples as a substitute to the old random method. This is just the standard Aesara debug feature that exists for any node, and shouldn't be used for more than that.

We can have a function wrapper that compiles a "proper" aesara function and takes a given number of draws. For analogy with V3 it could be named pm.random, but I like the pm.draw name better.

with pm.Model() as m:
  x = pm.Normal("x")

x_draws = pm.draw(x, draws=100)

Adding default updates to RNGs could then more justifiable be done in pymc.aesaraf.compile_pymc which already does this for Simulator variables anyway, and which pm.random/ pm.draw would call. That would be one less thing that Distribution has to be concerned with.

# Set the default update of a NoDistribution RNG so that it is automatically

Originally posted by @ricardoV94 in #5308 (comment)

@danhphan
Copy link
Member

danhphan commented Jan 8, 2022

Hi @ricardoV94, I would like to work on this task. Could you please give some more detailed suggestions (like which file should we put the pm.draw function wrapper, and is there a similar wrapper function to follow). Thank you.

@ricardoV94 ricardoV94 added this to the v4.0.0b3 milestone Jan 8, 2022
@ricardoV94
Copy link
Member Author

ricardoV94 commented Jan 8, 2022

Hi @ricardoV94, I would like to work on this task. Could you please give some more detailed suggestions (like which file should we put the pm.draw function wrapper, and is there a similar wrapper function to follow). Thank you.

Thanks for offering. I assigned the issue to you.

Good question about where it should go... sampling.py perhaps? This is basically a striped down version of prior_predictive. @fonnesbeck what do you think?

A rough sketch of what it could look like:

def draw(vars, draws=1, mode=None, **kwargs):
  if not isinstance(vars, (list, tuple)):
    vars = [vars]
  f = pm.aesaraf.compile_pymc([], vars, mode=mode, **kwargs)
  return [f() for _ in range(draws)]

Type hints would be a nice plus

@danhphan
Copy link
Member

danhphan commented Jan 8, 2022

Hi yes, thank you for the suggestion.

I am setting up the dev environment with docker and start reading the sample_prior_predictive function in sampling.py and related files. I will let you know if I face any issue :)

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

Successfully merging a pull request may close this issue.

2 participants