Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add introductory kernel notebook and change style file path in notebooks #331

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions docs/_static/gpjax.mplstyle
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
figure.figsize: 5.5, 2.5
figure.constrained_layout.use: True
figure.autolayout: False
savefig.bbox: tight
figure.dpi: 120

# Axes
axes.spines.left: True # display axis spines
axes.spines.bottom: True
axes.spines.top: False
axes.spines.right: False
axes.grid: true
axes.axisbelow: true

### Fonts
mathtext.fontset: cm
font.family: serif
font.serif: Computer Modern Roman
font.size: 10
text.usetex: True

# Axes ticks
ytick.left: True
xtick.bottom: True
xtick.direction: out
ytick.direction: out

# Colour palettes
axes.prop_cycle: cycler('color', ['2F83B4','B5121B', 'F77F00', '0B6E4F', '7A68A6', 'C5BB36', '8c564b', 'e377c2'])
lines.color: B5121B
scatter.marker: x
image.cmap: inferno

### Grids
grid.linestyle: -
grid.linewidth: 0.2
grid.color: cbcbcb

### Legend
legend.frameon: True
legend.loc: best
legend.fontsize: 8
legend.fancybox: True
legend.scatterpoints: 1
legend.numpoints: 1

patch.antialiased: True

# set text objects edidable in Adobe Illustrator
pdf.fonttype: 42
ps.fonttype: 42

# no background
savefig.transparent: True
46 changes: 25 additions & 21 deletions docs/examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@ https://docs.jaxgaussianprocesses.com/

# How to build the docs

1. Install the requirements using `pip install -r docs/requirements.txt`
1. Ensure you have installed the requirements using `poetry install` in the root directory.
2. Make sure `pandoc` is installed
3. Run the make script `make html`
3. Run the command `poetry run mkdocs serve` in the root directory.

The corresponding HTML files can then be found in `docs/_build/html/`.
The documentation will then be served at an IP address printed, which can then be opened in
a browser of you choice e.g. `Serving on http://127.0.0.1:8000/`.

# How to write code documentation

