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

New Documentation Structure #327

Merged
merged 26 commits into from
Nov 19, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
df0dd1d
Created new pattern for documentation. Ported first using turing doc …
cgbotta Oct 18, 2022
4ba06f0
Updated style
cgbotta Oct 18, 2022
a356863
Merge branch 'TuringLang:master' into master
cgbotta Oct 19, 2022
fc6bf5b
Added default weave that handles both directories and addressed gramm…
cgbotta Oct 19, 2022
f760b32
Renamed tutorials and added a doc example
cgbotta Oct 20, 2022
0cf7b6a
fixed format
cgbotta Oct 20, 2022
2c17932
Reverted tutorial names back to originals
cgbotta Oct 20, 2022
b6fe397
Generated manifest and project files, updated GH Action
cgbotta Oct 20, 2022
59313b6
Generated manifest with proper Julia version
cgbotta Oct 20, 2022
1b1c241
Fixed project files
cgbotta Oct 20, 2022
2590aa4
Updated Tutorial
cgbotta Oct 21, 2022
7116f29
style
cgbotta Oct 21, 2022
eb5476e
fix style
cgbotta Oct 21, 2022
d4b5ca9
style
cgbotta Oct 21, 2022
9bf0a08
Added calculation of true posterior mean
cgbotta Oct 26, 2022
f39de6c
format
cgbotta Oct 26, 2022
637829c
permalink
cgbotta Oct 26, 2022
8fc20b5
Merge branch 'master' into master
yebai Oct 26, 2022
d489a10
Added variance calculation
cgbotta Oct 27, 2022
b6a2cd9
formatting
cgbotta Oct 27, 2022
e9c73cc
formatting
cgbotta Oct 27, 2022
9dce638
Updated tutorial posterior visualizations
cgbotta Nov 5, 2022
6f9c246
Format
cgbotta Nov 5, 2022
8124cac
Calculated density of N-IG properly
cgbotta Nov 19, 2022
38c83a4
Format
cgbotta Nov 19, 2022
cfe15eb
Update tutorials/docs-00-getting-started/00_getting-started.jmd
yebai Nov 19, 2022
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ Testing/
/*/*/jl_*/
/Manifest.toml
/test/Manifest.toml
.vscode
78 changes: 78 additions & 0 deletions docs/00-getting-started/00_getting-started.jmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
---
title: Getting Started
permalink: /:collection/:name/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would these fields of permalink and redirect_from still work with jmd?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied this structure from all the files in TuringTutorials/tutorials, but I am assuming this is read by the build process. Perhaps @devmotion could also advise here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not relevant for weaving at all IIRC, it's just copied to the Markdown output (e.g., https://github.com/TuringLang/TuringTutorialsOutput/blob/main/markdown/00-introduction/00_introduction.md). This is just used by the Jekyll setup in turing.ml AFAIK.

redirect_from: docs/0-gettingstarted/
weave_options:
error : false
---

# Getting Started

## Installation

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

### Install Julia

You will need to install Julia 1.3 or greater, which you can get from [the official Julia website](http://julialang.org/downloads/).

### Install Turing.jl

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

```julia
using Pkg
Pkg.add("Turing")
```

You can check if all tests pass by running
cgbotta marked this conversation as resolved.
Show resolved Hide resolved

```julia
Pkg.test("Turing")
```

## Example

Here's a simple example showing Turing in action.

First, we can load the Turing and StatsPlots modules

```julia
using Turing
using StatsPlots
```

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

```julia
@model function gdemo(x, y)
s² ~ InverseGamma(2, 3)
m ~ Normal(0, sqrt(s²))
x ~ Normal(m, sqrt(s²))
return y ~ Normal(m, sqrt(s²))
end
```

Then we can run sampler a sampler to collect results. In this case it is a Hamiltonian Monte Carlo sampler
cgbotta marked this conversation as resolved.
Show resolved Hide resolved

```julia
chn = sample(gdemo(1.5, 2), HMC(0.1, 5), 1000)
```

We can use `describe` to summarise results

```julia
describe(chn)
```

Finally, we can plot the results

```julia
plot(chn)
```

The plots can also be saved

```julia
savefig("gdemo-plot.png")
```
23 changes: 12 additions & 11 deletions src/TuringTutorials.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function __init__()
end

function weave(
source_folder::AbstractString,
folder::AbstractString,
file::AbstractString;
out_path_root::AbstractString=pwd(),
Expand All @@ -33,15 +34,15 @@ function weave(
)
end

target = joinpath(REPO_DIR, "tutorials", folder, file)
target = joinpath(REPO_DIR, source_folder, folder, file)
@info("Weaving $(target)")

# Activate project
# TODO: use separate Julia process?
if isfile(joinpath(REPO_DIR, "tutorials", folder, "Project.toml")) &&
if isfile(joinpath(REPO_DIR, source_folder, folder, "Project.toml")) &&
(:github in build || :html in build || :pdf in build)
@info("Instantiating", folder)
Pkg.activate(joinpath(REPO_DIR, "tutorials", folder))
Pkg.activate(joinpath(REPO_DIR, source_folder, folder))
Pkg.instantiate()
Pkg.build()

Expand Down Expand Up @@ -91,23 +92,23 @@ function weave(
end

# Weave all tutorials
cgbotta marked this conversation as resolved.
Show resolved Hide resolved
function weave(; kwargs...)
for folder in readdir(joinpath(REPO_DIR, "tutorials"))
weave(folder; kwargs...)
function weave(source_folder::AbstractString; kwargs...)
yebai marked this conversation as resolved.
Show resolved Hide resolved
for folder in readdir(joinpath(REPO_DIR, source_folder))
weave(source_folder, folder; kwargs...)
end
end

# Weave a folder of tutorials
function weave(folder::AbstractString; kwargs...)
for file in readdir(joinpath(REPO_DIR, "tutorials", folder))
function weave(source_folder::AbstractString, folder::AbstractString; kwargs...)
for file in readdir(joinpath(REPO_DIR, source_folder, folder))
# Skip non-`.jmd` files
endswith(file, ".jmd") || continue

weave(folder, file; kwargs...)
weave(source_folder, folder, file; kwargs...)
end
end

function tutorial_footer(folder=nothing, file=nothing)
function doc_footer(folder=nothing, file=nothing)
display(
Markdown.md"""
## Appendix
Expand All @@ -116,7 +117,7 @@ These tutorials are a part of the TuringTutorials repository, found at: <https:/
)
if folder !== nothing && file !== nothing
display(Markdown.parse("""
To locally run this tutorial, do the following commands:
To locally run this doc, do the following commands:
```
using TuringTutorials
TuringTutorials.weave("$folder", "$file")
Expand Down