Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
DominiqueMakowski committed Jul 7, 2024
1 parent fe74711 commit 938249b
Show file tree
Hide file tree
Showing 38 changed files with 4,217 additions and 227 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Importantly, it is currently the only language in which we can fit all the cogni
## Why Bayesian?

Unfortunately, cognitive models often involve distributions for which Frequentist estimations are not yet implemented, and usually contain a lot of parameters (due to the presence of **random effects**), which makes traditional algorithms fail to converge.
Simply put, the Bayesian approach is the only one currently robust enough to fit these somewhat complex models.
Simply put, the Bayesian approach is the only one currently robust enough to fit these complex models.

## The Plan

Expand Down

Large diffs are not rendered by default.

3,069 changes: 3,069 additions & 0 deletions content/.jupyter_cache/executed/64687a80716dc9582e5b89057ffe678f/base.ipynb

Large diffs are not rendered by default.

Binary file modified content/.jupyter_cache/global.db
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"hash": "ee1e3ab46601401d12010460f9a3436a",
"hash": "f1b09c48ebcc0d8b9c817ca76b3d37bf",
"result": {
"engine": "jupyter",
"markdown": "# Fundamentals of Bayesian Modeling in Julia\n\n![](https://img.shields.io/badge/status-not_started-red)\n\n\n## Very quick intro to Julia and Turing\n\nGoal is to teach just enough so that the reader understands the code.\n\n### Generate Data from Normal Distribution\n\n::: {#86de7312 .cell execution_count=1}\n``` {.julia .cell-code}\nusing Turing, Distributions, Random\nusing Makie\n\n# Random sample from a Normal(μ=100, σ=15)\niq = rand(Normal(100, 15), 500)\n```\n:::\n\n\n::: {#8df07ece .cell execution_count=2}\n``` {.julia .cell-code}\nfig = Figure()\nax = Axis(fig[1, 1], title=\"Distribution\")\ndensity!(ax, iq)\nfig\n```\n\n::: {.cell-output .cell-output-stderr}\n```\n┌ Warning: Found `resolution` in the theme when creating a `Scene`. The `resolution` keyword for `Scene`s and `Figure`s has been deprecated. Use `Figure(; size = ...` or `Scene(; size = ...)` instead, which better reflects that this is a unitless size and not a pixel resolution. The key could also come from `set_theme!` calls or related theming functions.\n└ @ Makie C:\\Users\\domma\\.julia\\packages\\Makie\\VRavR\\src\\scenes.jl:220\n```\n:::\n\n::: {.cell-output .cell-output-display execution_count=3}\n![](1_introduction_files/figure-html/cell-3-output-2.svg){}\n:::\n:::\n\n\n### Recover Distribution Parameters with Turing\n\n::: {#3276026a .cell execution_count=3}\n``` {.julia .cell-code}\n@model function model_gaussian(x)\n # Priors\n μ ~ Uniform(0, 200)\n σ ~ Uniform(0, 30)\n\n # Check against each datapoint\n for i in 1:length(x)\n x[i] ~ Normal(μ, σ)\n end\nend\n\nmodel = model_gaussian(iq)\nsampling_results = sample(model, NUTS(), 400)\n\n# Summary (95% CI)\nsummarystats(sampling_results)\n```\n\n::: {.cell-output .cell-output-stderr}\n```\n┌ Info: Found initial step size\n└ ϵ = 0.05\n\rSampling: 0%|█ | ETA: 0:00:29\rSampling: 100%|█████████████████████████████████████████| Time: 0:00:00\n```\n:::\n\n::: {.cell-output .cell-output-display execution_count=4}\n\n::: {.ansi-escaped-output}\n```{=html}\n<pre>Summary Statistics\n <span class=\"ansi-bold\"> parameters </span> <span class=\"ansi-bold\"> mean </span> <span class=\"ansi-bold\"> std </span> <span class=\"ansi-bold\"> mcse </span> <span class=\"ansi-bold\"> ess_bulk </span> <span class=\"ansi-bold\"> ess_tail </span> <span class=\"ansi-bold\"> rhat </span> <span class=\"ansi-bold\"> e</span> ⋯\n <span class=\"ansi-bright-black-fg\"> Symbol </span> <span class=\"ansi-bright-black-fg\"> Float64 </span> <span class=\"ansi-bright-black-fg\"> Float64 </span> <span class=\"ansi-bright-black-fg\"> Float64 </span> <span class=\"ansi-bright-black-fg\"> Float64 </span> <span class=\"ansi-bright-black-fg\"> Float64 </span> <span class=\"ansi-bright-black-fg\"> Float64 </span> <span class=\"ansi-bright-black-fg\"> </span> ⋯\n μ 99.7082 0.6935 0.0367 349.6040 232.8456 1.0045 ⋯\n σ 15.2626 0.4713 0.0255 337.7052 265.8666 1.0002 ⋯\n<span class=\"ansi-cyan-fg\"> 1 column omitted</span>\n</pre>\n```\n:::\n\n:::\n:::\n\n\n## Linear Models\n\nUnderstand what the parameters mean (intercept, slopes, sigma).\n\n## Boostrapping\n\nIntroduce concepts related to pseudo-posterior distribution description\n\n## Hierarchical Models\n\nSimpson's paradox, random effects, how to leverage them to model interindividual differences\n\n## Bayesian estimation\n\nintroduce Bayesian estimation and priors over parameters\n\n## Bayesian mixed linear regression\n\nput everything together\n\n",
"markdown": "# Fundamentals of Bayesian Modeling in Julia\n\n![](https://img.shields.io/badge/status-not_started-red)\n\n\n## Very quick intro to Julia and Turing\n\nGoal is to teach just enough so that the reader understands the code.\n\n::: {.callout-important}\n\n### Notable Differences with Python and R\n\nThese are the most common sources of confusion and errors for newcomers to Julia:\n\n- **1-indexing**: Similarly to R, Julia uses 1-based indexing, which means that the first element of a vector is `x[1]` (not `x[0]` as in Python).\n- **Positional; Keyword arguments**: Julia functions makes a clear distinction between positional and keyword arguments, and both are often separated by `;`. Positional arguments are typically passed without a name, while keyword arguments must be named (e.g., `scatter(0, 0; color=:red)`). Some functions might look like `somefunction(; arg1=val1, arg2=val2)`.\n- **Symbols**: Some arguments are prefixed with `:` (e.g., `:red` in `scatter(0, 0; color=:red)`). These **symbols** are like character strings that are not manipulable (there are more efficient).\n- **Explicit vectorization**: Julia does not vectorize operations by default. You need to use a dot `.` in front of functions and operators to have it apply element by element. For example, `sin.([0, 1, 2])` will apply the `sin()` function to each element of its vector.\n- **In-place operations**: Julia has a strong emphasis on performance, and in-place operations are often used to avoid unnecessary memory allocations. When functions modify their input \"in-place\" (without returns), a band `!` is used. For example, assuming `x = [0]` (1-element vector containing 0), `push!(x, 2)` will modify `x` in place (it is equivalent to `x = push(x, 2)`).\n:::\n\n\n### Generate Data from Normal Distribution\n\n::: {#0c15ea13 .cell execution_count=1}\n``` {.julia .cell-code}\nusing Turing, Distributions, Random\nusing Makie\n\n# Random sample from a Normal(μ=100, σ=15)\niq = rand(Normal(100, 15), 500)\n```\n:::\n\n\n::: {#6de958d5 .cell execution_count=2}\n``` {.julia .cell-code}\nfig = Figure()\nax = Axis(fig[1, 1], title=\"Distribution\")\ndensity!(ax, iq)\nfig\n```\n\n::: {.cell-output .cell-output-stderr}\n```\n┌ Warning: Found `resolution` in the theme when creating a `Scene`. The `resolution` keyword for `Scene`s and `Figure`s has been deprecated. Use `Figure(; size = ...` or `Scene(; size = ...)` instead, which better reflects that this is a unitless size and not a pixel resolution. The key could also come from `set_theme!` calls or related theming functions.\n└ @ Makie C:\\Users\\domma\\.julia\\packages\\Makie\\VRavR\\src\\scenes.jl:220\n```\n:::\n\n::: {.cell-output .cell-output-display execution_count=3}\n![](1_introduction_files/figure-html/cell-3-output-2.svg){}\n:::\n:::\n\n\n### Recover Distribution Parameters with Turing\n\n::: {#76fbbced .cell execution_count=3}\n``` {.julia .cell-code}\n@model function model_gaussian(x)\n # Priors\n μ ~ Uniform(0, 200)\n σ ~ Uniform(0, 30)\n\n # Check against each datapoint\n for i in 1:length(x)\n x[i] ~ Normal(μ, σ)\n end\nend\n\nmodel = model_gaussian(iq)\nsampling_results = sample(model, NUTS(), 400)\n\n# Summary (95% CI)\nsummarystats(sampling_results)\n```\n\n::: {.cell-output .cell-output-stderr}\n```\n┌ Info: Found initial step size\n└ ϵ = 0.05\n\rSampling: 0%|█ | ETA: 0:00:32\rSampling: 100%|█████████████████████████████████████████| Time: 0:00:01\n```\n:::\n\n::: {.cell-output .cell-output-display execution_count=4}\n\n::: {.ansi-escaped-output}\n```{=html}\n<pre>Summary Statistics\n <span class=\"ansi-bold\"> parameters </span> <span class=\"ansi-bold\"> mean </span> <span class=\"ansi-bold\"> std </span> <span class=\"ansi-bold\"> mcse </span> <span class=\"ansi-bold\"> ess_bulk </span> <span class=\"ansi-bold\"> ess_tail </span> <span class=\"ansi-bold\"> rhat </span> <span class=\"ansi-bold\"> </span> ⋯\n <span class=\"ansi-bright-black-fg\"> Symbol </span> <span class=\"ansi-bright-black-fg\"> Float64 </span> <span class=\"ansi-bright-black-fg\"> Float64 </span> <span class=\"ansi-bright-black-fg\"> Float64 </span> <span class=\"ansi-bright-black-fg\"> Float64 </span> <span class=\"ansi-bright-black-fg\"> Float64 </span> <span class=\"ansi-bright-black-fg\"> Float64 </span> <span class=\"ansi-bright-black-fg\"> </span> ⋯\n μ 101.0966 0.6163 0.0285 464.5397 331.0063 1.0010 ⋯\n σ 14.5905 0.4758 0.0221 504.1965 231.1654 1.0362 ⋯\n<span class=\"ansi-cyan-fg\"> 1 column omitted</span>\n</pre>\n```\n:::\n\n:::\n:::\n\n\n## Linear Models\n\nUnderstand what the parameters mean (intercept, slopes, sigma).\n\n## Boostrapping\n\nIntroduce concepts related to pseudo-posterior distribution description\n\n## Hierarchical Models\n\nSimpson's paradox, random effects, how to leverage them to model interindividual differences\n\n## Bayesian estimation\n\nintroduce Bayesian estimation and priors over parameters\n\n## Bayesian mixed linear regression\n\nput everything together\n\n",
"supporting": [
"1_introduction_files\\figure-html"
],
Expand Down
Loading

0 comments on commit 938249b

Please sign in to comment.