Our documentation it is written in ReStructuredText for Sphinx. This is a
meta-language that is compiled into online documentation. For more details see
[Sphinx's documentation](https://www.sphinx-doc.org/en/master/usage/restructuredtext/index.html).
As a result, our docstrings adhere to a specific syntax that has to be kept in
mind. Below we provide some guidelines.
Our documentation is generated using [MkDocs](https://www.mkdocs.org/). This automatically creates online documentation
from docstrings, with full support for Markdown. Longer tutorial-style notebooks are also converted to webpages by MkDocs,
with these notebooks being stored in the `docs/examples` directory. If you write a new notebook and wish to add it to
the documentation website, add it to the `nav` section of the `mkdocs.yml` file found in the root directory.

Below we provide some guidelines for writing docstrings.

## How much information to put in a docstring

Expand Down Expand Up @@ -53,16 +55,13 @@ class Prior(AbstractPrior):
[mean](https://docs.jaxgaussianprocesses.com/api/mean_functions/)
and [kernel](https://docs.jaxgaussianprocesses.com/api/kernels/base/) function.

A Gaussian process prior parameterised by a mean function :math:`m(\\cdot)` and a kernel
function :math:`k(\\cdot, \\cdot)` is given by

.. math::

p(f(\\cdot)) = \mathcal{GP}(m(\\cdot), k(\\cdot, \\cdot)).
A Gaussian process prior parameterised by a mean function $`m(\cdot)`$ and a kernel
function $`k(\cdot, \cdot)`$ is given by
$`p(f(\cdot)) = \mathcal{GP}(m(\cdot), k(\cdot, \cdot))`$.
thomaspinder marked this conversation as resolved.
Show resolved Hide resolved

To invoke a ``Prior`` distribution, only a kernel function is required. By default,
the mean function will be set to zero. In general, this assumption will be reasonable
assuming the data being modelled has been centred.
To invoke a `Prior` distribution, only a kernel function is required. By
default, the mean function will be set to zero. In general, this assumption
Thomas-Christie marked this conversation as resolved.
Show resolved Hide resolved
will be reasonable assuming the data being modelled has been centred.

Example:
>>> import gpjax as gpx
Expand All @@ -84,10 +83,15 @@ class Prior(AbstractPrior):

### Documentation syntax

A helpful cheatsheet for writing restructured text can be found
[here](https://github.com/ralsina/rst-cheatsheet/blob/master/rst-cheatsheet.rst). In addition to that, we adopt the following convention when documenting
`` objects.
We adopt the following convention when documenting objects:

* Class attributes should be specified using the `Attributes:` tag.
* Method argument should be specified using the `Args:` tags.
* All attributes and arguments should have types.
* Values returned by a method should be specified using the `Returns:` tag.
* All attributes, arguments and returned values should have types.

!!! attention "Note"

Inline math in docstrings needs to be rendered within both `$` and `` symbols to be correctly rendered by MkDocs.
For instance, where one would typically write `$k(x,y)$` in standard LaTeX, in docstrings you are required to
write ``$`k(x,y)`$`` in order for the math to be correctly rendered by MkDocs.
4 changes: 3 additions & 1 deletion docs/examples/barycentres.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@


key = jr.PRNGKey(123)
plt.style.use("./gpjax.mplstyle")
plt.style.use(
"https://raw.githubusercontent.com/JaxGaussianProcesses/GPJax/main/docs/examples/gpjax.mplstyle"
)
cols = plt.rcParams["axes.prop_cycle"].by_key()["color"]

# %% [markdown]
Expand Down
4 changes: 3 additions & 1 deletion docs/examples/classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@
tfd = tfp.distributions
identity_matrix = jnp.eye
key = jr.PRNGKey(123)
plt.style.use("./gpjax.mplstyle")
plt.style.use(
"https://raw.githubusercontent.com/JaxGaussianProcesses/GPJax/main/docs/examples/gpjax.mplstyle"
)
cols = plt.rcParams["axes.prop_cycle"].by_key()["color"]

# %% [markdown]
Expand Down
4 changes: 3 additions & 1 deletion docs/examples/collapsed_vi.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@
import gpjax as gpx

key = jr.PRNGKey(123)
plt.style.use("./gpjax.mplstyle")
plt.style.use(
"https://raw.githubusercontent.com/JaxGaussianProcesses/GPJax/main/docs/examples/gpjax.mplstyle"
)
cols = mpl.rcParams["axes.prop_cycle"].by_key()["color"]

# %% [markdown]
Expand Down
4 changes: 3 additions & 1 deletion docs/examples/deep_kernels.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@
from gpjax.kernels.computations import AbstractKernelComputation

key = jr.PRNGKey(123)
plt.style.use("./gpjax.mplstyle")
plt.style.use(
"https://raw.githubusercontent.com/JaxGaussianProcesses/GPJax/main/docs/examples/gpjax.mplstyle"
)
cols = mpl.rcParams["axes.prop_cycle"].by_key()["color"]

# %% [markdown]
Expand Down
4 changes: 3 additions & 1 deletion docs/examples/graph_kernels.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
import gpjax as gpx

key = jr.PRNGKey(123)
plt.style.use("./gpjax.mplstyle")
plt.style.use(
"https://raw.githubusercontent.com/JaxGaussianProcesses/GPJax/main/docs/examples/gpjax.mplstyle"
)
cols = mpl.rcParams["axes.prop_cycle"].by_key()["color"]

# %% [markdown]
Expand Down
4 changes: 3 additions & 1 deletion docs/examples/intro_to_gps.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@
import tensorflow_probability.substrates.jax as tfp
from docs.examples.utils import confidence_ellipse

plt.style.use("./gpjax.mplstyle")
plt.style.use(
"https://raw.githubusercontent.com/JaxGaussianProcesses/GPJax/main/docs/examples/gpjax.mplstyle"
)
cols = mpl.rcParams["axes.prop_cycle"].by_key()["color"]
tfd = tfp.distributions

Expand Down
Loading