Skip to content

Commit 817f457

Browse files
committed
Remove size parameter from sample_posterior_predictive
1 parent 862bd05 commit 817f457

File tree

2 files changed

+2
-34
lines changed

2 files changed

+2
-34
lines changed

pymc/sampling.py

+2-11
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858

5959
import pymc as pm
6060

61-
from pymc.aesaraf import change_rv_size, compile_pymc
61+
from pymc.aesaraf import compile_pymc
6262
from pymc.backends.arviz import _DefaultTrace
6363
from pymc.backends.base import BaseTrace, MultiTrace
6464
from pymc.backends.ndarray import NDArray
@@ -1688,7 +1688,6 @@ def sample_posterior_predictive(
16881688
samples: Optional[int] = None,
16891689
model: Optional[Model] = None,
16901690
var_names: Optional[List[str]] = None,
1691-
size: Optional[int] = None,
16921691
keep_size: Optional[bool] = None,
16931692
random_seed=None,
16941693
progressbar: bool = True,
@@ -1721,13 +1720,9 @@ def sample_posterior_predictive(
17211720
generally be the model used to generate the ``trace``, but it doesn't need to be.
17221721
var_names : Iterable[str]
17231722
Names of variables for which to compute the posterior predictive samples.
1724-
size : int
1725-
The number of random draws from the distribution specified by the parameters in each
1726-
sample of the trace. Not recommended unless more than ndraws times nchains posterior
1727-
predictive samples are needed.
17281723
keep_size : bool, default True
17291724
Force posterior predictive sample to have the same shape as posterior and sample stats
1730-
data: ``(nchains, ndraws, ...)``. Overrides samples and size parameters.
1725+
data: ``(nchains, ndraws, ...)``. Overrides samples parameter.
17311726
random_seed : int
17321727
Seed for the random number generator.
17331728
progressbar : bool
@@ -1806,8 +1801,6 @@ def sample_posterior_predictive(
18061801
"Should not specify both keep_size and samples arguments. "
18071802
"See the docstring of the samples argument for more details."
18081803
)
1809-
if keep_size and size is not None:
1810-
raise IncorrectArgumentsError("Should not specify both keep_size and size arguments")
18111804

18121805
if samples is None:
18131806
if isinstance(_trace, MultiTrace):
@@ -1867,8 +1860,6 @@ def sample_posterior_predictive(
18671860
return trace
18681861
return {}
18691862

1870-
if size is not None:
1871-
vars_to_sample = [change_rv_size(v, size, expand=True) for v in vars_to_sample]
18721863
vars_in_trace = get_vars_in_point_list(_trace, model)
18731864

18741865
if compile_kwargs is None:

pymc/tests/test_sampling.py

-23
Original file line numberDiff line numberDiff line change
@@ -536,13 +536,6 @@ def test_normal_scalar(self):
536536
_, pval = stats.kstest(ppc["a"] - trace["mu"], stats.norm(loc=0, scale=1).cdf)
537537
assert pval > 0.001
538538

539-
# size argument not introduced to fast version [2019/08/20:rpg]
540-
with model:
541-
ppc = pm.sample_posterior_predictive(
542-
trace, size=5, var_names=["a"], return_inferencedata=False
543-
)
544-
assert ppc["a"].shape == (nchains * ndraws, 5)
545-
546539
def test_normal_scalar_idata(self):
547540
nchains = 2
548541
ndraws = 500
@@ -599,13 +592,6 @@ def test_normal_vector(self, caplog):
599592
assert "a" in ppc
600593
assert ppc["a"].shape == (12, 2)
601594

602-
# size unsupported by fast_ version argument. [2019/08/19:rpg]
603-
ppc = pm.sample_posterior_predictive(
604-
trace, return_inferencedata=False, samples=10, var_names=["a"], size=4
605-
)
606-
assert "a" in ppc
607-
assert ppc["a"].shape == (10, 4, 2)
608-
609595
def test_normal_vector_idata(self, caplog):
610596
with pm.Model() as model:
611597
mu = pm.Normal("mu", 0.0, 1.0)
@@ -632,9 +618,6 @@ def test_exceptions(self, caplog):
632618
with pytest.raises(IncorrectArgumentsError):
633619
ppc = pm.sample_posterior_predictive(idata, samples=10, keep_size=True)
634620

635-
with pytest.raises(IncorrectArgumentsError):
636-
ppc = pm.sample_posterior_predictive(idata, size=4, keep_size=True)
637-
638621
# test wrong type argument
639622
bad_trace = {"mu": stats.norm.rvs(size=1000)}
640623
with pytest.raises(TypeError, match="type for `trace`"):
@@ -658,12 +641,6 @@ def test_vector_observed(self):
658641
assert "a" in ppc
659642
assert ppc["a"].shape == (12, 2)
660643

661-
ppc = pm.sample_posterior_predictive(
662-
idata, return_inferencedata=False, samples=10, var_names=["a"], size=4
663-
)
664-
assert "a" in ppc
665-
assert ppc["a"].shape == (10, 4, 2)
666-
667644
def test_sum_normal(self):
668645
with pm.Model() as model:
669646
a = pm.Normal("a", sigma=0.2)

0 commit comments

Comments
 (0)