Skip to content

Commit 6d0ff91

Browse files
Rish001AlexAndorratwiecki
authored
Fix axis handling of randommethod in GRW (#3985)
* 3962 issue fixed * Scaled ._random() to more than 2 dim * Fixed the remaining failed testcase * Update pymc3/distributions/distribution.py Co-authored-by: Alexandre ANDORRA <[email protected]> * Update pymc3/distributions/distribution.py Co-authored-by: Alexandre ANDORRA <[email protected]> * Update pymc3/distributions/timeseries.py Co-authored-by: Alexandre ANDORRA <[email protected]> * Formatting issues fixed * handled value of axis to fix the bug * Documented the change in Release-Notes * Documented RELEASENOTES * removed text from the docs/release-notes.md/pymc3-3.0.md * Fix typo in release notes and line changes * Fixed the typos in Release notes. Added comments in timeseries.py and fixed the line changes in distributions.py * Removed temporary from release notes. fixed the line changes * Update RELEASE-NOTES.md Co-authored-by: Alexandre ANDORRA <[email protected]> Co-authored-by: Thomas Wiecki <[email protected]>
1 parent 6f8a0f7 commit 6d0ff91

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

Diff for: RELEASE-NOTES.md

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
- 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)).
2121
- Add simple test case for new coords and dims feature in `pm.Model` (see [#3977](https://github.com/pymc-devs/pymc3/pull/3977)).
2222
- Require ArviZ >= 0.9.0 (see [#3977](https://github.com/pymc-devs/pymc3/pull/3977)).
23+
- 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)
2324

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

Diff for: docs/release-notes/pymc3-3.0.md

-1
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-

Diff for: pymc3/distributions/timeseries.py

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

305306
def _random(self, sigma, mu, size, sample_shape):
306-
"""Implement a Gaussian random walk as a cumulative sum of normals."""
307+
"""Implement a Gaussian random walk as a cumulative sum of normals.
308+
axis = len(size) - 1 denotes the axis along which cumulative sum would be calculated.
309+
This might need to be corrected in future when issue #4010 is fixed.
310+
Lines 318-322 ties the starting point of each instance of random walk to 0"
311+
"""
307312
if size[len(sample_shape)] == sample_shape:
308313
axis = len(sample_shape)
309314
else:
310-
axis = 0
315+
axis = len(size) - 1
311316
rv = stats.norm(mu, sigma)
312317
data = rv.rvs(size).cumsum(axis=axis)
313-
data = data - data[0] # TODO: this should be a draw from `init`, if available
318+
data = np.array(data)
319+
if len(data.shape)>1:
320+
for i in range(data.shape[0]):
321+
data[i] = data[i] - data[i][0]
322+
else:
323+
data = data - data[0]
314324
return data
315325

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

0 commit comments

Comments
 (0)