Skip to content

Commit be837bf

Browse files
committed
Merge branch 'main' of github.com:pymc-devs/pymc into deprecate-generator
2 parents 46073dd + d7d2be2 commit be837bf

File tree

10 files changed

+33
-22
lines changed

10 files changed

+33
-22
lines changed

conda-envs/environment-dev.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ dependencies:
1313
- numpy>=1.25.0
1414
- pandas>=0.24.0
1515
- pip
16-
- pytensor>=2.26.2,<2.27
16+
- pytensor>=2.26.2,<2.28
1717
- python-graphviz
1818
- networkx
1919
- scipy>=1.4.1

conda-envs/environment-docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ dependencies:
1111
- numpy>=1.25.0
1212
- pandas>=0.24.0
1313
- pip
14-
- pytensor>=2.26.2,<2.27
14+
- pytensor>=2.26.2,<2.28
1515
- python-graphviz
1616
- rich>=13.7.1
1717
- scipy>=1.4.1

conda-envs/environment-jax.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ dependencies:
2121
- numpyro>=0.8.0
2222
- pandas>=0.24.0
2323
- pip
24-
- pytensor>=2.26.2,<2.27
24+
- pytensor>=2.26.2,<2.28
2525
- python-graphviz
2626
- networkx
2727
- rich>=13.7.1

conda-envs/environment-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ dependencies:
1414
- numpy>=1.25.0
1515
- pandas>=0.24.0
1616
- pip
17-
- pytensor>=2.26.2,<2.27
17+
- pytensor>=2.26.2,<2.28
1818
- python-graphviz
1919
- networkx
2020
- rich>=13.7.1

conda-envs/windows-environment-dev.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ dependencies:
1313
- numpy>=1.25.0
1414
- pandas>=0.24.0
1515
- pip
16-
- pytensor>=2.26.2,<2.27
16+
- pytensor>=2.26.2,<2.28
1717
- python-graphviz
1818
- networkx
1919
- rich>=13.7.1

conda-envs/windows-environment-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ dependencies:
1616
- numpy>=1.25.0
1717
- pandas>=0.24.0
1818
- pip
19-
- pytensor>=2.26.2,<2.27
19+
- pytensor>=2.26.2,<2.28
2020
- python-graphviz
2121
- networkx
2222
- rich>=13.7.1

docs/source/guides/Probability_Distributions.rst

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,32 @@ A variable requires at least a ``name`` argument, and zero or more model paramet
2929

3030
Probability distributions are all subclasses of ``Distribution``, which in turn has two major subclasses: ``Discrete`` and ``Continuous``. In terms of data types, a ``Continuous`` random variable is given whichever floating point type is defined by ``pytensor.config.floatX``, while ``Discrete`` variables are given ``int16`` types when ``pytensor.config.floatX`` is ``float32``, and ``int64`` otherwise.
3131

32-
All distributions in ``pm.distributions`` will have two important methods: ``random()`` and ``logp()`` with the following signatures:
32+
All distributions in ``pm.distributions`` are associated with two key functions:
33+
34+
1. ``logp(dist, value)`` - Calculates log-probability at given value
35+
2. ``draw(dist, size=...)`` - Generates random samples
36+
37+
For example, with a normal distribution:
3338

3439
::
3540

36-
class SomeDistribution(Continuous):
41+
with pm.Model():
42+
x = pm.Normal('x', mu=0, sigma=1)
43+
44+
# Calculate log-probability
45+
log_prob = pm.logp(x, 0.5)
46+
47+
# Generate samples
48+
samples = pm.draw(x, size=100)
3749

38-
def random(self, point=None, size=None):
39-
...
40-
return random_samples
50+
Custom distributions using ``CustomDist`` should provide logp via the ``dist`` parameter:
51+
52+
::
4153

42-
def logp(self, value):
43-
...
44-
return total_log_prob
54+
def custom_logp(value, mu):
55+
return -0.5 * (value - mu)**2
4556

46-
PyMC expects the ``logp()`` method to return a log-probability evaluated at the passed ``value`` argument. This method is used internally by all of the inference methods to calculate the model log-probability that is used for fitting models. The ``random()`` method is used to simulate values from the variable, and is used internally for posterior predictive checks.
57+
custom_dist = pm.CustomDist('custom', dist=custom_logp, mu=0)
4758

4859

4960
Custom distributions
@@ -58,7 +69,7 @@ An exponential survival function, where :math:`c=0` denotes failure (or non-surv
5869
f(c, t) = \left\{ \begin{array}{l} \exp(-\lambda t), \text{if c=1} \\
5970
\lambda \exp(-\lambda t), \text{if c=0} \end{array} \right.
6071
61-
Such a function can be implemented as a PyMC distribution by writing a function that specifies the log-probability, then passing that function as a keyword argument to the ``DensityDist`` function, which creates an instance of a PyMC distribution with the custom function as its log-probability.
72+
Such a function can be implemented as a PyMC distribution by writing a function that specifies the log-probability, then passing that function as a keyword argument to the ``CustomDist`` function, which creates an instance of a PyMC distribution with the custom function as its log-probability.
6273

6374
For the exponential survival function, this is:
6475

@@ -67,7 +78,7 @@ For the exponential survival function, this is:
6778
def logp(value, t, lam):
6879
return (value * log(lam) - lam * t).sum()
6980

70-
exp_surv = pm.DensityDist('exp_surv', t, lam, logp=logp, observed=failure)
81+
exp_surv = pm.CustomDist('exp_surv', dist=logp, t=t, lam=lam, observed=failure)
7182

7283
Similarly, if a random number generator is required, a function returning random numbers corresponding to the probability distribution can be passed as the ``random`` argument.
7384

@@ -98,10 +109,10 @@ This allows for probabilities to be calculated and random numbers to be drawn.
98109

99110
::
100111

101-
>>> y.logp(4).eval()
112+
>>> pm.logp(y, 4).eval()
102113
array(-1.5843639373779297, dtype=float32)
103114

104-
>>> y.random(size=3)
115+
>>> pm.draw(y, size=3)
105116
array([5, 4, 3])
106117

107118

requirements-dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ numpydoc
1717
pandas>=0.24.0
1818
polyagamma
1919
pre-commit>=2.8.0
20-
pytensor>=2.26.2,<2.27
20+
pytensor>=2.26.2,<2.28
2121
pytest-cov>=2.5
2222
pytest>=3.0
2323
rich>=13.7.1

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ cachetools>=4.2.1
33
cloudpickle
44
numpy>=1.25.0
55
pandas>=0.24.0
6-
pytensor>=2.26.1,<2.27
6+
pytensor>=2.26.1,<2.28
77
rich>=13.7.1
88
scipy>=1.4.1
99
threadpoolctl>=3.1.0,<4.0.0

tests/test_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ def test_implicit_coords_series(self, seeded_test):
373373
pd = pytest.importorskip("pandas")
374374
ser_sales = pd.Series(
375375
data=np.random.randint(low=0, high=30, size=22),
376-
index=pd.date_range(start="2020-05-01", periods=22, freq="24H", name="date"),
376+
index=pd.date_range(start="2020-05-01", periods=22, freq="24h", name="date"),
377377
name="sales",
378378
)
379379
with pm.Model() as pmodel:

0 commit comments

Comments
 (0)