Skip to content

Commit ccf03b3

Browse files
rpgoldmanColCarroll
authored andcommitted
WIP: Documentation cleanup (#3575)
* Fix typos in docstrings. Fix some minor wording errors, but mostly fixed formatting issues. * Update sphinx configuration. Updated to make a deprecation warning go away. This should not change the behavior at all. * Update MultiTrace docs. Minor typo fixes and added MultiTrace attributes section. * Fix RST issues in documentation. * Remove obsolete file. The `getting_started.rst` file does not yield output that is linked into the docs. Instead, the index.rst file directly links to the pages once linked from getting_started.
1 parent c1e272c commit ccf03b3

File tree

18 files changed

+96
-91
lines changed

18 files changed

+96
-91
lines changed

docs/source/Gaussian_Processes.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ all columns of the matrix of inputs.
8888
Covariance functions in PyMC3 closely follow the algebraic rules for kernels,
8989
which allows users to combine covariance functions into new ones, for example:
9090

91-
- The sum two covariance functions is also a covariance function::
91+
- The sum of two covariance functions is also a covariance function::
9292

9393

9494
cov_func = pm.gp.cov.ExpQuad(...) + pm.gp.cov.ExpQuad(...)
@@ -98,12 +98,14 @@ which allows users to combine covariance functions into new ones, for example:
9898

9999
cov_func = pm.gp.cov.ExpQuad(...) * pm.gp.cov.Periodic(...)
100100
101-
- The product (or sum) of a covariance function with a scalar is a covariance
102-
function::
101+
- The product (or sum) of a covariance function with a scalar is a
102+
covariance function::
103103

104104
105105
cov_func = eta**2 * pm.gp.cov.Matern32(...)
106106
107+
108+
107109
After the covariance function is defined, it is now a function that is
108110
evaluated by calling :code:`cov_func(x, x)` (or :code:`mean_func(x)`). Since
109111
PyMC3 is built on top of Theano, it is relatively easy to define and experiment

docs/source/api.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
.. _api:
22

3-
*************
3+
***************
44
API Reference
5-
*************
5+
***************
66

77
.. toctree::
88
:maxdepth: 2
@@ -24,7 +24,7 @@ API Reference
2424

2525

2626
Indices and tables
27-
===========
27+
===================
2828

2929
* :ref:`genindex`
3030
* :ref:`modindex`

docs/source/api/backends.rst

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,6 @@ Backends
77
.. automodule:: pymc3.backends
88
:members:
99

10-
basic Backends (including MultiTrace)
11-
^^^^^^^^
12-
13-
.. automodule:: pymc3.backends.base
14-
:members:
15-
16-
1710
ndarray
1811
^^^^^^^
1912

docs/source/api/bounds.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ Caveats
7272
an unnormalized probability distribution. This doesn't effect inference
7373
algorithms but may complicate some model comparison procedures.
7474

75-
API
76-
###
75+
Bounded Variable API
76+
####################
7777

7878

7979
.. currentmodule:: pymc3.distributions.bound

docs/source/api/gp.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
Gaussian Processes
2-
------------------
1+
Gaussian Processes API
2+
----------------------
33

44
.. currentmodule:: pymc3.gp.gp
55

docs/source/api/inference.rst

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ Sampling
1414
Step-methods
1515
^^^^^^^^^^^^
1616

17+
.. currentmodule:: pymc3.sampling
18+
19+
.. autofunction:: pymc3.sampling.assign_step_methods
20+
21+
1722
NUTS
1823
~~~~
1924

@@ -56,7 +61,7 @@ Sequential Monte Carlo
5661

5762

5863
MultiTrace
59-
^^^^^^^^
64+
^^^^^^^^^^
6065

6166
.. currentmodule:: pymc3.backends.base
6267
.. autoclass:: pymc3.backends.base.MultiTrace
@@ -65,7 +70,7 @@ MultiTrace
6570
.. autoclass:: pymc3.backends.base.BaseTrace
6671

6772
Variational Inference
68-
----------------
73+
---------------------
6974

7075
OPVI
7176
^^^^
@@ -75,8 +80,8 @@ OPVI
7580
.. automodule:: pymc3.variational.opvi
7681
:members:
7782

78-
Inference
79-
^^^^^^^^^
83+
VI Inference API
84+
^^^^^^^^^^^^^^^^
8085

8186
.. currentmodule:: pymc3.variational.inference
8287

docs/source/api/model_graph.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Graphing Models
2-
-------------
2+
---------------
33

44
.. currentmodule:: pymc3.model_graph
55
.. automodule:: pymc3.model_graph

docs/source/conf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@
4141
"numpydoc",
4242
"IPython.sphinxext.ipython_console_highlighting",
4343
"sphinx.ext.autosectionlabel",
44+
"sphinx.ext.napoleon",
4445
"gallery_generator",
46+
"recommonmark",
4547
]
4648

