Skip to content

Commit

Permalink
Fix axis handling of randommethod in GRW (#3985)
Browse files Browse the repository at this point in the history
* 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 <andorra.alexandre@gmail.com>

* Update pymc3/distributions/distribution.py

Co-authored-by: Alexandre ANDORRA <andorra.alexandre@gmail.com>

* Update pymc3/distributions/timeseries.py

Co-authored-by: Alexandre ANDORRA <andorra.alexandre@gmail.com>

* 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 <andorra.alexandre@gmail.com>
Co-authored-by: Thomas Wiecki <thomas.wiecki@gmail.com>
  • Loading branch information
3 people authored Jul 24, 2020
1 parent 6f8a0f7 commit 6d0ff91
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,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]
else:
data = data - data[0]
return data

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

0 comments on commit 6d0ff91

Please sign in to comment.