Skip to content

Make docstring for keep_size in Posterior predictive check be nicer, or turn it off by default #5971

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
canyon289 opened this issue Jul 12, 2022 · 3 comments

Comments

@canyon289
Copy link
Member

canyon289 commented Jul 12, 2022

Description of your problem

Getting an exception that I can't pass both samples=500 and keep_size=True cant both be provided, but as a user I only pass samples, and then get this exception which is then surprising.

    ppc = pm.sample_posterior_predictive(idata, samples=500, var_names=['f'])

Two ideas here

Idea 1

At minimum the docstring could be improved to explicitly say something like

"You passed both a sample size and keep_size=True. Did you mean to turn keep_size=False" or something like that, rather than forcing the user to then go find the docstring and go figure out to turn keep_size=False.

Idea 2

At best perhaps keep_size should automatically be turned off automatically since the user is passing a sample size. I dont know the implications of this one so not suggesting it as strongly as the docstring.

The model

The model doesnt really matter but here it is, the most relevant bit is at the bottom

data = pd.read_csv("data/co2_mm_mlo.csv", header=51)

subset = data.sort_values("decimal date").tail(12)
x = subset["decimal date"].values - subset["decimal date"].min()

y_mu = subset["average"].mean()
y_sd = subset["average"].std()
y = (subset["average"].values - y_mu) / y_sd

coords = {'time': subset['decimal date'].values}

with pm.Model(coords=coords) as model:
    
    eta = pm.HalfNormal('eta', sigma=1)
    ell = pm.Gamma('ell', alpha=2, beta=3)
    cov_eq = eta**2 * pm.gp.cov.Exponential(1, ls=ell)
    
    eta_per = pm.HalfNormal('eta_per', sigma=1)
    ell_per = pm.Gamma('ell_per', alpha=2, beta=3)
    cov_per = eta_per**2 * pm.gp.cov.Periodic(1, period=1.0, ls=ell_per)
        
    gp_eq = pm.gp.Marginal(cov_func=cov_eq)
    gp_per = pm.gp.Marginal(cov_func=cov_per)
    
    gp = gp_eq + gp_per
    
    sigma = pm.HalfNormal("sigma", sigma=1)
    lik = gp.marginal_likelihood("lik", X=x[:, None], y=y, noise=sigma, dims='time')
    
with model:
    idata = pm.sampling_jax.sample_blackjax_nuts()

xnew = np.linspace(np.min(x) - 1, np.max(x) + 1, 500)
with model:
    f = gp.conditional('f', Xnew=xnew[:, None], jitter=1e-4)

   # the line that matters
    ppc = pm.sample_posterior_predictive(idata, samples=500, var_names=['f'])
    
idata.extend(ppc)

Please provide the full traceback.

image

Please provide any additional information below.

Versions and main components

image

  • PyMC/PyMC3 Version:
  • Aesara/Theano Version:
  • Python Version:
  • Operating system:
  • How did you install PyMC/PyMC3: (conda/pip)
@OriolAbril
Copy link
Member

I believe the solution to this issue is closing #5775

@canyon289 canyon289 changed the title Make docstring for keep_size in Posterior predictive check be nicer, or turn it off by defaulkt Make docstring for keep_size in Posterior predictive check be nicer, or turn it off by default Jul 19, 2022
@thomasaarholt
Copy link
Contributor

#6029 closes this, I believe :)

@OriolAbril
Copy link
Member

Yep, thanks

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