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

Generalized plot_posterior to plot vector-valued variables #1440

Merged
merged 2 commits into from
Oct 12, 2016

Conversation

fonnesbeck
Copy link
Member

This is a refactor of plot_posterior that accepts vector-valued parameters. I will add a test, but please test it on your favorite example.

Closes #1131

@ColCarroll
Copy link
Member

Cool! Works on occupancy example -- changing n=100 to n = (2, 100) in the setUp creates 200 plots for z, which seems correct.

Maybe a warning for too many plots? Or an implicit upper bound?

@fonnesbeck
Copy link
Member Author

We don't warn users for other plots, so I wouldn't put one here. If we think that's something we ought to have then it's probably best implemented module-wide in a separate PR.

Copy link
Contributor

@springcoil springcoil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see nothing wrong with this fix. Maybe @ColCarroll has some objections though.

@ColCarroll
Copy link
Member

No, this looks good -- @fonnesbeck should we wait for a test or merge now? I was using the test below, if that helps.

import pymc3 as pm
import numpy as np

def test_plot_posterior(self):
    n = (2, 100)
    theta = 2.1
    pi = 0.4
    y = (np.random.random(n) < pi) * np.random.poisson(lam=theta, size=n)

    with pm.Model() as model:
        psi = pm.Beta('psi', 1, 1)
        pm.Bernoulli('z', psi, y.shape)
        theta = pm.Uniform('theta', 0, 100)
        pm.ZeroInflatedPoisson('y', theta, psi, observed=y)
        start = {'psi': 0.5, 'z': (y > 0).astype(int), 'theta': 5}
        step_one = pm.Metropolis([model.theta_interval_, model.psi_logodds_])
        step_two = pm.BinaryMetropolis([model.z])
        tr = pm.sample(50, [step_one, step_two], start)

    # should produce a plot for each dimension of n
    plots = pm.plot_posterior(tr, varnames=['z'])
    self.assertEqual(plots.shape, (np.prod(n),))

@twiecki
Copy link
Member

twiecki commented Oct 12, 2016

I think we should add @ColCarroll's test.

@fonnesbeck
Copy link
Member Author

The added test should do it, and it uses an existing test model run.

@ColCarroll
Copy link
Member

Looks good to me -- will merge after travis passes

@ColCarroll ColCarroll merged commit 5b2b7f0 into master Oct 12, 2016
@ColCarroll ColCarroll deleted the plot_posterior_vector branch October 12, 2016 14:46
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.

4 participants