pymc icon indicating copy to clipboard operation
pymc copied to clipboard

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

Open canyon289 opened this issue 3 years ago • 1 comments

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)

canyon289 avatar Jul 12 '22 14:07 canyon289

I believe the solution to this issue is closing https://github.com/pymc-devs/pymc/issues/5775

OriolAbril avatar Jul 15 '22 08:07 OriolAbril

#6029 closes this, I believe :)

thomasaarholt avatar Nov 27 '22 13:11 thomasaarholt

Yep, thanks

OriolAbril avatar Nov 27 '22 17:11 OriolAbril