Skip to content

Commit dc08791

Browse files
for-developers & contributing sections added
1 parent 84f7953 commit dc08791

File tree

14 files changed

+4468
-443
lines changed

14 files changed

+4468
-443
lines changed

tutorials/docs-00-getting-started/Manifest.toml

Lines changed: 2202 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[deps]
2+
StatsPlots = "f3b207a7-027a-5e70-b257-86293d7955fd"
3+
Turing = "fce5fe82-541a-59a6-adf8-730c64b5f9a0"
Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
---
22
title: Getting Started
3-
permalink: /docs/using-turing/get-started
4-
redirect_from: docs/0-gettingstarted/
5-
weave_options:
6-
error : false
3+
engine: julia
74
---
85

9-
# Getting Started
10-
11-
## Installation
6+
### Installation
127

138
To use Turing, you need to install Julia first and then install Turing.
149

@@ -20,27 +15,28 @@ You will need to install Julia 1.3 or greater, which you can get from [the offic
2015

2116
Turing is an officially registered Julia package, so you can install a stable version of Turing by running the following in the Julia REPL:
2217

23-
```julia
18+
```{julia}
19+
#| output: false
2420
using Pkg
2521
Pkg.add("Turing")
2622
```
2723

2824
You can check if all tests pass by running `Pkg.test("Turing")` (it might take a long time)
2925

30-
## Example
26+
### Example
3127

3228
Here's a simple example showing Turing in action.
3329

3430
First, we can load the Turing and StatsPlots modules
3531

36-
```julia
32+
```{julia}
3733
using Turing
3834
using StatsPlots
3935
```
4036

4137
Then, we define a simple Normal model with unknown mean and variance
4238

43-
```julia
39+
```{julia}
4440
@model function gdemo(x, y)
4541
s² ~ InverseGamma(2, 3)
4642
m ~ Normal(0, sqrt(s²))
@@ -51,21 +47,19 @@ end
5147

5248
Then we can run a sampler to collect results. In this case, it is a Hamiltonian Monte Carlo sampler
5349

54-
```julia
55-
chn = sample(gdemo(1.5, 2), NUTS(), 1000)
50+
```{julia}
51+
chn = sample(gdemo(1.5, 2), NUTS(), 1000, progress=false)
5652
```
5753

5854
We can plot the results
5955

60-
```julia
56+
```{julia}
6157
plot(chn)
6258
```
6359

64-
In this case, because we use the [normal-inverse gamma distribution](https://en.wikipedia.org/wiki/Normal-inverse-gamma_distribution)
65-
as a [conjugate prior](https://en.wikipedia.org/wiki/Conjugate_prior), we can compute
66-
its updated mean as follows:
60+
In this case, because we use the normal-inverse gamma distribution as a conjugate prior, we can compute its updated mean as follows:
6761

68-
```julia
62+
```{julia}
6963
s² = InverseGamma(2, 3)
7064
m = Normal(0, 1)
7165
data = [1.5, 2]
@@ -77,7 +71,7 @@ mean_exp = (m.σ * m.μ + N * x_bar) / (m.σ + N)
7771

7872
We can also compute the updated variance
7973

80-
```julia
74+
```{julia}
8175
updated_alpha = shape(s²) + (N / 2)
8276
updated_beta =
8377
scale(s²) +
@@ -86,11 +80,9 @@ updated_beta =
8680
variance_exp = updated_beta / (updated_alpha - 1)
8781
```
8882

89-
Finally, we can check if these expectations align with our HMC approximations
90-
from earlier. We can compute samples from a normal-inverse gamma following the
91-
equations given [here](https://en.wikipedia.org/wiki/Normal-inverse-gamma_distribution#Generating_normal-inverse-gamma_random_variates).
83+
Finally, we can check if these expectations align with our HMC approximations from earlier. We can compute samples from a normal-inverse gamma following the equations given [here](https://en.wikipedia.org/wiki/Normal-inverse-gamma_distribution#Generating_normal-inverse-gamma_random_variates).
9284

93-
```julia
85+
```{julia}
9486
function sample_posterior(alpha, beta, mean, lambda, iterations)
9587
samples = []
9688
for i in 1:iterations
@@ -104,7 +96,7 @@ end
10496
analytical_samples = sample_posterior(updated_alpha, updated_beta, mean_exp, 2, 1000);
10597
```
10698

107-
```julia
99+
```{julia}
108100
density(analytical_samples; label="Posterior (Analytical)")
109101
density!(chn[:m]; label="Posterior (HMC)")
110102
```
Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
---
22
title: Contributing
3-
permalink: /docs/contributing/guide
4-
weave_options:
5-
error : false
63
---
74

8-
# Contributing
9-
105
Turing is an open source project. If you feel that you have some relevant skills and are interested in contributing, then please do get in touch. You can contribute by opening issues on GitHub or implementing things yourself and making a pull request. We would also appreciate example models written using Turing.
116

12-
Turing has a [style guide](%7B%7Bsite.baseurl%7D%7D/docs/contributing/style-guide). It is not strictly necessary to review it before making a pull request, but you may be asked to change portions of your code to conform with the style guide before it is merged.
7+
Turing has a [style guide]({{< meta site-url >}}/dev/docs/contributing/style-guide). It is not strictly necessary to review it before making a pull request, but you may be asked to change portions of your code to conform with the style guide before it is merged.
138

149
## How to Contribute
1510

1611
### Getting Started
1712

1813
- [Fork this repository](https://github.com/TuringLang/Turing.jl#fork-destination-box).
14+
1915
- Clone your fork on your local machine: `git clone https://github.com/your_username/Turing.jl`.
16+
2017
- Add a remote corresponding to this repository:
2118

2219
`git remote add upstream https://github.com/TuringLang/Turing.jl`.
@@ -27,4 +24,4 @@ Look at the [issues](https://github.com/TuringLang/Turing.jl/issues) page to fin
2724

2825
### Git Workflow
2926

30-
For more information on how the Git workflow typically functions, please see the [GitHub's introduction](https://guides.github.com/introduction/flow/) or [Julia's contribution guide](https://github.com/JuliaLang/julia/blob/master/CONTRIBUTING.md).
27+
For more information on how the Git workflow typically functions, please see the [GitHub's introduction](https://guides.github.com/introduction/flow/) or [Julia's contribution guide](https://github.com/JuliaLang/julia/blob/master/CONTRIBUTING.md).

tutorials/docs-02-contributing-style-guide/index.qmd

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
---
22
title: Style Guide
3-
permalink: /docs/contributing/style-guide
4-
weave_options:
5-
error : false
3+
engine: julia
64
---
75

8-
# Style Guide
9-
106
Most Turing code follows the [Invenia](https://invenia.ca/labs/)'s style guide. We would like to thank them for allowing us to access and use it. Please don't let not having read it stop you from contributing to Turing! No one will be annoyed if you open a PR with style that doesn't follow these conventions; we will just help you correct it before it gets merged.
117

128
These conventions were originally written at Invenia, taking inspiration from a variety of sources including Python's [PEP8](http://legacy.python.org/dev/peps/pep-0008), Julia's [Notes for Contributors](https://github.com/JuliaLang/julia/blob/master/CONTRIBUTING.md), and Julia's [Style Guide](https://docs.julialang.org/en/v1/manual/style-guide/).
@@ -40,7 +36,7 @@ Attempt to follow the [Julia Contribution Guidelines](https://github.com/JuliaLa
4036

4137
If you are a user of Sublime Text we recommend that you have the following options in your Julia syntax specific settings. To modify these settings first open any Julia file (`*.jl`) in Sublime Text. Then navigate to: `Preferences > Settings - More > Syntax Specific - User`
4238

43-
```json
39+
```{json}
4440
{
4541
"translate_tabs_to_spaces": true,
4642
"tab_size": 4,
@@ -71,7 +67,8 @@ By default, Vim seems to guess that `.jl` files are written in Lisp. To ensure t
7167

7268
Julia provides [test sets](https://docs.julialang.org/en/v1/stdlib/Test/#Working-with-Test-Sets-1) which allows developers to group tests into logical groupings. Test sets can be nested and ideally packages should only have a single "root" test set. It is recommended that the "runtests.jl" file contains the root test set which contains the remainder of the tests:
7369

74-
```julia eval=false
70+
```{julia}
71+
#| eval: false
7572
@testset "PkgExtreme" begin
7673
include("arithmetic.jl")
7774
include("utils.jl")
@@ -84,7 +81,8 @@ The file structure of the `test` folder should mirror that of the `src` folder.
8481

8582
Most tests are written in the form `@test x == y`. Since the `==` function doesn't take types into account, tests like the following are valid: `@test 1.0 == 1`. Avoid adding visual noise into test comparisons:
8683

87-
```julia eval=false
84+
```{julia}
85+
#| eval: false
8886
# Yes:
8987
@test value == 0
9088
@@ -96,7 +94,8 @@ In cases where you are checking the numerical validity of a model's parameter es
9694

9795
Here is an example of usage:
9896

99-
```julia eval=false
97+
```{julia}
98+
#| eval: false
10099
# Check that m and s are plus or minus one from 1.5 and 2.2, respectively.
101100
check_numerical(chain, [:m, :s], [1.5, 2.2]; atol=1.0)
102101
@@ -105,4 +104,4 @@ check_gdemo(chain; atol=0.1)
105104
106105
# Checks the estimates for a default MoG model.
107106
check_MoGtest_default(chain; atol=0.1)
108-
```
107+
```

tutorials/docs-03-using-turing-sampler-viz/index.qmd

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

0 commit comments

Comments
 (0)