Skip to content

Commit bdc9966

Browse files
ColCarrolljunpenglao
authored andcommitted
Sample ppc does not shuffle by default (#3212)
* Sample ppc does not shuffle by default * Cycle through ppc samples
1 parent b2bf28a commit bdc9966

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

RELEASE-NOTES.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66

77
- Track the model log-likelihood as a sampler stat for NUTS and HMC samplers
88
(accessible as `trace.get_sampler_stats('model_logp')`) (#3134)
9-
- Add Incomplete Beta function `incomplete_beta(a, b, value)`
9+
- Add Incomplete Beta function `incomplete_beta(a, b, value)`
1010
- Add log CDF functions to continuous distributions: `Beta`, `Cauchy`, `ExGaussian`, `Exponential`, `Flat`, `Gumbel`, `HalfCauchy`, `HalfFlat`, `HalfNormal`, `Laplace`, `Logistic`, `Lognormal`, `Normal`, `Pareto`, `StudentT`, `Triangular`, `Uniform`, `Wald`, `Weibull`.
11+
- Behavior of `sample_posterior_predictive` is now to produce posterior predictive samples, in order, from all values of the `trace`. Previously, by default it would produce 1 chain worth of samples, using a random selection from the `trace` (#3212)
1112

1213
### Maintenance
1314

pymc3/sampling.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,7 @@ def sample_posterior_predictive(trace, samples=None, model=None, vars=None, size
10981098
nchain = 1
10991099

11001100
if samples is None:
1101-
samples = len(trace)
1101+
samples = sum(len(v) for v in trace._straces.values())
11021102

11031103
model = modelcontext(model)
11041104

@@ -1108,7 +1108,7 @@ def sample_posterior_predictive(trace, samples=None, model=None, vars=None, size
11081108
if random_seed is not None:
11091109
np.random.seed(random_seed)
11101110

1111-
indices = np.random.randint(0, nchain * len_trace, samples)
1111+
indices = np.arange(samples)
11121112

11131113
if progressbar:
11141114
indices = tqdm(indices, total=samples)
@@ -1126,9 +1126,9 @@ def sample_posterior_predictive(trace, samples=None, model=None, vars=None, size
11261126
for slc, idx in enumerate(indices):
11271127
if nchain > 1:
11281128
chain_idx, point_idx = np.divmod(idx, len_trace)
1129-
param = trace._straces[chain_idx].point(point_idx)
1129+
param = trace._straces[chain_idx % nchain].point(point_idx)
11301130
else:
1131-
param = trace[idx]
1131+
param = trace[idx % len_trace]
11321132

11331133
values = draw_values(vars, point=param, size=size)
11341134
for k, v in zip(vars, values):

0 commit comments

Comments
 (0)