Skip to content

Commit efc3cd8

Browse files
Set up documentation (#23)
* Set up documentation * Update docs/make.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent f083af8 commit efc3cd8

File tree

11 files changed

+221
-95
lines changed

11 files changed

+221
-95
lines changed

.github/workflows/CI.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ on:
66
- main
77
pull_request:
88

9+
concurrency:
10+
# Skip intermediate builds: always.
11+
# Cancel intermediate builds: only if it is a pull request build.
12+
group: ${{ github.workflow }}-${{ github.ref }}
13+
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
14+
915
jobs:
1016
test:
1117
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }}

.github/workflows/CompatHelper.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ jobs:
2424
- name: "Run CompatHelper"
2525
run: |
2626
import CompatHelper
27-
CompatHelper.main()
27+
CompatHelper.main(; subdirs=["", "docs"])
2828
shell: julia --color=yes {0}
2929
env:
3030
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
31-
COMPATHELPER_PRIV: ${{ secrets.COMPATHELPER_PRIV }}
31+
COMPATHELPER_PRIV: ${{ secrets.DOCUMENTER_KEY }}

.github/workflows/Docs.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Documentation
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
tags: '*'
8+
pull_request:
9+
10+
concurrency:
11+
# Skip intermediate builds: always.
12+
# Cancel intermediate builds: only if it is a pull request build.
13+
group: ${{ github.workflow }}-${{ github.ref }}
14+
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
15+
16+
jobs:
17+
docs:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v2
21+
- uses: julia-actions/setup-julia@latest
22+
with:
23+
version: '1'
24+
- name: Install dependencies
25+
run: julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
26+
- name: Build and deploy
27+
env:
28+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # For authentication with GitHub Actions token
29+
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} # For authentication with SSH deploy key
30+
JULIA_DEBUG: Documenter # Print `@debug` statements (https://github.com/JuliaDocs/Documenter.jl/issues/955)
31+
run: julia --project=docs/ docs/make.jl
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: DocsPreviewCleanup
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
7+
jobs:
8+
cleanup:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout gh-pages branch
12+
uses: actions/checkout@v2
13+
with:
14+
ref: gh-pages
15+
- name: Delete preview and history + push changes
16+
run: |
17+
if [ -d "previews/PR$PRNUM" ]; then
18+
git config user.name "Documenter.jl"
19+
git config user.email "[email protected]"
20+
git rm -rf "previews/PR$PRNUM"
21+
git commit -m "delete preview"
22+
git branch gh-pages-new $(echo "delete history" | git commit-tree HEAD^{tree})
23+
git push --force origin gh-pages-new:gh-pages
24+
fi
25+
env:
26+
PRNUM: ${{ github.event.number }}

.github/workflows/Format.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ name: Format
33
on:
44
pull_request:
55

6+
concurrency:
7+
# Skip intermediate builds: always.
8+
# Cancel intermediate builds: only if it is a pull request build.
9+
group: ${{ github.workflow }}-${{ github.ref }}
10+
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
11+
612
jobs:
713
format:
814
runs-on: ubuntu-latest
@@ -11,14 +17,15 @@ jobs:
1117
- uses: julia-actions/setup-julia@latest
1218
with:
1319
version: 1
14-
- name: Install JuliaFormatter and format code
20+
- name: Format code
1521
run: |
16-
using Pkg: Pkg
22+
using Pkg
1723
Pkg.add(; name="JuliaFormatter", uuid="98e50ef6-434e-11e9-1051-2b60c6c9e899")
1824
using JuliaFormatter
1925
format("."; verbose=true)
2026
shell: julia --color=yes {0}
2127
- uses: reviewdog/action-suggester@v1
28+
if: github.event_name == 'pull_request'
2229
with:
2330
tool_name: JuliaFormatter
2431
fail_on_error: true

.github/workflows/TagBot.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ jobs:
1212
- uses: JuliaRegistries/TagBot@v1
1313
with:
1414
token: ${{ secrets.GITHUB_TOKEN }}
15+
ssh: ${{ secrets.DOCUMENTER_KEY }}

