Skip to content

Commit 0152862

Browse files
committed
Write docstrings in imperative mood (D401)
1 parent c209f99 commit 0152862

39 files changed

+142
-132
lines changed

pymc/backends/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def _init_trace(
101101
model: Model,
102102
trace_vars: list[TensorVariable] | None = None,
103103
) -> BaseTrace:
104-
"""Initializes a trace backend for a chain."""
104+
"""Initialize a trace backend for a chain."""
105105
strace: BaseTrace
106106
if trace is None:
107107
strace = NDArray(model=model, vars=trace_vars)
@@ -126,7 +126,7 @@ def init_traces(
126126
model: Model,
127127
trace_vars: list[TensorVariable] | None = None,
128128
) -> tuple[RunType | None, Sequence[IBaseTrace]]:
129-
"""Initializes a trace recorder for each chain."""
129+
"""Initialize a trace recorder for each chain."""
130130
if HAS_MCB and isinstance(backend, Backend):
131131
return init_chain_adapters(
132132
backend=backend,

pymc/backends/mcbackend.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444

4545
def find_data(pmodel: Model) -> list[mcb.DataVariable]:
46-
"""Extracts data variables from a model."""
46+
"""Extract data variables from a model."""
4747
observed_rvs = {pmodel.rvs_to_values[rv] for rv in pmodel.observed_RVs}
4848
dvars = []
4949
# All data containers are named vars!
@@ -131,7 +131,7 @@ def get_values(self, varname: str, burn=0, thin=1) -> np.ndarray:
131131
return self._chain.get_draws(varname, slice(burn, None, thin))
132132

133133
def _get_stats(self, fname: str, slc: slice) -> np.ndarray:
134-
"""Wraps `self._chain.get_stats` but unpickles automatically."""
134+
"""Wrap `self._chain.get_stats` but unpickle automatically."""
135135
values = self._chain.get_stats(fname, slc)
136136
# Unpickle object stats
137137
if fname in self._statsbj.object_stats:

pymc/data.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353

5454

5555
def get_data(filename):
56-
"""Returns a BytesIO object for a package data file.
56+
"""Return a BytesIO object for a package data file.
5757
5858
Parameters
5959
----------
@@ -224,7 +224,7 @@ def determine_coords(
224224
dims: Sequence[str | None] | None = None,
225225
coords: dict[str, Sequence | np.ndarray] | None = None,
226226
) -> tuple[dict[str, Sequence | np.ndarray], Sequence[str | None]]:
227-
"""Determines coordinate values from data or the model (via ``dims``)."""
227+
"""Determine coordinate values from data or the model (via ``dims``)."""
228228
if coords is None:
229229
coords = {}
230230

@@ -343,7 +343,7 @@ def Data(
343343
mutable: bool | None = None,
344344
**kwargs,
345345
) -> SharedVariable | TensorConstant:
346-
"""Data container that registers a data variable with the model.
346+
"""Create a data container that registers a data variable with the model.
347347
348348
Depending on the ``mutable`` setting (default: True), the variable
349349
is registered as a :class:`~pytensor.compile.sharedvalue.SharedVariable`,

pymc/distributions/dist_math.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def check_icdf_value(expr: Variable, value: Variable) -> Variable:
9090

9191

9292
def logpow(x, m):
93-
"""Calculates log(x**m) since m*log(x) will fail when m, x = 0."""
93+
"""Calculate log(x**m) since m*log(x) will fail when m, x = 0."""
9494
# return m * log(x)
9595
return pt.switch(pt.eq(x, 0), pt.switch(pt.eq(m, 0), 0.0, -np.inf), m * pt.log(x))
9696

@@ -108,7 +108,7 @@ def betaln(x, y):
108108

109109

110110
def std_cdf(x):
111-
"""Calculates the standard normal cumulative distribution function."""
111+
"""Calculate the standard normal cumulative distribution function."""
112112
return 0.5 + 0.5 * pt.erf(x / pt.sqrt(2.0))
113113

114114

@@ -400,7 +400,7 @@ def multigammaln(a, p):
400400

401401

402402
def log_i0(x):
403-
"""Calculates the logarithm of the 0 order modified Bessel function of the first kind."""
403+
"""Calculate the logarithm of the 0 order modified Bessel function of the first kind."""
404404
return pt.switch(
405405
pt.lt(x, 5),
406406
pt.log1p(

pymc/distributions/distribution.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ def update(self, node: Apply) -> dict[Variable, Variable]:
392392
return collect_default_updates_inner_fgraph(node)
393393

394394
def batch_ndim(self, node: Apply) -> int:
395-
"""Number of dimensions of the distribution's batch shape."""
395+
"""Return the number of dimensions of the distribution's batch shape."""
396396
out_ndim = max(getattr(out.type, "ndim", 0) for out in node.outputs)
397397
return out_ndim - self.ndim_supp
398398

@@ -438,7 +438,7 @@ def __new__(
438438
default_transform=UNSET,
439439
**kwargs,
440440
) -> TensorVariable:
441-
"""Adds a tensor variable corresponding to a PyMC distribution to the current model.
441+
"""Add a tensor variable corresponding to a PyMC distribution to the current model.
442442
443443
Note that all remaining kwargs must be compatible with ``.dist()``
444444
@@ -531,7 +531,7 @@ def dist(
531531
shape: Shape | None = None,
532532
**kwargs,
533533
) -> TensorVariable:
534-
"""Creates a tensor variable corresponding to the `cls` distribution.
534+
"""Create a tensor variable corresponding to the `cls` distribution.
535535
536536
Parameters
537537
----------
@@ -604,8 +604,7 @@ def _support_point(op, rv, *rv_inputs) -> TensorVariable:
604604

605605

606606
def support_point(rv: TensorVariable) -> TensorVariable:
607-
"""Method for choosing a representative point/value
608-
that can be used to start optimization or MCMC sampling.
607+
"""Choose a representative point/value that can be used to start optimization or MCMC sampling.
609608
610609
The only parameter to this function is the RandomVariable
611610
for which the value is to be derived.

pymc/distributions/mixture.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -555,9 +555,9 @@ def dist(cls, w, mu, sigma=None, tau=None, **kwargs):
555555

556556

557557
def _zero_inflated_mixture(*, name, nonzero_p, nonzero_dist, **kwargs):
558-
"""Helper function to create a zero-inflated mixture.
558+
"""Create a zero-inflated mixture (helper function).
559559
560-
If name is `None`, this function returns an unregistered variable
560+
If name is `None`, this function returns an unregistered variable.
561561
"""
562562
nonzero_p = pt.as_tensor_variable(nonzero_p)
563563
weights = pt.stack([1 - nonzero_p, nonzero_p], axis=-1)
@@ -799,7 +799,7 @@ def dist(cls, psi, mu=None, alpha=None, p=None, n=None, **kwargs):
799799

800800

801801
def _hurdle_mixture(*, name, nonzero_p, nonzero_dist, dtype, max_n_steps=10_000, **kwargs):
802-
"""Helper function to create a hurdle mixtures.
802+
"""Create a hurdle mixtures (helper function).
803803
804804
If name is `None`, this function returns an unregistered variable
805805

pymc/distributions/multivariate.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ def precision_mv_normal_logp(op: PrecisionMvNormalRV, value, rng, size, mean, ta
342342

343343
@node_rewriter(tracks=[MvNormalRV])
344344
def mv_normal_to_precision_mv_normal(fgraph, node):
345-
"""Replaces MvNormal(mu, inv(tau)) -> PrecisionMvNormal(mu, tau).
345+
"""Replace MvNormal(mu, inv(tau)) -> PrecisionMvNormal(mu, tau).
346346
347347
This is introduced in logprob rewrites to provide a more efficient logp for a MvNormal
348348
that is defined by a precision matrix.
@@ -2153,7 +2153,8 @@ def make_node(self, rng, size, mu, W, alpha, tau, W_is_valid):
21532153

21542154
@classmethod
21552155
def rng_fn(cls, rng: np.random.RandomState, mu, W, alpha, tau, W_is_valid, size):
2156-
"""
2156+
"""Sample a numeric random variate.
2157+
21572158
Implementation of algorithm from paper
21582159
Havard Rue, 2001. "Fast sampling of Gaussian Markov random fields,"
21592160
Journal of the Royal Statistical Society Series B, Royal Statistical Society,

pymc/distributions/shape_utils.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def convert_size(size: Size) -> StrongSize | None:
149149

150150

151151
def shape_from_dims(dims: StrongDims, model) -> StrongShape:
152-
"""Determines shape from a `dims` tuple.
152+
"""Determine shape from a `dims` tuple.
153153
154154
Parameters
155155
----------
@@ -178,7 +178,7 @@ def find_size(
178178
size: StrongSize | None,
179179
ndim_supp: int,
180180
) -> StrongSize | None:
181-
"""Determines the size keyword argument for creating a Distribution.
181+
"""Determine the size keyword argument for creating a Distribution.
182182
183183
Parameters
184184
----------
@@ -436,7 +436,11 @@ def get_support_shape_1d(
436436
observed: Any | None = None,
437437
support_shape_offset: int = 0,
438438
) -> TensorVariable | None:
439-
"""Helper function for cases when you just care about one dimension."""
439+
"""
440+
Extract the support shapes from shape / dims / observed information.
441+
442+
Helper function for cases when you just care about one dimension.
443+
"""
440444
support_shape_tuple = get_support_shape(
441445
support_shape=(support_shape,) if support_shape is not None else None,
442446
shape=shape,

pymc/gp/cov.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def __pow__(self, other) -> "Exponentiated":
114114
return Exponentiated(self, other)
115115

116116
def __array_wrap__(self, result):
117-
"""Required to allow radd/rmul by numpy arrays."""
117+
"""Allow radd/rmul by numpy arrays."""
118118
result = np.squeeze(result)
119119
if len(result.shape) <= 1:
120120
result = result.reshape(1, 1)
@@ -234,7 +234,7 @@ def __init__(self, factor_list: Sequence):
234234
self._factor_list.append(factor)
235235

236236
def _merge_factors_cov(self, X, Xs=None, diag=False):
237-
"""Called to evaluate either all the sums or all the
237+
"""Evaluate either all the sums or all the
238238
products of kernels that are possible to evaluate.
239239
"""
240240
factor_list = []
@@ -264,12 +264,12 @@ def _merge_factors_cov(self, X, Xs=None, diag=False):
264264
return factor_list
265265

266266
def _merge_factors_psd(self, omega):
267-
"""Called to evaluatate spectral densities of combination kernels when possible.
267+
"""Evaluate spectral densities of combination kernels when possible.
268268
269-
Implements
270-
a more restricted set of rules than `_merge_factors_cov` -- just additivity of stationary
271-
covariances with defined power spectral densities and multiplication by scalars. Also, the
272-
active_dims for all covariances in the sum must be the same.
269+
Implements a more restricted set of rules than `_merge_factors_cov` --
270+
just additivity of stationary covariances with defined power spectral
271+
densities and multiplication by scalars. Also, the active_dims for all
272+
covariances in the sum must be the same.
273273
"""
274274
factor_list = []
275275
for factor in self._factor_list:

pymc/gp/gp.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747

4848

4949
def _handle_sigma_noise_parameters(sigma, noise):
50-
"""Helper function for transition of 'noise' parameter to be named 'sigma'."""
50+
"""Help transition of 'noise' parameter to be named 'sigma'."""
5151
if (sigma is None and noise is None) or (sigma is not None and noise is not None):
5252
raise ValueError("'sigma' argument must be specified.")
5353

@@ -177,7 +177,7 @@ def _build_prior(
177177

178178
def prior(self, name, X, n_outputs=1, reparameterize=True, jitter=JITTER_DEFAULT, **kwargs):
179179
R"""
180-
Returns the GP prior distribution evaluated over the input
180+
Return the GP prior distribution evaluated over the input
181181
locations `X`.
182182
183183
This is the prior probability over the space
@@ -250,7 +250,7 @@ def _build_conditional(self, Xnew, X, f, cov_total, mean_total, jitter):
250250

251251
def conditional(self, name, Xnew, given=None, jitter=JITTER_DEFAULT, **kwargs):
252252
R"""
253-
Returns the conditional distribution evaluated over new input
253+
Return the conditional distribution evaluated over new input
254254
locations `Xnew`.
255255
256256
Given a set of function values `f` that
@@ -350,7 +350,7 @@ def _build_prior(self, name, X, reparameterize=True, jitter=JITTER_DEFAULT, **kw
350350

351351
def prior(self, name, X, reparameterize=True, jitter=JITTER_DEFAULT, **kwargs):
352352
R"""
353-
Returns the TP prior distribution evaluated over the input
353+
Return the TP prior distribution evaluated over the input
354354
locations `X`.
355355
356356
This is the prior probability over the space
@@ -394,7 +394,7 @@ def _build_conditional(self, Xnew, X, f, jitter):
394394

395395
def conditional(self, name, Xnew, jitter=JITTER_DEFAULT, **kwargs):
396396
R"""
397-
Returns the conditional distribution evaluated over new input
397+
Return the conditional distribution evaluated over new input
398398
locations `Xnew`.
399399
400400
Given a set of function values `f` that
@@ -487,7 +487,7 @@ def marginal_likelihood(
487487
**kwargs,
488488
):
489489
R"""
490-
Returns the marginal likelihood distribution, given the input
490+
Return the marginal likelihood distribution, given the input
491491
locations `X` and the data `y`.
492492
493493
This is the integral over the product of the GP prior and a normal likelihood.
@@ -594,7 +594,7 @@ def conditional(
594594
self, name, Xnew, pred_noise=False, given=None, jitter=JITTER_DEFAULT, **kwargs
595595
):
596596
R"""
597-
Returns the conditional distribution evaluated over new input
597+
Return the conditional distribution evaluated over new input
598598
locations `Xnew`.
599599
600600
Given a set of function values `f` that the GP prior was over, the
@@ -814,7 +814,7 @@ def marginal_likelihood(
814814
self, name, X, Xu, y, sigma=None, noise=None, jitter=JITTER_DEFAULT, **kwargs
815815
):
816816
R"""
817-
Returns the approximate marginal likelihood distribution, given the input
817+
Return the approximate marginal likelihood distribution, given the input
818818
locations `X`, inducing point locations `Xu`, data `y`, and white noise
819819
standard deviations `sigma`.
820820
@@ -906,7 +906,7 @@ def conditional(
906906
self, name, Xnew, pred_noise=False, given=None, jitter=JITTER_DEFAULT, **kwargs
907907
):
908908
R"""
909-
Returns the approximate conditional distribution of the GP evaluated over
909+
Return the approximate conditional distribution of the GP evaluated over
910910
new input locations `Xnew`.
911911
912912
Parameters
@@ -1019,7 +1019,7 @@ def _build_prior(self, name, Xs, jitter, **kwargs):
10191019

10201020
def prior(self, name, Xs, jitter=JITTER_DEFAULT, **kwargs):
10211021
"""
1022-
Returns the prior distribution evaluated over the input
1022+
Return the prior distribution evaluated over the input
10231023
locations `Xs`.
10241024
10251025
Parameters
@@ -1065,7 +1065,7 @@ def _build_conditional(self, Xnew, jitter):
10651065

10661066
def conditional(self, name, Xnew, jitter=JITTER_DEFAULT, **kwargs):
10671067
"""
1068-
Returns the conditional distribution evaluated over new input
1068+
Return the conditional distribution evaluated over new input
10691069
locations `Xnew`.
10701070
10711071
`Xnew` will be split by columns and fed to the relevant
@@ -1188,7 +1188,7 @@ def _check_inputs(self, Xs, y):
11881188

11891189
def marginal_likelihood(self, name, Xs, y, sigma, is_observed=True, **kwargs):
11901190
"""
1191-
Returns the marginal likelihood distribution, given the input
1191+
Return the marginal likelihood distribution, given the input
11921192
locations `cartesian(*Xs)` and the data `y`.
11931193
11941194
Parameters
@@ -1267,7 +1267,7 @@ def _build_conditional(self, Xnew, diag, pred_noise):
12671267

12681268
def conditional(self, name, Xnew, pred_noise=False, diag=False, **kwargs):
12691269
"""
1270-
Returns the conditional distribution evaluated over new input
1270+
Return the conditional distribution evaluated over new input
12711271
locations `Xnew`, just as in `Marginal`.
12721272
12731273
`Xnew` will be split by columns and fed to the relevant

pymc/gp/hsgp_approx.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ def calc_basis_periodic(
9393
def approx_hsgp_hyperparams(
9494
x_range: list[float], lengthscale_range: list[float], cov_func: str
9595
) -> tuple[int, float]:
96-
"""Utility function that uses heuristics to recommend minimum `m` and `c` values,
97-
based on recommendations from Ruitort-Mayol et. al.
96+
"""Use heuristics to recommend minimum `m` and `c` values, based on recommendations from Ruitort-Mayol et. al.
9897
9998
In practice, you need to choose `c` large enough to handle the largest lengthscales,
10099
and `m` large enough to accommodate the smallest lengthscales. Use your prior on the
@@ -427,7 +426,7 @@ def prior(
427426
**kwargs,
428427
): # type: ignore
429428
R"""
430-
Returns the (approximate) GP prior distribution evaluated over the input locations `X`.
429+
Return the (approximate) GP prior distribution evaluated over the input locations `X`.
431430
For usage examples, refer to `pm.gp.Latent`.
432431
433432
Parameters
@@ -490,7 +489,7 @@ def _build_conditional(self, Xnew):
490489

491490
def conditional(self, name: str, Xnew: TensorLike, dims: str | None = None): # type: ignore
492491
R"""
493-
Returns the (approximate) conditional distribution evaluated over new input locations
492+
Return the (approximate) conditional distribution evaluated over new input locations
494493
`Xnew`.
495494
496495
Parameters
@@ -685,7 +684,7 @@ def prior_linearized(self, X: TensorLike):
685684

686685
def prior(self, name: str, X: TensorLike, dims: str | None = None): # type: ignore
687686
R"""
688-
Returns the (approximate) GP prior distribution evaluated over the input locations `X`.
687+
Return the (approximate) GP prior distribution evaluated over the input locations `X`.
689688
For usage examples, refer to `pm.gp.Latent`.
690689
691690
Parameters
@@ -736,7 +735,7 @@ def _build_conditional(self, Xnew):
736735

737736
def conditional(self, name: str, Xnew: TensorLike, dims: str | None = None): # type: ignore
738737
R"""
739-
Returns the (approximate) conditional distribution evaluated over new input locations
738+
Return the (approximate) conditional distribution evaluated over new input locations
740739
`Xnew`.
741740
742741
Parameters

0 commit comments

Comments
 (0)