Skip to content
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

Fix axis handling of randommethod in GRW #3985

Merged
merged 15 commits into from
Jul 24, 2020
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pymc3/distributions/distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,7 @@ def draw_values(params, point=None, size=None):
# draw_values in the context of sample_posterior_predictive
ppc_sampler = vectorized_ppc.get(None)
if ppc_sampler is not None:

# this is being done inside new, vectorized sample_posterior_predictive
return ppc_sampler(params, trace=point, samples=size)

Expand Down Expand Up @@ -592,7 +593,6 @@ def draw_values(params, point=None, size=None):
else:
# param still needs to be drawn
symbolic_params.append((i, p))

if not symbolic_params:
# We only need to enforce the correct order if there are symbolic
# params that could be drawn in variable order
Expand Down Expand Up @@ -995,7 +995,7 @@ def generate_samples(generator, *args, **kwargs):
else:
samples = generator(size=size_tup + dist_bcast_shape, *args, **kwargs)
samples = np.asarray(samples)

# reshape samples here
if samples.ndim > 0 and samples.shape[0] == 1 and size_tup == (1,):
if (len(samples.shape) > len(dist_shape) and
Expand Down
11 changes: 9 additions & 2 deletions pymc3/distributions/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from scipy import stats
import theano.tensor as tt
from theano import scan
import numpy as np

from pymc3.util import get_variable_name
from .continuous import get_tau_sigma, Normal, Flat
Expand Down Expand Up @@ -293,6 +294,7 @@ def random(self, point=None, size=None):
sigma, mu = distribution.draw_values(
[self.sigma, self.mu], point=point, size=size
)

return distribution.generate_samples(
self._random,
sigma=sigma,
Expand All @@ -307,10 +309,15 @@ def _random(self, sigma, mu, size, sample_shape):
if size[len(sample_shape)] == sample_shape:
axis = len(sample_shape)
else:
axis = 0
axis = len(size) - 1
rv = stats.norm(mu, sigma)
data = rv.rvs(size).cumsum(axis=axis)
data = data - data[0] # TODO: this should be a draw from `init`, if available
data = np.array(data)
if len(data.shape)>1:
for i in range(data.shape[0]):
data[i] = data[i] - data[i][0]
Rish001 marked this conversation as resolved.
Show resolved Hide resolved
else:
data = data - data[0]
return data

def _repr_latex_(self, name=None, dist=None):
Expand Down