Skip to content

Commit 96ff04a

Browse files
authored
Initial implementation of Sphinx docs (#6)
* Touch up documentation for HMC * Initial pass at documentation * Blackify docs/conf.py
1 parent d028de4 commit 96ff04a

File tree

7 files changed

+156
-15
lines changed

7 files changed

+156
-15
lines changed

docs/Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line, and also
5+
# from the environment for the first two.
6+
SPHINXOPTS ?=
7+
SPHINXBUILD ?= sphinx-build
8+
SOURCEDIR = .
9+
BUILDDIR = _build
10+
11+
# Put it first so that "make" without argument is like "make help".
12+
help:
13+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14+
15+
.PHONY: help Makefile
16+
17+
# Catch-all target: route all unknown targets to Sphinx using the new
18+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19+
%: Makefile
20+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

docs/conf.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Configuration file for the Sphinx documentation builder.
2+
#
3+
# This file only contains a selection of the most common options. For a full
4+
# list see the documentation:
5+
# https://www.sphinx-doc.org/en/master/usage/configuration.html
6+
7+
# -- Path setup --------------------------------------------------------------
8+
9+
# If extensions (or modules to document with autodoc) are in another directory,
10+
# add these directories to sys.path here. If the directory is relative to the
11+
# documentation root, use os.path.abspath to make it absolute, like shown here.
12+
#
13+
# import os
14+
# import sys
15+
# sys.path.insert(0, os.path.abspath('.'))
16+
17+
18+
# -- Project information -----------------------------------------------------
19+
20+
project = "littlemcmc"
21+
copyright = "2019, George Ho"
22+
author = "George Ho"
23+
24+
# The full version, including alpha/beta/rc tags
25+
release = "0.1.0"
26+
27+
28+
# -- General configuration ---------------------------------------------------
29+
30+
# Add any Sphinx extension module names here, as strings. They can be
31+
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
32+
# ones.
33+
extensions = [
34+
"sphinx.ext.autodoc",
35+
"sphinx_rtd_theme",
36+
]
37+
38+
# Add any paths that contain templates here, relative to this directory.
39+
templates_path = ["_templates"]
40+
41+
# List of patterns, relative to source directory, that match files and
42+
# directories to ignore when looking for source files.
43+
# This pattern also affects html_static_path and html_extra_path.
44+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
45+
46+
47+
# -- Options for HTML output -------------------------------------------------
48+
49+
# The theme to use for HTML and HTML Help pages. See the documentation for
50+
# a list of builtin themes.
51+
#
52+
html_theme = "sphinx_rtd_theme"
53+
54+
# Add any paths that contain custom static files (such as style sheets) here,
55+
# relative to this directory. They are copied after the builtin static files,
56+
# so a file named 'default.css' will overwrite the builtin 'default.css'.
57+
html_static_path = ["_static"]

docs/index.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.. littlemcmc documentation master file, created by
2+
sphinx-quickstart on Sat Dec 14 22:49:04 2019.
3+
You can adapt this file completely to your liking, but it should at least
4+
contain the root `toctree` directive.
5+
6+
Welcome to littlemcmc's documentation!
7+
======================================
8+
9+
.. toctree::
10+
:maxdepth: 2
11+
:caption: Contents:
12+
13+
14+
15+
Indices and tables
16+
==================
17+
18+
* :ref:`genindex`
19+
* :ref:`modindex`
20+
* :ref:`search`

docs/make.bat

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
@ECHO OFF
2+
3+
pushd %~dp0
4+
5+
REM Command file for Sphinx documentation
6+
7+
if "%SPHINXBUILD%" == "" (
8+
set SPHINXBUILD=sphinx-build
9+
)
10+
set SOURCEDIR=.
11+
set BUILDDIR=_build
12+
13+
if "%1" == "" goto help
14+
15+
%SPHINXBUILD% >NUL 2>NUL
16+
if errorlevel 9009 (
17+
echo.
18+
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
19+
echo.installed, then set the SPHINXBUILD environment variable to point
20+
echo.to the full path of the 'sphinx-build' executable. Alternatively you
21+
echo.may add the Sphinx directory to PATH.
22+
echo.
23+
echo.If you don't have Sphinx installed, grab it from
24+
echo.http://sphinx-doc.org/
25+
exit /b 1
26+
)
27+
28+
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
29+
goto end
30+
31+
:help
32+
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
33+
34+
:end
35+
popd

littlemcmc/base_hmc.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Base class for Hamiltonian Monte Carlo."""
1+
"""Base class for Hamiltonian Monte Carlo samplers."""
22

33
from collections import namedtuple
44
import numpy as np
@@ -82,12 +82,18 @@ def __init__(
8282
dtype
8383
Emax
8484
target_accept
85-
gamma
86-
k
87-
t0
88-
adapt_step_size
85+
gamma : float, default .05
86+
k : float, default .75
87+
Parameter for dual averaging for step size adaptation. Values
88+
between 0.5 and 1 (exclusive) are admissible. Higher values
89+
correspond to slower adaptation.
90+
t0 : int, default 10
91+
Parameter for dual averaging. Higher values slow initial adaptation.
92+
adapt_step_size : bool, default=True
93+
If True, performs dual averaging step size adaptation. If False,
94+
`k`, `t0`, `gamma` and `target_accept` are ignored.
8995
step_rand : Python callable
90-
Called on step size to randomize, immediate before adapting step
96+
Called on step size to randomize, immediately before adapting step
9197
size.
9298
"""
9399
self._logp_dlogp_func = logp_dlogp_func

littlemcmc/hmc.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ def unif(step_size, elow=0.85, ehigh=1.15):
1616
class HamiltonianMC(BaseHMC):
1717
r"""A sampler for continuous variables based on Hamiltonian mechanics.
1818
19-
See NUTS sampler for automatically tuned stopping time and step size scaling.
19+
See NUTS sampler for automatically tuned stopping time and step size
20+
scaling.
2021
"""
2122

2223
name = "hmc"
@@ -73,12 +74,11 @@ def __init__(
7374
`energy`, and `random` methods. It can be specified instead
7475
of the scaling matrix.
7576
target_accept : float, default .8
76-
Adapt the step size such that the average acceptance
77-
probability across the trajectories are close to target_accept.
78-
Higher values for target_accept lead to smaller step sizes.
79-
Setting this to higher values like 0.9 or 0.99 can help
80-
with sampling from difficult posteriors. Valid values are
81-
between 0 and 1 (exclusive).
77+
Adapt the step size such that the average acceptance probability
78+
across the trajectories are close to target_accept. Higher values
79+
for target_accept lead to smaller step sizes. Setting this to higher
80+
values like 0.9 or 0.99 can help with sampling from difficult
81+
posteriors. Valid values are between 0 and 1 (exclusive).
8282
gamma : float, default .05
8383
k : float, default .75
8484
Parameter for dual averaging for step size adaptation. Values
@@ -88,8 +88,8 @@ def __init__(
8888
Parameter for dual averaging. Higher values slow initial
8989
adaptation.
9090
adapt_step_size : bool, default=True
91-
Whether step size adaptation should be enabled. If this is
92-
disabled, `k`, `t0`, `gamma` and `target_accept` are ignored.
91+
If True, performs dual averaging step size adaptation. If False,
92+
`k`, `t0`, `gamma` and `target_accept` are ignored.
9393
**kwargs : passed to BaseHMC
9494
"""
9595
super(HamiltonianMC, self).__init__(**kwargs)

requirements-dev.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ pylint
66
pytest
77
pytest-cov
88
pytest-html
9+
recommonmark
10+
sphinx
11+
sphinx-rtd-theme

0 commit comments

Comments
 (0)