Skip to content

Commit eb4e353

Browse files
authored
fix docstrings for censored and timeseries (#6638)
1 parent 617f93c commit eb4e353

File tree

4 files changed

+48
-30
lines changed

4 files changed

+48
-30
lines changed

docs/source/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
"SMC_kernel": ":ref:`SMC Kernel <smc_kernels>`",
7777
"PyTensor_Op": ":class:`PyTensor Op <pytensor.graph.op.Op>`",
7878
"tensor_like": ":term:`tensor_like`",
79+
"unnamed_distribution": ":term:`unnamed_distribution`",
7980
"numpy_Generator": ":class:`~numpy.random.Generator`",
8081
"Distribution": ":ref:`Distribution <api_distributions>`",
8182
}

docs/source/glossary.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,5 +132,26 @@ tensor_like
132132
133133
pt.as_tensor_variable([[1, 2.0], [0, 0]])
134134
```
135+
unnamed_distribution
136+
PyMC distributions can be initialized directly (e.g. `pm.Normal`) or using the `.dist` classmethod (e.g. `pm.Normal.dist`). Distributions initialized with the 1st method are registered as model parameters and thus, need to be given a name and be initialized within a model context. "unnamed_distributions" are distributions initialized with the 2nd method. These are standalone distributions, they are not parameters in any model and can be used to draw samples from a distribution by itself or as parameters to other distributions like mixtures or censored.
137+
138+
"unnamed_distributions" can be used outside the model context. For example:
139+
140+
```{jupyter-execute}
141+
import pymc as pm
142+
143+
unnamed_dist = pm.Normal.dist(mu=1, sigma=2)
144+
pm.draw(unnamed_dist, draws=10)
145+
```
146+
147+
Trying to initialize a named distribution outside a model context raises a `TypeError`:
148+
149+
```{jupyter-execute}
150+
:raises: TypeError
151+
152+
import pymc as pm
153+
154+
pm.Normal("variable")
155+
```
135156

136157
:::::

pymc/distributions/censored.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ class Censored(Distribution):
5252
5353
Parameters
5454
----------
55-
dist: unnamed distribution
56-
Univariate distribution created via the `.dist()` API, which will be censored.
55+
dist : unnamed_distribution
56+
Univariate distribution which will be censored.
5757
This distribution must have a logcdf method implemented for sampling.
5858
5959
.. warning:: dist will be cloned, rendering it independent of the one passed as input.
6060
61-
lower: float or None
61+
lower : float or None
6262
Lower (left) censoring point. If `None` the distribution will not be left censored
63-
upper: float or None
63+
upper : float or None
6464
Upper (right) censoring point. If `None`, the distribution will not be right censored.
6565
6666
Warnings

pymc/distributions/timeseries.py

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ class GaussianRandomWalk(PredefinedRandomWalk):
277277
innovation drift
278278
sigma : tensor_like of float, default 1
279279
sigma > 0, innovation standard deviation.
280-
init_dist : Distribution
280+
init_dist : unnamed_distribution
281281
Unnamed univariate distribution of the initial value. Unnamed refers to distributions
282282
created with the ``.dist()`` API.
283283
@@ -317,19 +317,18 @@ class MvGaussianRandomWalk(PredefinedRandomWalk):
317317
318318
Parameters
319319
----------
320-
mu: tensor_like of float
320+
mu : tensor_like of float
321321
innovation drift
322-
cov: tensor_like of float
322+
cov : tensor_like of float
323323
pos def matrix, innovation covariance matrix
324-
tau: tensor_like of float
324+
tau : tensor_like of float
325325
pos def matrix, inverse covariance matrix
326-
chol: tensor_like of float
326+
chol : tensor_like of float
327327
Cholesky decomposition of covariance matrix
328328
lower : bool, default=True
329329
Whether the cholesky fatcor is given as a lower triangular matrix.
330-
init_dist: distribution
331-
Unnamed multivariate distribution of the initial value. Unnamed refers to distributions
332-
created with the ``.dist()`` API.
330+
init_dist : unnamed_distribution
331+
Unnamed multivariate distribution of the initial value.
333332
334333
.. warning:: init_dist will be cloned, rendering them independent of the ones passed as input.
335334
@@ -370,21 +369,20 @@ class MvStudentTRandomWalk(PredefinedRandomWalk):
370369
371370
Parameters
372371
----------
373-
nu: int
372+
nu : int
374373
degrees of freedom
375-
mu: tensor_like of float
374+
mu : tensor_like of float
376375
innovation drift
377-
scale: tensor_like of float
376+
scale : tensor_like of float
378377
pos def matrix, innovation covariance matrix
379-
tau: tensor_like of float
378+
tau : tensor_like of float
380379
pos def matrix, inverse covariance matrix
381-
chol: tensor_like of float
380+
chol : tensor_like of float
382381
Cholesky decomposition of covariance matrix
383382
lower : bool, default=True
384383
Whether the cholesky fatcor is given as a lower triangular matrix.
385-
init_dist: distribution
386-
Unnamed multivariate distribution of the initial value. Unnamed refers to distributions
387-
created with the ``.dist()`` API.
384+
init_dist : unnamed_distribution
385+
Unnamed multivariate distribution of the initial value.
388386
389387
.. warning:: init_dist will be cloned, rendering them independent of the ones passed as input.
390388
@@ -471,9 +469,8 @@ class AR(Distribution):
471469
constant : bool, default False
472470
Whether the first element of rho should be used as a constant term in the AR
473471
process.
474-
init_dist : unnamed distribution, optional
475-
Scalar or vector distribution for initial values. Unnamed refers to distributions
476-
created with the ``.dist()`` API. Distributions should have shape (*shape[:-1], ar_order).
472+
init_dist : unnamed_distribution, optional
473+
Scalar or vector distribution for initial values. Distributions should have shape (*shape[:-1], ar_order).
477474
If not, it will be automatically resized. Defaults to pm.Normal.dist(0, 100, shape=...).
478475
479476
.. warning:: init_dist will be cloned, rendering it independent of the one passed as input.
@@ -755,13 +752,13 @@ class GARCH11(Distribution):
755752
756753
Parameters
757754
----------
758-
omega: tensor
755+
omega : tensor_like of float
759756
omega > 0, mean variance
760-
alpha_1: tensor
757+
alpha_1 : tensor_like of float
761758
alpha_1 >= 0, autoregressive term coefficient
762-
beta_1: tensor
759+
beta_1 : tensor_like of float
763760
beta_1 >= 0, alpha_1 + beta_1 < 1, moving average term coefficient
764-
initial_vol: tensor
761+
initial_vol : tensor_like of float
765762
initial_vol >= 0, initial volatility, sigma_0
766763
"""
767764

@@ -922,9 +919,8 @@ class EulerMaruyama(Distribution):
922919
function returning the drift and diffusion coefficients of SDE
923920
sde_pars : tuple
924921
parameters of the SDE, passed as ``*args`` to ``sde_fn``
925-
init_dist : unnamed distribution, optional
926-
Scalar distribution for initial values. Unnamed refers to distributions created with
927-
the ``.dist()`` API. Distributions should have shape (*shape[:-1]).
922+
init_dist : unnamed_distribution, optional
923+
Scalar distribution for initial values. Distributions should have shape (*shape[:-1]).
928924
If not, it will be automatically resized. Defaults to pm.Normal.dist(0, 100, shape=...).
929925
930926
.. warning:: init_dist will be cloned, rendering it independent of the one passed as input.

0 commit comments

Comments
 (0)