Skip to content

Commit fbd8539

Browse files
committed
Revamp docs and add dev section
1 parent 28d51c4 commit fbd8539

14 files changed

Lines changed: 510 additions & 161 deletions

README.md

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,52 +10,57 @@
1010
alt="Codecov Badge"
1111
/>
1212

13-
As PyMC continues to mature and expand its functionality to accommodate more domains of application, we increasingly see cutting-edge methodologies, highly specialized statistical distributions, and complex models appear.
14-
While this adds to the functionality and relevance of the project, it can also introduce instability and impose a burden on testing and quality control.
15-
To reduce the burden on the main `pymc` repository, this `pymc-extras` repository can become the aggregator and testing ground for new additions to PyMC.
16-
This may include unusual probability distributions, advanced model fitting algorithms, innovative yet not fully tested methods, or niche functionality that might not fit in the main PyMC repository, but still may be of interest to users.
13+
PyMC Extras extends [PyMC](https://www.pymc.io) with additional distributions, inference methods, and model transformations.
14+
It is maintained by the PyMC team and hosts functionality that is too specialized for the core library, but useful enough that you shouldn't have to write it yourself.
1715

18-
The `pymc-extras` repository can be understood as the first step in the PyMC development pipeline, where all novel code is introduced until it is obvious that it belongs in the main repository.
19-
We hope that this organization improves the stability and streamlines the testing overhead of the `pymc` repository, while allowing users and developers to test and evaluate cutting-edge methods and not yet fully mature features.
16+
Highlights include:
2017

21-
`pymc-extras` would be designed to mirror the namespaces in `pymc` to make usage and migration as easy as possible.
22-
For example, a `ParabolicFractal` distribution could be used analogously to those in `pymc`:
18+
- Automatic marginalization: exact for finite discrete and conjugate variables, approximate via the Laplace approximation
19+
- Alternative inference methods: Pathfinder, DADVI, INLA, Laplace approximation, and better MAP estimation
20+
- Statespace models: SARIMAX, VARMAX, ETS, and structural time series with Kalman filtering
21+
- Additional distributions such as `DiscreteMarkovChain`, `GeneralizedPoisson`, and `GenExtreme`
22+
23+
`pymc-extras` mirrors the namespaces in `pymc` to make usage and migration as easy as possible.
24+
For example, distributions are used exactly like those in `pymc`:
2325

2426
```python
2527
import pymc as pm
2628
import pymc_extras as pmx
2729

2830
with pm.Model():
29-
alpha = pmx.ParabolicFractal('alpha', b=1, c=1)
31+
xi = pm.HalfNormal("xi", 0.2)
32+
pmx.GenExtreme("llik", mu=1, sigma=0.5, xi=xi, observed=data)
33+
```
34+
35+
See the [documentation](https://pymc-extras.readthedocs.io/) for the full API reference.
36+
37+
## Installation
38+
39+
```bash
40+
pip install pymc-extras
41+
```
3042

31-
...
43+
or for the development version:
3244

45+
```bash
46+
pip install git+https://github.com/pymc-devs/pymc-extras.git
3347
```
3448

3549
## Questions
3650

3751
### What belongs in `pymc-extras`?
3852

39-
- newly-implemented statistical methods, for example step methods or model construction helpers
53+
- statistical methods, for example step methods or model construction helpers
4054
- distributions that are tricky to sample from or test
41-
- infrequently-used fitting methods or distributions
55+
- specialized fitting methods or distributions
4256
- any code that requires additional optimization before it can be used in practice
4357

58+
Functionality that proves widely useful may graduate to the main `pymc` repository.
4459

4560
### What does not belong in `pymc-extras`?
4661
- Case studies
4762
- Implementations that cannot be applied generically, for example because they are tied to variables from a toy example
4863

64+
## Contributing
4965

50-
### Should there be more than one add-on repository?
51-
52-
Since there is a lot of code that we may not want in the main repository, does it make sense to have more than one additional repository?
53-
For example, `pymc-extras` may just include methods that are not fully developed, tested and trusted, while code that is known to work well and has adequate test coverage, but is still too specialized to become part of `pymc` could reside in a `pymc-extras` (or similar) repository.
54-
55-
56-
### Unanswered questions & ToDos
57-
This project is still young and many things have not been answered or implemented.
58-
Please get involved!
59-
60-
* What are guidelines for organizing submodules?
61-
* Proposal: No default imports of WIP/unstable submodules. By importing manually we can avoid breaking the package if a submodule breaks, for example because of an updated dependency.
66+
We welcome contributions! Check out the [contributing guidelines](https://github.com/pymc-devs/pymc-extras/blob/main/CONTRIBUTING.md) to get started.

docs/api/distributions.rst

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Distributions
2+
=============
3+
4+
Distributions that are not (or not yet) part of PyMC itself. They behave
5+
like regular PyMC distributions and can be used directly inside a model.
6+
7+
.. currentmodule:: pymc_extras.distributions
8+
.. autosummary::
9+
:toctree: ../generated/
10+
11+
Chi
12+
Maxwell
13+
DiscreteMarkovChain
14+
GeneralizedPoisson
15+
BetaNegativeBinomial
16+
GenExtreme
17+
R2D2M2CP
18+
Skellam
19+
histogram_approximation
20+
21+
Transforms
22+
----------
23+
24+
Value transforms for constrained sampling.
25+
26+
.. currentmodule:: pymc_extras.distributions.transforms
27+
.. autosummary::
28+
:toctree: ../generated/
29+
30+
PartialOrder

docs/api/inference.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Inference
2+
=========
3+
4+
Fitting methods beyond ``pm.sample``: optimization-based point estimates
5+
(``find_MAP``), Gaussian approximations (Laplace, INLA), and fast variational
6+
methods (Pathfinder, DADVI). ``fit`` is a single entry point that dispatches
7+
to these by name.
8+
9+
.. currentmodule:: pymc_extras.inference
10+
.. autosummary::
11+
:toctree: ../generated/
12+
13+
fit
14+
find_MAP
15+
fit_laplace
16+
fit_pathfinder
17+
fit_dadvi
18+
fit_INLA

docs/api/marginalization.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Marginalization
2+
===============
3+
4+
Model transformations that integrate variables out of a model, and recover
5+
them afterwards. Marginalizing discrete variables allows sampling with
6+
gradient-based samplers like NUTS; marginalizing conjugate pairs or using the
7+
Laplace approximation reduces the dimensionality of the posterior.
8+
9+
``marginalize`` returns a model where the requested variables no longer
10+
appear, but the remaining variables keep their original joint distribution
11+
(exactly, or approximately when using the Laplace approximation).
12+
``unmarginalize`` undoes the transformation, and ``conditional`` /
13+
``recover`` reintroduce the marginalized variables conditioned on the
14+
posterior of the remaining ones.
15+
16+
.. currentmodule:: pymc_extras.marginal
17+
.. autosummary::
18+
:toctree: ../generated/
19+
20+
marginalize
21+
unmarginalize
22+
conditional
23+
recover
24+
25+
The set of supported marginalizations is extensible; see
26+
:doc:`../developer/extending_marginalization`.

docs/api/model.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Model building
2+
==============
3+
4+
Tools for defining models. ``as_model`` turns a function with PyMC
5+
statements into a reusable model factory, and ``ModelBuilder`` is a base
6+
class for packaging a model behind a scikit-learn-like ``fit``/``predict``
7+
interface, with saving and loading included.
8+
9+
.. currentmodule:: pymc_extras
10+
.. autosummary::
11+
:toctree: ../generated/
12+
13+
as_model
14+
model_builder.ModelBuilder

docs/api/prior.rst

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
Prior specification
2+
===================
3+
4+
A declarative way to define (hierarchical) prior distributions that can be
5+
serialized to and from JSON. Useful when priors are part of a configuration
6+
file rather than hardcoded in a model, as in
7+
`pymc-marketing <https://www.pymc-marketing.io>`_.
8+
9+
.. currentmodule:: pymc_extras.prior
10+
.. autosummary::
11+
:toctree: ../generated/
12+
13+
Prior
14+
Censored
15+
Scaled
16+
sample_prior
17+
create_dim_handler
18+
handle_dims
19+
register_tensor_transform
20+
VariableFactory
21+
22+
From a previous model
23+
---------------------
24+
25+
Build a prior from the posterior of a previously fitted model, enabling
26+
simple Bayesian updating workflows.
27+
28+
.. currentmodule:: pymc_extras.utils
29+
.. autosummary::
30+
:toctree: ../generated/
31+
32+
prior.prior_from_idata
33+
34+
Deserialization
35+
---------------
36+
37+
Registry that maps JSON data back to Python objects, used to round-trip
38+
``Prior`` definitions and extensible to arbitrary custom types.
39+
40+
.. currentmodule:: pymc_extras.deserialize
41+
.. autosummary::
42+
:toctree: ../generated/
43+
44+
deserialize
45+
register_deserialization
46+
Deserializer

docs/api/reparametrization.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Reparametrization
2+
=================
3+
4+
Automatic reparametrization of hierarchical models. VIP (variationally
5+
inferred parametrization) makes the choice between centered and non-centered
6+
parametrizations continuous and learns the best setting per variable, instead
7+
of leaving it as a manual, all-or-nothing decision.
8+
9+
.. currentmodule:: pymc_extras.model.transforms
10+
.. autosummary::
11+
:toctree: ../generated/
12+
13+
autoreparam.vip_reparametrize
14+
autoreparam.VIP

docs/api/statespace.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Statespace models
2+
=================
3+
4+
Linear Gaussian statespace models with Kalman filtering and smoothing:
5+
classical time series models (SARIMAX, VARMAX, ETS) and structural models
6+
built from interpretable components (trend, seasonality, cycles,
7+
autoregressive errors).
8+
9+
.. automodule:: pymc_extras.statespace
10+
.. toctree::
11+
:maxdepth: 1
12+
13+
../statespace/core
14+
../statespace/filters
15+
../statespace/models

docs/api/utils.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Utilities
2+
=========
3+
4+
Printing
5+
--------
6+
7+
.. currentmodule:: pymc_extras.printing
8+
.. autosummary::
9+
:toctree: ../generated/
10+
11+
model_table
12+
13+
Miscellaneous
14+
-------------
15+
16+
.. currentmodule:: pymc_extras.utils
17+
.. autosummary::
18+
:toctree: ../generated/
19+
20+
spline.bspline_interpolation
21+
model_equivalence.equivalent_models

0 commit comments

Comments
 (0)