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 10 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
3 changes: 3 additions & 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)).
- Temporarily 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].Furthur 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 Expand Up @@ -54,6 +55,8 @@ Though we had to temporarily remove the `docs/*` folder from the tarball due to
- Forced the `Beta` distribution's `random` method to generate samples that are in the open interval $(0, 1)$, i.e. no value can be equal to zero or equal to one (issue [#3898](https://github.com/pymc-devs/pymc3/issues/3898) fixed by [#3924](https://github.com/pymc-devs/pymc3/pull/3924)).
- Fixed an issue that happened on Windows, that was introduced by the clipped beta distribution rvs function ([#3924](https://github.com/pymc-devs/pymc3/pull/3924)). Windows does not support the `float128` dtype, but we had assumed that it had to be available. The solution was to only support `float128` on Linux and Darwin systems (see issue [#3929](https://github.com/pymc-devs/pymc3/issues/3849) fixed by [#3930](https://github.com/pymc-devs/pymc3/pull/3930)).



### Deprecations
- Remove `sample_ppc` and `sample_ppc_w` that were deprecated in 3.6.
- Deprecated `sd` has been replaced by `sigma` (already in version 3.7) in continuous, mixed and timeseries distributions and now raises `DeprecationWarning` when `sd` is used. (see [#3837](https://github.com/pymc-devs/pymc3/pull/3837) and [#3688](https://github.com/pymc-devs/pymc3/issues/3688)).
Expand Down
3 changes: 2 additions & 1 deletion docs/release-notes/pymc3-3.0.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@

Changed _random() method of pymc3/distributions.py :: GaussianandomWalk classto fix #3962
Rish001 marked this conversation as resolved.
Show resolved Hide resolved
It is temporary fix to be amended in #4010
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