Skip to content

Commit b3388a9

Browse files
committed
Update from comments
1 parent 1b7cd6f commit b3388a9

File tree

3 files changed

+19
-17
lines changed

3 files changed

+19
-17
lines changed

RELEASE-NOTES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
- Sampling from variational approximation now allows for alternative trace backends [#3550].
1313
- Infix `@` operator now works with random variables and deterministics [#3619](https://github.com/pymc-devs/pymc3/pull/3619).
1414
- [ArviZ](https://arviz-devs.github.io/arviz/) is now a requirement, and handles plotting, diagnostics, and statistical checks.
15-
- Can use GaussianRandomWalk in sample_prior_predictive [#3682](https://github.com/pymc-devs/pymc3/pull/3682)
15+
- Can use GaussianRandomWalk in sample_prior_predictive and sample_prior_predictive [#3682](https://github.com/pymc-devs/pymc3/pull/3682)
1616
- Now 11 years of S&P returns in data set[#3682](https://github.com/pymc-devs/pymc3/pull/3682)
1717

1818
### Maintenance

docs/source/notebooks/stochastic_volatility.ipynb

Lines changed: 6 additions & 6 deletions
Large diffs are not rendered by default.

pymc3/distributions/timeseries.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,14 @@ def __init__(self, tau=None, init=Flat.dist(), sigma=None, mu=0.,
200200
self.init = init
201201
self.mean = tt.as_tensor_variable(0.)
202202

203+
def _mu_and_sigma(self, mu, sigma):
204+
"""Helper to get mu and sigma if they are high dimensional."""
205+
if sigma.ndim > 0:
206+
sigma = sigma[1:]
207+
if mu.ndim > 0:
208+
mu = mu[1:]
209+
return mu, sigma
210+
203211
def logp(self, x):
204212
"""
205213
Calculate log-probability of Gaussian Random Walk distribution at specified value.
@@ -216,15 +224,7 @@ def logp(self, x):
216224
if x.ndim > 0:
217225
x_im1 = x[:-1]
218226
x_i = x[1:]
219-
if self.sigma.ndim > 0:
220-
sigma = self.sigma[:-1]
221-
else:
222-
sigma = self.sigma
223-
if self.mu.ndim > 0:
224-
mu = self.mu[:-1]
225-
else:
226-
mu = self.mu
227-
227+
mu, sigma = self._mu_and_sigma(self.mu, self.sigma)
228228
innov_like = Normal.dist(mu=x_im1 + mu, sigma=sigma).logp(x_i)
229229
return self.init.logp(x[0]) + tt.sum(innov_like)
230230
return self.init.logp(x)
@@ -252,7 +252,9 @@ def random(self, point=None, size=None):
252252
def _random(self, sigma, mu, size):
253253
"""Implement a Gaussian random walk as a cumulative sum of normals."""
254254
rv = stats.norm(mu, sigma)
255-
return rv.rvs(size).cumsum(axis=0)
255+
data = rv.rvs(size).cumsum(axis=0)
256+
data = data - data[0] # TODO: this should be a draw from `init`, if available
257+
return data
256258

257259
def _repr_latex_(self, name=None, dist=None):
258260
if dist is None:

0 commit comments

Comments
 (0)