4749
# Don't auto-generate summary for class members.
@@ -59,7 +61,6 @@
5961
# The suffix(es) of source filenames.
6062
# You can specify multiple suffix as a list of string:
6163
# source_suffix = ['.rst', '.md']
62-
source_parsers = {".md": "recommonmark.parser.CommonMarkParser"}
6364
source_suffix = [".rst", ".md"]
6465

6566
# The encoding of source files.

docs/source/developer_guide.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ straightforward. In a perfect world, we should have
136136
follows a Gaussian distribution, and
137137
:math:`\chi = \text{Normal}(0, 1), x \sim \chi` which define a scalar
138138
density function that takes input :math:`x`
139+
140+
.. math::
139141
(``X:=f(x) = 1/sqrt(2*pi) * exp(-.5*x**2)``)
140142
141143
Within a model context, RVs are essentially Theano tensors (more on that
@@ -827,8 +829,8 @@ the input to the Theano function being a 1d vector (instead of a list of
827829
RV that each can have very different shape), thus it is very easy to do
828830
matrix operation like rotation etc.
829831
830-
Reflection
831-
~~~~~~~~~~
832+
Notes
833+
~~~~~
832834
833835
| The current setup is quite powerful, as the Theano compiled function
834836
is fairly fast to compile and to call. Also, when we are repeatedly

docs/source/getting_started.rst

Lines changed: 0 additions & 13 deletions
This file was deleted.

pymc3/backends/base.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def stat_names(self):
219219

220220

221221
class MultiTrace:
222-
"""Main interface for accessing values from MCMC results
222+
"""Main interface for accessing values from MCMC results.
223223
224224
The core method to select values is `get_values`. The method
225225
to select sampler statistics is `get_sampler_stats`. Both kinds of
@@ -256,6 +256,17 @@ class MultiTrace:
256256
For any methods that require a single trace (e.g., taking the length
257257
of the MultiTrace instance, which returns the number of draws), the
258258
trace with the highest chain number is always used.
259+
260+
Attributes
261+
----------
262+
nchains : int
263+
Number of chains in the `MultiTrace`.
264+
chains : `List[int]`
265+
List of chain indices
266+
report : str
267+
Report on the sampling process.
268+
varnames : `List[str]`
269+
List of variable names in the trace(s)
259270
"""
260271

261272
def __init__(self, straces):
@@ -363,19 +374,23 @@ def stat_names(self):
363374
names.update(vars.keys())
364375
return names
365376

366-
def add_values(self, vals, overwrite=False):
367-
"""add variables to traces.
377+
def add_values(self, vals, overwrite=False) -> None:
378+
"""Add variables to traces.
368379
369380
Parameters
370381
----------
371382
vals : dict (str: array-like)
372383
The keys should be the names of the new variables. The values are expected to be
373-
array-like object. For traces with more than one chain the length of each value
374-
should match the number of total samples already in the trace (chains * iterations),
384+
array-like objects. For traces with more than one chain the length of each value
385+
should match the number of total samples already in the trace `(chains * iterations)`,
375386
otherwise a warning is raised.
376387
overwrite : bool
377388
If `False` (default) a ValueError is raised if the variable already exists.
378389
Change to `True` to overwrite the values of variables
390+
391+
Returns
392+
-------
393+
Nothing.
379394
"""
380395
for k, v in vals.items():
381396
new_var = 1

pymc3/data.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ class Minibatch(tt.TensorVariable):
141141
if we want 1d slice of size 10 we do
142142
>>> x = Minibatch(data, batch_size=10)
143143
144-
Note, that your data is cast to `floatX` if it is not integer type
145-
But you still can add `dtype` kwarg for :class:`Minibatch`
144+
Note that your data is cast to `floatX` if it is not integer type
145+
But you still can add the `dtype` kwarg for :class:`Minibatch`
146146
147147
in case we want 10 sampled rows and columns
148148
`[(size, seed), (size, seed)]` it is

pymc3/distributions/continuous.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -589,8 +589,7 @@ class TruncatedNormal(BoundedContinuous):
589589
======== ==========================================
590590
Support :math:`x \in [a, b]`
591591
Mean :math:`\mu +{\frac {\phi (\alpha )-\phi (\beta )}{Z}}\sigma`
592-
Variance :math:`\sigma ^{2}\left[1+{\frac {\alpha \phi (\alpha )-\beta \phi (\beta )}{Z}}-
593-
\left({\frac {\phi (\alpha )-\phi (\beta )}{Z}}\right)^{2}\right]`
592+
Variance :math:`\sigma ^{2}\left[1+{\frac {\alpha \phi (\alpha )-\beta \phi (\beta )}{Z}}-\left({\frac {\phi (\alpha )-\phi (\beta )}{Z}}\right)^{2}\right]`
594593
======== ==========================================
595594
596595
Parameters
@@ -1544,14 +1543,14 @@ def _repr_latex_(self, name=None, dist=None):
15441543
get_variable_name(lam))
15451544

