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 all 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
1 change: 1 addition & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- Pass the `tune` argument from `sample` when using `advi+adapt_diag_grad` (see issue [#3965](https://github.com/pymc-devs/pymc3/issues/3965), fixed by [#3979](https://github.com/pymc-devs/pymc3/pull/3979)).
- Add simple test case for new coords and dims feature in `pm.Model` (see [#3977](https://github.com/pymc-devs/pymc3/pull/3977)).
- Require ArviZ >= 0.9.0 (see [#3977](https://github.com/pymc-devs/pymc3/pull/3977)).
- Fixed issue [#3962](https://github.com/pymc-devs/pymc3/issues/3962) by making change in the `_random()` method of `GaussianRandomWalk` class, refer to PR [#3985]. Further testing revealed a new issue which is being tracked [#4010](https://github.com/pymc-devs/pymc3/issues/4010)

_NB: The `docs/*` folder is still removed from the tarball due to an upload size limit on PyPi._

Expand Down
1 change: 0 additions & 1 deletion docs/release-notes/pymc3-3.0.md
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

16 changes: 13 additions & 3 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 @@ -303,14 +304,23 @@ def random(self, point=None, size=None):
)

def _random(self, sigma, mu, size, sample_shape):
"""Implement a Gaussian random walk as a cumulative sum of normals."""
"""Implement a Gaussian random walk as a cumulative sum of normals.
axis = len(size) - 1 denotes the axis along which cumulative sum would be calculated.
This might need to be corrected in future when issue #4010 is fixed.
Lines 318-322 ties the starting point of each instance of random walk to 0"
"""
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