Skip to content

Commit 18f1e51

Browse files
Closes #3051 - logp numpy array input fixed (#3836)
* Closes #3051 - logp numpy array input- fixed Converts 'int' type to <TensorType(int64,Scalar)> to parse value to `astype` and allows arguments to `logp(self,value)` when called with numpy array. * Closes #3051 - Allows numpy array input to logp Allows `logp(self,value)` to take `value` input of type numpy array without errors * fixes #3051 * Fixes #3051 * updated RELEASE-NOTES.md Added the deprecation of `sd` with `sigma` in newer version with DeprecationWarning on usage of `sd`. * directly use floatX * mention #3836 * move all deprecations into their own chapter, as done in previous releases * add regression test Co-authored-by: Michael Osthege <[email protected]>
1 parent 727b88a commit 18f1e51

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

RELEASE-NOTES.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,23 @@
1616
- `pm.LKJCholeskyCov` now automatically computes and returns the unpacked Cholesky decomposition, the correlations and the standard deviations of the covariance matrix (see [#3881](https://github.com/pymc-devs/pymc3/pull/3881)).
1717

1818
### Maintenance
19-
- Remove `sample_ppc` and `sample_ppc_w` that were deprecated in 3.6.
2019
- Tuning results no longer leak into sequentially sampled `Metropolis` chains (see #3733 and #3796).
21-
- Deprecated `sd` in version 3.7 has been replaced by `sigma` now raises `DeprecationWarning` on using `sd` in continuous, mixed and timeseries distributions. (see #3837 and #3688).
22-
- We'll deprecate the `Text` and `SQLite` backends and the `save_trace`/`load_trace` functions, since this is now done with ArviZ. (see [#3902](https://github.com/pymc-devs/pymc3/pull/3902))
2320
- In named models, `pm.Data` objects now get model-relative names (see [#3843](https://github.com/pymc-devs/pymc3/pull/3843)).
2421
- `pm.sample` now takes 1000 draws and 1000 tuning samples by default, instead of 500 previously (see [#3855](https://github.com/pymc-devs/pymc3/pull/3855)).
25-
- Dropped some deprecated kwargs and functions (see [#3906](https://github.com/pymc-devs/pymc3/pull/3906))
26-
- Dropped the outdated 'nuts' initialization method for `pm.sample` (see [#3863](https://github.com/pymc-devs/pymc3/pull/3863)).
2722
- Moved argument division out of `NegativeBinomial` `random` method. Fixes [#3864](https://github.com/pymc-devs/pymc3/issues/3864) in the style of [#3509](https://github.com/pymc-devs/pymc3/pull/3509).
2823
- The Dirichlet distribution now raises a ValueError when it's initialized with <= 0 values (see [#3853](https://github.com/pymc-devs/pymc3/pull/3853)).
24+
- Dtype bugfix in `MvNormal` and `MvStudentT` (see [3836](https://github.com/pymc-devs/pymc3/pull/3836))
2925
- End of sampling report now uses `arviz.InferenceData` internally and avoids storing
3026
pointwise log likelihood (see [#3883](https://github.com/pymc-devs/pymc3/pull/3883))
3127

28+
### Deprecations
29+
- Remove `sample_ppc` and `sample_ppc_w` that were deprecated in 3.6.
30+
- Deprecated `sd` in version 3.7 has been replaced by `sigma` now raises `DeprecationWarning` on using `sd` in continuous, mixed and timeseries distributions. (see [#3837](https://github.com/pymc-devs/pymc3/pull/3837) and [#3688](https://github.com/pymc-devs/pymc3/issues/3688)).
31+
- We'll deprecate the `Text` and `SQLite` backends and the `save_trace`/`load_trace` functions, since this is now done with ArviZ. (see [#3902](https://github.com/pymc-devs/pymc3/pull/3902))
32+
- Dropped some deprecated kwargs and functions (see [#3906](https://github.com/pymc-devs/pymc3/pull/3906))
33+
- Dropped the outdated 'nuts' initialization method for `pm.sample` (see [#3863](https://github.com/pymc-devs/pymc3/pull/3863)).
34+
35+
3236
## PyMC3 3.8 (November 29 2019)
3337

3438
### New features

pymc3/distributions/multivariate.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from theano.tensor.slinalg import Cholesky
2828
import pymc3 as pm
2929

30-
from pymc3.theanof import floatX, intX
30+
from pymc3.theanof import floatX
3131
from . import transforms
3232
from pymc3.util import get_variable_name
3333
from .distribution import (Continuous, Discrete, draw_values, generate_samples,
@@ -325,7 +325,7 @@ def logp(self, value):
325325
TensorVariable
326326
"""
327327
quaddist, logdet, ok = self._quaddist(value)
328-
k = intX(value.shape[-1]).astype(theano.config.floatX)
328+
k = floatX(value.shape[-1])
329329
norm = - 0.5 * k * pm.floatX(np.log(2 * np.pi))
330330
return bound(norm - 0.5 * quaddist - logdet, ok)
331331

@@ -439,7 +439,7 @@ def logp(self, value):
439439
TensorVariable
440440
"""
441441
quaddist, logdet, ok = self._quaddist(value)
442-
k = intX(value.shape[-1]).astype(theano.config.floatX)
442+
k = floatX(value.shape[-1])
443443

444444
norm = (gammaln((self.nu + k) / 2.)
445445
- gammaln(self.nu / 2.)

pymc3/tests/test_distributions.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,3 +1414,21 @@ def test_orderedlogistic_dimensions(shape):
14141414
assert np.allclose(clogp, expected)
14151415
assert ol.distribution.p.ndim == (len(shape) + 1)
14161416
assert np.allclose(ologp, expected)
1417+
1418+
1419+
class TestBugfixes:
1420+
@pytest.mark.parametrize('dist_cls,kwargs', [
1421+
(MvNormal, dict(mu=0)),
1422+
(MvStudentT, dict(mu=0, nu=2))
1423+
])
1424+
@pytest.mark.parametrize('dims', [1,2,4])
1425+
def test_issue_3051(self, dims, dist_cls, kwargs):
1426+
d = dist_cls.dist(**kwargs, cov=np.eye(dims), shape=(dims,))
1427+
1428+
X = np.random.normal(size=(20,dims))
1429+
actual_t = d.logp(X)
1430+
assert isinstance(actual_t, tt.TensorVariable)
1431+
actual_a = actual_t.eval()
1432+
assert isinstance(actual_a, np.ndarray)
1433+
assert actual_a.shape == (X.shape[0],)
1434+
pass

0 commit comments

Comments
 (0)