15461545
def logcdf(self, value):
1547-
"""
1546+
r"""
15481547
Compute the log of cumulative distribution function for the Exponential distribution
15491548
at the specified value.
15501549
15511550
References
15521551
----------
15531552
.. [Machler2012] Martin Mächler (2012).
1554-
"Accurately computing log(1-exp(-|a|)) Assessed by the Rmpfr
1553+
"Accurately computing :math: `\log(1-\exp(-\mid a \mid))` Assessed by the Rmpfr
15551554
package"
15561555
15571556
Parameters
@@ -1758,8 +1757,9 @@ class Lognormal(PositiveContinuous):
17581757
tau : float
17591758
Scale parameter (tau > 0). (only required if sigma is not specified).
17601759
1761-
Example
1762-
-------
1760+
Examples
1761+
--------
1762+
17631763
.. code-block:: python
17641764
17651765
# Example to show that we pass in only `sigma` or `tau` but not both.
@@ -2931,7 +2931,7 @@ def logcdf(self, value):
29312931
References
29322932
----------
29332933
.. [Machler2012] Martin Mächler (2012).
2934-
"Accurately computing log(1-exp(-|a|)) Assessed by the Rmpfr
2934+
"Accurately computing `\log(1-\exp(- \mid a \mid))` Assessed by the Rmpfr
29352935
package"
29362936
29372937
Parameters
@@ -4060,7 +4060,7 @@ def logcdf(self, value):
40604060
References
40614061
----------
40624062
.. [Machler2012] Martin Mächler (2012).
4063-
"Accurately computing log(1-exp(-|a|)) Assessed by the Rmpfr
4063+
"Accurately computing :math: `\log(1-\exp(- \mid a \mid<))` Assessed by the Rmpfr
40644064
package"
40654065
40664066
Parameters

pymc3/distributions/discrete.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,9 +1535,10 @@ class OrderedLogistic(Categorical):
15351535
ranges. Do not explicitly set the first and last elements of
15361536
:math:`c` to negative and positive infinity.
15371537
1538-
Example
1538+
Examples
15391539
--------
1540-
.. code:: python
1540+
1541+
.. code-block:: python
15411542
15421543
# Generate data for a simple 1 dimensional example problem
15431544
n1_c = 300; n2_c = 300; n3_c = 300

pymc3/distributions/timeseries.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ class EulerMaruyama(distribution.Continuous):
316316
sde_fn : callable
317317
function returning the drift and diffusion coefficients of SDE
318318
sde_pars : tuple
319-
parameters of the SDE, passed as *args to sde_fn
319+
parameters of the SDE, passed as `*args` to `sde_fn`
320320
"""
321321
def __init__(self, dt, sde_fn, sde_pars, *args, **kwds):
322322
super().__init__(*args, **kwds)

pymc3/math.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ def kron_matrix_op(krons, m, op):
5050
5151
Parameters
5252
-----------
53-
krons: list of square 2D array-like objects
54-
D square matrices [A_1, A_2, ..., A_D] to be Kronecker'ed:
55-
A = A_1 \otimes A_2 \otimes ... \otimes A_D
56-
Product of column dimensions must be N
53+
krons : list of square 2D array-like objects
54+
D square matrices :math:`[A_1, A_2, ..., A_D]` to be Kronecker'ed
55+
:math:`A = A_1 \otimes A_2 \otimes ... \otimes A_D`
56+
Product of column dimensions must be :math:`N`
5757
m : NxM array or 1D array (treated as Nx1)
5858
Object that krons act upon
5959
"""

0 commit comments

Comments
 (0)