From 918f1af856d8222af2fc06f43960fd714b2fbcd7 Mon Sep 17 00:00:00 2001 From: Dan F-M Date: Mon, 6 Apr 2020 14:33:31 -0400 Subject: [PATCH 1/6] adding logcdf method to inverse gamma distribution --- pymc3/distributions/continuous.py | 33 +++++++++++++++++++++++++++++++ pymc3/tests/test_distributions.py | 6 ++++++ 2 files changed, 39 insertions(+) diff --git a/pymc3/distributions/continuous.py b/pymc3/distributions/continuous.py index 234d5d7aed..556af25966 100644 --- a/pymc3/distributions/continuous.py +++ b/pymc3/distributions/continuous.py @@ -2634,6 +2634,39 @@ def logp(self, value): def _distr_parameters_for_repr(self): return ["alpha", "beta"] + def logcdf(self, value): + """ + Compute the log of the cumulative distribution function for Inverse Gamma distribution + at the specified value. + + Parameters + ---------- + value: numeric + Value(s) for which log CDF is calculated. If the log CDF for multiple + values are desired the values must be provided in a numpy array or theano tensor. + + Returns + ------- + TensorVariable + """ + alpha = self.alpha + beta = self.beta + return bound( + tt.log(tt.gammaincc(alpha, beta / value)), + value >= 0, + alpha > 0, + beta > 0) + + def _repr_latex_(self, name=None, dist=None): + if dist is None: + dist = self + beta = dist.beta + alpha = dist.alpha + name = r'\text{%s}' % name + return r'${} \sim \text{{InverseGamma}}(\mathit{{alpha}}={},~\mathit{{beta}}={})$'.format(name, + get_variable_name(alpha), + get_variable_name(beta)) + class ChiSquared(Gamma): r""" diff --git a/pymc3/tests/test_distributions.py b/pymc3/tests/test_distributions.py index 0ee4e00dd5..9685fb8362 100644 --- a/pymc3/tests/test_distributions.py +++ b/pymc3/tests/test_distributions.py @@ -920,6 +920,12 @@ def test_inverse_gamma(self): {"alpha": Rplus, "beta": Rplus}, lambda value, alpha, beta: sp.invgamma.logpdf(value, alpha, scale=beta), ) + self.check_logcdf( + InverseGamma, + Rplus, + {'alpha': Rplusbig, 'beta': Rplusbig}, + lambda value, alpha, beta: sp.invgamma.logcdf(value, alpha, scale=beta), + ) @pytest.mark.xfail( condition=(theano.config.floatX == "float32"), From df5481d7fcc14be69f992744cbc6aafc078d09a6 Mon Sep 17 00:00:00 2001 From: Dan F-M Date: Mon, 2 Nov 2020 07:41:37 -0500 Subject: [PATCH 2/6] formatting fixes --- pymc3/distributions/continuous.py | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/pymc3/distributions/continuous.py b/pymc3/distributions/continuous.py index 556af25966..533aeff5b4 100644 --- a/pymc3/distributions/continuous.py +++ b/pymc3/distributions/continuous.py @@ -2655,17 +2655,8 @@ def logcdf(self, value): tt.log(tt.gammaincc(alpha, beta / value)), value >= 0, alpha > 0, - beta > 0) - - def _repr_latex_(self, name=None, dist=None): - if dist is None: - dist = self - beta = dist.beta - alpha = dist.alpha - name = r'\text{%s}' % name - return r'${} \sim \text{{InverseGamma}}(\mathit{{alpha}}={},~\mathit{{beta}}={})$'.format(name, - get_variable_name(alpha), - get_variable_name(beta)) + beta > 0, + ) class ChiSquared(Gamma): From 81f8320d3b66208234d5ad3727925403593b8f18 Mon Sep 17 00:00:00 2001 From: Dan F-M Date: Mon, 2 Nov 2020 08:02:25 -0500 Subject: [PATCH 3/6] more formatting fixes --- pymc3/tests/test_distributions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pymc3/tests/test_distributions.py b/pymc3/tests/test_distributions.py index 9685fb8362..d3aefbbb2b 100644 --- a/pymc3/tests/test_distributions.py +++ b/pymc3/tests/test_distributions.py @@ -923,7 +923,7 @@ def test_inverse_gamma(self): self.check_logcdf( InverseGamma, Rplus, - {'alpha': Rplusbig, 'beta': Rplusbig}, + {"alpha": Rplus, "beta": Rplus}, lambda value, alpha, beta: sp.invgamma.logcdf(value, alpha, scale=beta), ) From 2cf411e02dca4da34db8550b244dd4984429dd8a Mon Sep 17 00:00:00 2001 From: Dan F-M Date: Mon, 2 Nov 2020 11:05:38 -0500 Subject: [PATCH 4/6] mark xfail for float32 --- pymc3/tests/test_distributions.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pymc3/tests/test_distributions.py b/pymc3/tests/test_distributions.py index d3aefbbb2b..0ccea6ce22 100644 --- a/pymc3/tests/test_distributions.py +++ b/pymc3/tests/test_distributions.py @@ -913,6 +913,10 @@ def test_fun(value, mu, sigma): lambda value, alpha, beta: sp.gamma.logcdf(value, alpha, scale=1.0 / beta), ) + @pytest.mark.xfail( + condition=(theano.config.floatX == "float32"), + reason="Fails on float32 due to numerical issues", + ) def test_inverse_gamma(self): self.pymc3_matches_scipy( InverseGamma, From 0e41f409c98a3e64edd397c390681ca774784cc9 Mon Sep 17 00:00:00 2001 From: Eelke Spaak Date: Wed, 2 Dec 2020 15:17:17 +0100 Subject: [PATCH 5/6] updating release notes to master --- RELEASE-NOTES.md | 75 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 57 insertions(+), 18 deletions(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 9199eaa931..2dd70fbaf4 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -1,35 +1,60 @@ # Release Notes -## PyMC3 3.9.x (on deck) +## PyMC3 3.10.0 (on deck) + +This is a major release with many exciting new features. The biggest change is that we now rely on our own fork of [Theano-PyMC](https://github.com/pymc-devs/Theano-PyMC). This is in line with our [big announcement about our commitment to PyMC3 and Theano](https://pymc-devs.medium.com/the-future-of-pymc3-or-theano-is-dead-long-live-theano-d8005f8a0e9b). + +When upgrading, make sure that `Theano-PyMC` and not `Theano` are installed (the imports remain unchanged, however). If not, you can uninstall `Theano`: +``` +conda remove theano +``` + +And to install: +``` +conda install -c conda-forge theano-pymc +``` + +Or, if you are using pip (not recommended): +``` +pip uninstall theano +``` +And to install: +``` +pip install theano-pymc +``` + +This new version of `Theano-PyMC` comes with an experimental JAX backend which, when combined with the new and experimental JAX samplers in PyMC3, can greatly speed up sampling in your model. As this is still very new, please do not use it in production yet but do test it out and let us know if anything breaks and what results you are seeing, especially speed-wise. + +### New features +- New experimental JAX samplers in `pymc3.sample_jax` (see [notebook](https://docs.pymc.io/notebooks/GLM-hierarchical-jax.html) and [#4247](https://github.com/pymc-devs/pymc3/pull/4247)). Requires JAX and either TFP or numpyro. +- Add MLDA, a new stepper for multilevel sampling. MLDA can be used when a hierarchy of approximate posteriors of varying accuracy is available, offering improved sampling efficiency especially in high-dimensional problems and/or where gradients are not available (see [#3926](https://github.com/pymc-devs/pymc3/pull/3926)) +- Add Bayesian Additive Regression Trees (BARTs) [#4183](https://github.com/pymc-devs/pymc3/pull/4183)) +- Added `pymc3.gp.cov.Circular` kernel for Gaussian Processes on circular domains, e.g. the unit circle (see [#4082](https://github.com/pymc-devs/pymc3/pull/4082)). +- Added a new `MixtureSameFamily` distribution to handle mixtures of arbitrary dimensions in vectorized form for improved speed (see [#4185](https://github.com/pymc-devs/pymc3/issues/4185)). +- `sample_posterior_predictive_w` can now feed on `xarray.Dataset` - e.g. from `InferenceData.posterior`. (see [#4042](https://github.com/pymc-devs/pymc3/pull/4042)) +- Change SMC metropolis kernel to independent metropolis kernel [#4115](https://github.com/pymc-devs/pymc3/pull/4115)) +- Add alternative parametrization to NegativeBinomial distribution in terms of n and p (see [#4126](https://github.com/pymc-devs/pymc3/issues/4126)) +- Added semantically meaningful `str` representations to PyMC3 objects for console, notebook, and GraphViz use (see [#4076](https://github.com/pymc-devs/pymc3/pull/4076), [#4065](https://github.com/pymc-devs/pymc3/pull/4065), [#4159](https://github.com/pymc-devs/pymc3/pull/4159), [#4217](https://github.com/pymc-devs/pymc3/pull/4217), and [#4243](https://github.com/pymc-devs/pymc3/pull/4243)). ### Maintenance - Switch the dependency of Theano to our own fork, [Theano-PyMC](https://github.com/pymc-devs/Theano-PyMC). -- Mentioned the way to do any random walk with `theano.tensor.cumsum()` in `GaussianRandomWalk` docstrings (see [#4048](https://github.com/pymc-devs/pymc3/pull/4048)). -- Fixed numerical instability in ExGaussian's logp by preventing `logpow` from returning `-inf` (see [#4050](https://github.com/pymc-devs/pymc3/pull/4050)). +- Removed non-NDArray (Text, SQLite, HDF5) backends and associated tests. - Use dill to serialize user defined logp functions in `DensityDist`. The previous serialization code fails if it is used in notebooks on Windows and Mac. `dill` is now a required dependency. (see [#3844](https://github.com/pymc-devs/pymc3/issues/3844)). +- Fixed numerical instability in ExGaussian's logp by preventing `logpow` from returning `-inf` (see [#4050](https://github.com/pymc-devs/pymc3/pull/4050)). - Numerically improved stickbreaking transformation - e.g. for the `Dirichlet` distribution. [#4129](https://github.com/pymc-devs/pymc3/pull/4129) - Enabled the `Multinomial` distribution to handle batch sizes that have more than 2 dimensions. [#4169](https://github.com/pymc-devs/pymc3/pull/4169) +- Test model logp before starting any MCMC chains (see [#4116](https://github.com/pymc-devs/pymc3/issues/4116)) +- Fix bug in `model.check_test_point` that caused the `test_point` argument to be ignored. (see [PR #4211](https://github.com/pymc-devs/pymc3/pull/4211#issuecomment-727142721)) +- Refactored MvNormal.random method with better handling of sample, batch and event shapes. [#4207](https://github.com/pymc-devs/pymc3/pull/4207) ### Documentation +- Added a new notebook demonstrating how to incorporate sampling from a conjugate Dirichlet-multinomial posterior density in conjunction with other step methods (see [#4199](https://github.com/pymc-devs/pymc3/pull/4199)). +- Mentioned the way to do any random walk with `theano.tensor.cumsum()` in `GaussianRandomWalk` docstrings (see [#4048](https://github.com/pymc-devs/pymc3/pull/4048)). -### New features -- `sample_posterior_predictive_w` can now feed on `xarray.Dataset` - e.g. from `InferenceData.posterior`. (see [#4042](https://github.com/pymc-devs/pymc3/pull/4042)) -- Added `pymc3.gp.cov.Circular` kernel for Gaussian Processes on circular domains, e.g. the unit circle (see [#4082](https://github.com/pymc-devs/pymc3/pull/4082)). -- Add MLDA, a new stepper for multilevel sampling. MLDA can be used when a hierarchy of approximate posteriors of varying accuracy is available, offering improved sampling efficiency especially in high-dimensional problems and/or where gradients are not available (see [#3926](https://github.com/pymc-devs/pymc3/pull/3926)) -- Change SMC metropolis kernel to independent metropolis kernel [#4115](https://github.com/pymc-devs/pymc3/pull/3926)) -- Add alternative parametrization to NegativeBinomial distribution in terms of n and p (see [#4126](https://github.com/pymc-devs/pymc3/issues/4126)) -- Added a new `MixtureSameFamily` distribution to handle mixtures of arbitrary dimensions in vectorized form (see [#4185](https://github.com/pymc-devs/pymc3/issues/4185)). - +**Release manager** for 3.10.0: Eelke Spaak ([@Spaak](https://github.com/Spaak)) ## PyMC3 3.9.3 (11 August 2020) -### Maintenance -- Fix an error on Windows and Mac where error message from unpickling models did not show up in the notebook, or where sampling froze when a worker process crashed (see [#3991](https://github.com/pymc-devs/pymc3/pull/3991)). -- Require Theano >= 1.0.5 (see [#4032](https://github.com/pymc-devs/pymc3/pull/4032)). - -### Documentation -- Notebook on [multilevel modeling](https://docs.pymc.io/notebooks/multilevel_modeling.html) has been rewritten to showcase ArviZ and xarray usage for inference result analysis (see [#3963](https://github.com/pymc-devs/pymc3/pull/3963)). - ### New features - Introduce optional arguments to `pm.sample`: `mp_ctx` to control how the processes for parallel sampling are started, and `pickle_backend` to specify which library is used to pickle models in parallel sampling when the multiprocessing context is not of type `fork` (see [#3991](https://github.com/pymc-devs/pymc3/pull/3991)). - Add sampler stats `process_time_diff`, `perf_counter_diff` and `perf_counter_start`, that record wall and CPU times for each NUTS and HMC sample (see [ #3986](https://github.com/pymc-devs/pymc3/pull/3986)). @@ -37,10 +62,19 @@ - SMC-ABC: add the Wasserstein and energy distance functions. Refactor API, the distance, sum_stats and epsilon arguments are now passed `pm.Simulator` instead of `pm.sample_smc`. Add random method to `pm.Simulator`. Add option to save the simulated data. Improved LaTeX representation [#3996](https://github.com/pymc-devs/pymc3/pull/3996). - SMC-ABC: Allow use of potentials by adding them to the prior term. [#4016](https://github.com/pymc-devs/pymc3/pull/4016). +### Maintenance +- Fix an error on Windows and Mac where error message from unpickling models did not show up in the notebook, or where sampling froze when a worker process crashed (see [#3991](https://github.com/pymc-devs/pymc3/pull/3991)). +- Require Theano >= 1.0.5 (see [#4032](https://github.com/pymc-devs/pymc3/pull/4032)). + +### Documentation +- Notebook on [multilevel modeling](https://docs.pymc.io/notebooks/multilevel_modeling.html) has been rewritten to showcase ArviZ and xarray usage for inference result analysis (see [#3963](https://github.com/pymc-devs/pymc3/pull/3963)). + _NB: The `docs/*` folder is still removed from the tarball due to an upload size limit on PyPi._ +**Release manager** for 3.9.3: Kyle Beauchamp ([@kyleabeauchamp](https://github.com/kyleabeauchamp)) ## PyMC3 3.9.2 (24 June 2020) + ### Maintenance - Warning added in GP module when `input_dim` is lower than the number of columns in `X` to compute the covariance function (see [#3974](https://github.com/pymc-devs/pymc3/pull/3974)). - 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)). @@ -50,10 +84,14 @@ _NB: The `docs/*` folder is still removed from the tarball due to an upload size _NB: The `docs/*` folder is still removed from the tarball due to an upload size limit on PyPi._ +**Release manager** for 3.9.2: Alex Andorra ([@AlexAndorra](https://github.com/AlexAndorra)) + ## PyMC3 3.9.1 (16 June 2020) The `v3.9.0` upload to PyPI didn't include a tarball, which is fixed in this release. Though we had to temporarily remove the `docs/*` folder from the tarball due to a size limit. +**Release manager** for 3.9.1: Michael Osthege ([@michaelosthege](https://github.com/michaelosthege)) + ## PyMC3 3.9.0 (16 June 2020) ### New features @@ -99,6 +137,7 @@ Though we had to temporarily remove the `docs/*` folder from the tarball due to - Dropped some deprecated kwargs and functions (see [#3906](https://github.com/pymc-devs/pymc3/pull/3906)) - Dropped the outdated 'nuts' initialization method for `pm.sample` (see [#3863](https://github.com/pymc-devs/pymc3/pull/3863)). +**Release manager** for 3.9.0: Michael Osthege ([@michaelosthege](https://github.com/michaelosthege)) ## PyMC3 3.8 (November 29 2019) From 7d6ba6bb4474f74ca7790ecc037ade4dc54aefe4 Mon Sep 17 00:00:00 2001 From: Eelke Spaak Date: Wed, 2 Dec 2020 15:19:08 +0100 Subject: [PATCH 6/6] adding PR to release notes --- RELEASE-NOTES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 2dd70fbaf4..d3815033d0 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -46,6 +46,7 @@ This new version of `Theano-PyMC` comes with an experimental JAX backend which, - Test model logp before starting any MCMC chains (see [#4116](https://github.com/pymc-devs/pymc3/issues/4116)) - Fix bug in `model.check_test_point` that caused the `test_point` argument to be ignored. (see [PR #4211](https://github.com/pymc-devs/pymc3/pull/4211#issuecomment-727142721)) - Refactored MvNormal.random method with better handling of sample, batch and event shapes. [#4207](https://github.com/pymc-devs/pymc3/pull/4207) +- `InverseGamma` now implements a `logcdf`. [#3944](https://github.com/pymc-devs/pymc3/pull/3944) ### Documentation - Added a new notebook demonstrating how to incorporate sampling from a conjugate Dirichlet-multinomial posterior density in conjunction with other step methods (see [#4199](https://github.com/pymc-devs/pymc3/pull/4199)).