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

Compound/Gibbs step and discrete suppot #306

Merged
merged 139 commits into from
Aug 27, 2020
Merged

Conversation

rrkarim
Copy link
Contributor

@rrkarim rrkarim commented Jul 28, 2020

  • Add tests
  • Add Gibbs
  • Check on the performance for the one_step in compound sampler
  • Improve user design. First, make sampler_type the default for the model with discrete and continuous distributions.
  • Add logging as in pymc3
  • Fix seed
  • Fix the bug with merge of proposal funcs

@junpenglao junpenglao self-assigned this Jul 28, 2020
@rrkarim
Copy link
Contributor Author

rrkarim commented Jul 31, 2020

Here is the trivial example from sampling from pm.Categorical:

@pm.model
def categorical():
    var1 = yield pm.Categorical("var1", probs=[0.2, 0.4, 0.4])
    var1 = yield pm.Categorical("var2", probs=[0.1, 0.3, 0.2, 0.2, 0.2])
    var1 = yield pm.Categorical("var3", probs=[0.1, 0.1, 0.1, 0.1, 0.1, 0.5])
trace = pm.sample(categorical(), sampler_type="compound") 
# after the review default attribute should be compound and if there is no
# discrete variable in the model, we choose nuts as the sampler

image

I've included the notebook with discrete distributions: discrete_distributions_sampling.ipynb

@rrkarim
Copy link
Contributor Author

rrkarim commented Aug 1, 2020

Som results with different proposal generations for Poisson. I'm note sure about the poisson proposal generation though. Now it will be able to discover proper samples when scale is provided.

@pm.model
def model():
    var1 = yield pm.Poisson("var1", 4) # gaussian with round dist proposal
    var1 = yield pm.Poisson("var2", 4) # poisson dist proposal
    var2 = yield pm.Poisson("var3", 4) # continous space

trace = pm.sample(model(), 
                  sampler_type="compound", 
                  sampler_methods=[
                      ("var1", RandomWalkM, {"new_state_fn": gaussian_round_fn}),
                      ("var2", RandomWalkM, {"new_state_fn": functools.partial(poisson_fn, scale=4)}), # not sure if this is the right way to define proposal
                  ],
                  trace_discrete=["var1", "var2"])

image

pymc4/distributions/state_functions.py Outdated Show resolved Hide resolved
pymc4/distributions/state_functions.py Outdated Show resolved Hide resolved
@rrkarim
Copy link
Contributor Author

rrkarim commented Aug 8, 2020

@junpenglao Can you also suggest something better with the trace_discrete argument I've added to sample(). I don't like any additional argument, but it is the only way I can have discreteness in the plot for Poisson (see the Picture above). (tfd.Poisson can sample dtype tf.float32 points only, so delta should also be the same dtype)

@rrkarim rrkarim requested a review from junpenglao August 9, 2020 03:55
@junpenglao
Copy link
Member

@rrkarim is this ready for review? if so could you resolve the conflicts?

@junpenglao junpenglao merged commit 0f16a47 into pymc-devs:master Aug 27, 2020
@junpenglao
Copy link
Member

This is awesome contribution! Thanks and great job :-)

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

Successfully merging this pull request may close these issues.

3 participants