Skip to content

Commit fbb817a

Browse files
committed
3962 issue fixed
1 parent f93b5e7 commit fbb817a

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

pymc3/distributions/distribution.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,7 @@ def draw_values(params, point=None, size=None):
559559
# draw_values in the context of sample_posterior_predictive
560560
ppc_sampler = vectorized_ppc.get(None)
561561
if ppc_sampler is not None:
562+
562563
# this is being done inside new, vectorized sample_posterior_predictive
563564
return ppc_sampler(params, trace=point, samples=size)
564565

@@ -592,7 +593,6 @@ def draw_values(params, point=None, size=None):
592593
else:
593594
# param still needs to be drawn
594595
symbolic_params.append((i, p))
595-
596596
if not symbolic_params:
597597
# We only need to enforce the correct order if there are symbolic
598598
# params that could be drawn in variable order
@@ -818,6 +818,7 @@ def _draw_value(param, point=None, givens=None, size=None):
818818
if point and hasattr(param, 'model') and param.name in point:
819819
return point[param.name]
820820
elif hasattr(param, 'random') and param.random is not None:
821+
print(point)
821822
return param.random(point=point, size=size)
822823
elif (hasattr(param, 'distribution') and
823824
hasattr(param.distribution, 'random') and
@@ -995,7 +996,7 @@ def generate_samples(generator, *args, **kwargs):
995996
else:
996997
samples = generator(size=size_tup + dist_bcast_shape, *args, **kwargs)
997998
samples = np.asarray(samples)
998-
999+
9991000
# reshape samples here
10001001
if samples.ndim > 0 and samples.shape[0] == 1 and size_tup == (1,):
10011002
if (len(samples.shape) > len(dist_shape) and
@@ -1009,4 +1010,5 @@ def generate_samples(generator, *args, **kwargs):
10091010
size_tup == (1,))
10101011
):
10111012
samples = samples.reshape(samples.shape[:-1])
1013+
print("samples:",samples)
10121014
return np.asarray(samples)

pymc3/distributions/timeseries.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from scipy import stats
1818
import theano.tensor as tt
1919
from theano import scan
20+
import numpy as np
2021

2122
from pymc3.util import get_variable_name
2223
from .continuous import get_tau_sigma, Normal, Flat
@@ -293,6 +294,7 @@ def random(self, point=None, size=None):
293294
sigma, mu = distribution.draw_values(
294295
[self.sigma, self.mu], point=point, size=size
295296
)
297+
296298
return distribution.generate_samples(
297299
self._random,
298300
sigma=sigma,
@@ -309,8 +311,14 @@ def _random(self, sigma, mu, size, sample_shape):
309311
else:
310312
axis = 0
311313
rv = stats.norm(mu, sigma)
312-
data = rv.rvs(size).cumsum(axis=axis)
313-
data = data - data[0] # TODO: this should be a draw from `init`, if available
314+
if len(size) == 1:
315+
data = rv.rvs(size).cumsum(axis=axis)
316+
data = data - data[0] # TODO: this should be a draw from `init`, if available
317+
else:
318+
data = np.empty(size)
319+
for i in range(size[0]):
320+
data[i]=rv.rvs((size[1],)).cumsum(axis=axis)
321+
data[i]=data[i] - data[i][0]
314322
return data
315323

316324
def _repr_latex_(self, name=None, dist=None):

pymc3/sampling.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1825,6 +1825,7 @@ def sample_prior_predictive(
18251825
samples.
18261826
"""
18271827
model = modelcontext(model)
1828+
18281829

18291830
if vars is None and var_names is None:
18301831
prior_pred_vars = model.observed_RVs
@@ -1842,15 +1843,17 @@ def sample_prior_predictive(
18421843
else:
18431844
raise ValueError("Cannot supply both vars and var_names arguments.")
18441845
vars = cast(TIterable[str], vars) # tell mypy that vars cannot be None here.
1846+
18451847

18461848
if random_seed is not None:
18471849
np.random.seed(random_seed)
18481850
names = get_default_varnames(vars_, include_transformed=False)
18491851
# draw_values fails with auto-transformed variables. transform them later!
18501852
values = draw_values([model[name] for name in names], size=samples)
1853+
18511854

18521855
data = {k: v for k, v in zip(names, values)}
1853-
if data is None:
1856+
if data is None:
18541857
raise AssertionError("No variables sampled: attempting to sample %s" % names)
18551858

18561859
prior = {} # type: Dict[str, np.ndarray]

0 commit comments

Comments
 (0)