README.md

Lines changed: 8 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
Julia implementation of elliptical slice sampling.
44

5-
[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
5+
[![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://turinglang.github.io/EllipticalSliceSampling.jl/stable)
6+
[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://turinglang.github.io/EllipticalSliceSampling.jl/dev)
67
[![Build Status](https://github.com/TuringLang/EllipticalSliceSampling.jl/workflows/CI/badge.svg?branch=main)](https://github.com/TuringLang/EllipticalSliceSampling.jl/actions?query=workflow%3ACI%20branch%3Amain)
78
[![Codecov](https://codecov.io/gh/TuringLang/EllipticalSliceSampling.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/TuringLang/EllipticalSliceSampling.jl)
89
[![Coveralls](https://coveralls.io/repos/github/TuringLang/EllipticalSliceSampling.jl/badge.svg?branch=main)](https://coveralls.io/github/TuringLang/EllipticalSliceSampling.jl?branch=main)
@@ -16,99 +17,15 @@ This package implements elliptical slice sampling in the Julia language, as desc
1617
Elliptical slice sampling is a "Markov chain Monte Carlo algorithm for performing
1718
inference in models with multivariate Gaussian priors" (Murray, Adams & MacKay (2010)).
1819

19-
Without loss of generality, the originally described algorithm assumes that the Gaussian
20-
prior has zero mean. For convenience we allow the user to specify arbitrary Gaussian
21-
priors with non-zero means and handle the change of variables internally.
20+
Please check the [documentation](https://turinglang.github.io/EllipticalSliceSampling.jl/stable)
21+
for more details.
2222

23-
## Usage
23+
## Poster at JuliaCon 2021
2424

25-
Probably most users would like to generate a MC Markov chain of samples from
26-
the posterior distribution by calling
27-
```julia
28-
sample([rng, ]ESSModel(prior, loglikelihood), ESS(), N[; kwargs...])
29-
```
30-
which returns a vector of `N` samples for approximating the posterior of
31-
a model with a Gaussian prior that allows sampling from the `prior` and
32-
evaluation of the log likelihood `loglikelihood`.
25+
[![EllipticalSliceSampling.jl: MCMC with Gaussian priors](http://img.youtube.com/vi/S5gUED7Uq2Q/0.jpg)](https://www.youtube.com/watch?v=S5gUED7Uq2Q)
3326

34-
You can sample multiple chains in parallel with multiple threads or processes
35-
by running
36-
```julia
37-
sample([rng, ]ESSModel(prior, loglikelihood), ESS(), MCMCThreads(), N, nchains[; kwargs...])
38-
```
39-
or
40-
```julia
41-
sample([rng, ]ESSModel(prior, loglikelihood), ESS(), MCMCDistributed(), N, nchains[; kwargs...])
42-
```
27+
The slides are available as [Pluto notebook](https://talks.widmann.dev/2021/07/ellipticalslicesampling/).
4328

44-
If you want to have more control about the sampling procedure (e.g., if you
45-
only want to save a subset of samples or want to use another stopping
46-
criterion), the function
47-
```julia
48-
AbstractMCMC.steps(
49-
[rng,]
50-
ESSModel(prior, loglikelihood),
51-
ESS();
52-
kwargs...
53-
)
54-
```
55-
gives you access to an iterator from which you can generate an unlimited
56-
number of samples.
57-
58-
For more details regarding `sample` and `steps` please check the documentation of
59-
[AbstractMCMC.jl](https://github.com/TuringLang/AbstractMCMC.jl).
60-
61-
### Prior
62-
63-
You may specify Gaussian priors with arbitrary means. EllipticalSliceSampling.jl
64-
provides first-class support for the scalar and multivariate normal distributions
65-
in [Distributions.jl](https://github.com/JuliaStats/Distributions.jl). For
66-
instance, if the prior distribution is a standard normal distribution, you can
67-
choose
68-
```julia
69-
prior = Normal()
70-
```
71-
72-
However, custom Gaussian priors are supported as well. For instance, if you want to
73-
use a custom distribution type `GaussianPrior`, the following methods should be
74-
implemented:
75-
```julia
76-
# state that the distribution is actually Gaussian
77-
EllipticalSliceSampling.isgaussian(::Type{<:GaussianPrior}) = true
78-
79-
# define the mean of the distribution
80-
# alternatively implement `proposal(prior, ...)` and
81-
# `proposal!(out, prior, ...)` (only if the samples are mutable)
82-
Statistics.mean(dist::GaussianPrior) = ...
83-
84-
# define how to sample from the distribution
85-
# only one of the following methods is needed:
86-
# - if the samples are immutable (e.g., numbers or static arrays) only
87-
# `rand(rng, dist)` should be implemented
88-
# - otherwise only `rand!(rng, dist, sample)` is required
89-
Base.rand(rng::AbstractRNG, dist::GaussianPrior) = ...
90-
Random.rand!(rng::AbstractRNG, dist::GaussianPrior, sample) = ...
91-
```
92-
93-
### Log likelihood
94-
95-
In addition to the prior, you have to specify a Julia implementation of
96-
the log likelihood function. Here the predefined log densities and log
97-
likelihood functions in
98-
[Distributions.jl](https://github.com/JuliaStats/Distributions.jl) might
99-
be useful.
100-
101-
### Progress monitor
102-
103-
If you use a package such as [Juno](https://junolab.org/) or
104-
[TerminalLoggers.jl](https://github.com/c42f/TerminalLoggers.jl) that supports
105-
progress logs created by the
106-
[ProgressLogging.jl](https://github.com/JunoLab/ProgressLogging.jl) API, then you can
107-
monitor the progress of the sampling algorithm. If you do not specify a progress
108-
logging frontend explicitly,
109-
[AbstractMCMC.jl](https://github.com/TuringLang/AbstractMCMC.jl) picks a frontend
110-
for you automatically.
111-
112-
## Bibliography
29+
## References
11330

11431
Murray, I., Adams, R. & MacKay, D.. (2010). Elliptical slice sampling. Proceedings of Machine Learning Research, 9:541-548.

docs/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/Manifest.toml
2+
/build/

docs/Project.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[deps]
2+
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
3+
4+
[compat]
5+
Documenter = "0.27"

docs/make.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using Documenter
2+
using EllipticalSliceSampling
3+
4+
makedocs(;
5+
sitename="EllipticalSliceSampling",
6+
format=Documenter.HTML(),
7+
modules=[EllipticalSliceSampling],
8+
pages=["Home" => "index.md"],
9+
strict=true,
10+
checkdocs=:exports,
11+
)
12+
13+
deploydocs(;
14+
repo="github.com/TuringLang/EllipticalSliceSampling.jl.git",
15+
devbranch="main",
16+
push_preview=true,
17+
)

docs/src/index.md

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# EllipticalSliceSampling
2+
3+
*Julia implementation of elliptical slice sampling.*
4+
5+
## Overview
6+
7+
This package implements elliptical slice sampling in the Julia language, as described in
8+
[Murray, Adams & MacKay (2010)](http://proceedings.mlr.press/v9/murray10a/murray10a.pdf).
9+
10+
Elliptical slice sampling is a "Markov chain Monte Carlo algorithm for performing
11+
inference in models with multivariate Gaussian priors" (Murray, Adams & MacKay (2010)).
12+
13+
Without loss of generality, the originally described algorithm assumes that the Gaussian
14+
prior has zero mean. For convenience we allow the user to specify arbitrary Gaussian
15+
priors with non-zero means and handle the change of variables internally.
16+
17+
## Poster at JuliaCon 2021
18+
19+
[![EllipticalSliceSampling.jl: MCMC with Gaussian priors](http://img.youtube.com/vi/S5gUED7Uq2Q/0.jpg)](https://www.youtube.com/watch?v=S5gUED7Uq2Q)
20+
21+
The slides are available as [Pluto notebook](https://talks.widmann.dev/2021/07/ellipticalslicesampling/).
22+
23+
## Usage
24+
25+
Probably most users would like to generate a MC Markov chain of samples from
26+
the posterior distribution by calling
27+
```julia
28+
sample([rng, ]ESSModel(prior, loglikelihood), ESS(), N[; kwargs...])
29+
```
30+
which returns a vector of `N` samples for approximating the posterior of
31+
a model with a Gaussian prior that allows sampling from the `prior` and
32+
evaluation of the log likelihood `loglikelihood`.
33+
34+
You can sample multiple chains in parallel with multiple threads or processes
35+
by running
36+
```julia
37+
sample([rng, ]ESSModel(prior, loglikelihood), ESS(), MCMCThreads(), N, nchains[; kwargs...])
38+
```
39+
or
40+
```julia
41+
sample([rng, ]ESSModel(prior, loglikelihood), ESS(), MCMCDistributed(), N, nchains[; kwargs...])
42+
```
43+
44+
If you want to have more control about the sampling procedure (e.g., if you
45+
only want to save a subset of samples or want to use another stopping
46+
criterion), the function
47+
```julia
48+
AbstractMCMC.steps(
49+
[rng,]
50+
ESSModel(prior, loglikelihood),
51+
ESS();
52+
kwargs...
53+
)
54+
```
55+
gives you access to an iterator from which you can generate an unlimited
56+
number of samples.
57+
58+
For more details regarding `sample` and `steps` please check the documentation of
59+
[AbstractMCMC.jl](https://github.com/TuringLang/AbstractMCMC.jl).
60+
61+
### Prior
62+
63+
You may specify Gaussian priors with arbitrary means. EllipticalSliceSampling.jl
64+
provides first-class support for the scalar and multivariate normal distributions
65+
in [Distributions.jl](https://github.com/JuliaStats/Distributions.jl). For
66+
instance, if the prior distribution is a standard normal distribution, you can
67+
choose
68+
```julia
69+
prior = Normal()
70+
```
71+
72+
However, custom Gaussian priors are supported as well. For instance, if you want to
73+
use a custom distribution type `GaussianPrior`, the following methods should be
74+
implemented:
75+
```julia
76+
# state that the distribution is actually Gaussian
77+
EllipticalSliceSampling.isgaussian(::Type{<:GaussianPrior}) = true
78+
79+
# define the mean of the distribution
80+
# alternatively implement `proposal(prior, ...)` and
81+
# `proposal!(out, prior, ...)` (only if the samples are mutable)
82+
Statistics.mean(dist::GaussianPrior) = ...
83+
84+
# define how to sample from the distribution
85+
# only one of the following methods is needed:
86+
# - if the samples are immutable (e.g., numbers or static arrays) only
87+
# `rand(rng, dist)` should be implemented
88+
# - otherwise only `rand!(rng, dist, sample)` is required
89+
Base.rand(rng::AbstractRNG, dist::GaussianPrior) = ...
90+
Random.rand!(rng::AbstractRNG, dist::GaussianPrior, sample) = ...
91+
```
92+
93+
### Log likelihood
94+
95+
In addition to the prior, you have to specify a Julia implementation of
96+
the log likelihood function. Here the predefined log densities and log
97+
likelihood functions in
98+
[Distributions.jl](https://github.com/JuliaStats/Distributions.jl) might
99+
be useful.
100+
101+
### Progress monitor
102+
103+
If you use a package such as [Juno](https://junolab.org/) or
104+
[TerminalLoggers.jl](https://github.com/c42f/TerminalLoggers.jl) that supports
105+
progress logs created by the
106+
[ProgressLogging.jl](https://github.com/JunoLab/ProgressLogging.jl) API, then you can
107+
monitor the progress of the sampling algorithm. If you do not specify a progress
108+
logging frontend explicitly,
109+
[AbstractMCMC.jl](https://github.com/TuringLang/AbstractMCMC.jl) picks a frontend
110+
for you automatically.
111+
112+
## References
113+
114+
Murray, I., Adams, R. & MacKay, D.. (2010). Elliptical slice sampling. Proceedings of Machine Learning Research, 9:541-548.

0 commit comments

Comments
 (0)