Skip to content

Commit 1e31d3a

Browse files
authored
Update model_macro.md
1 parent fed528a commit 1e31d3a

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed

JuliaBUGS/docs/src/model_macro.md

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,6 @@
22

33
JuliaBUGS provides the `@model` macro for defining probabilistic models in a Julia-native way. This guide explains how to create and use models effectively.
44

5-
## Core Concepts
6-
7-
When defining a model, you work with two main categories of variables:
8-
9-
### 1. Stochastic Parameters
10-
Variables that follow probability distributions, defined with the `~` operator:
11-
- **Unobserved parameters**: Variables to be sampled during inference
12-
- **Observed data**: Known values that the model conditions on
13-
14-
### 2. Constants and Covariates
15-
Deterministic inputs that don't have probability distributions:
16-
- **Covariates/predictors**: Input features like `x` in regression models
17-
- **Structural constants**: Values that determine model structure (e.g., `N` for array sizes)
18-
- **Fixed parameters**: Any other non-stochastic inputs
19-
205
## The `@model` Macro
216

227
The `@model` macro creates a function that returns a `BUGSModel` object. Here's the basic syntax:
@@ -38,12 +23,30 @@ end
3823

3924
2. **Remaining arguments**: All constants, covariates, and structural parameters
4025

26+
### Two Types of Variables
27+
28+
As shown in the above model, we have two main categories of variables:
29+
30+
#### 1. Stochastic Parameters
31+
Variables that follow probability distributions, defined with the `~` operator:
32+
- **Unobserved parameters**: Variables to be sampled during inference
33+
- **Observed data**: Known values that the model conditions on
34+
35+
#### 2. Constants and Covariates
36+
Deterministic inputs that don't have probability distributions:
37+
- **Covariates/predictors**: Input features like `x` in regression models
38+
- **Structural constants**: Values that determine model structure (e.g., `N` for array sizes)
39+
- **Fixed parameters**: Any other non-stochastic inputs
40+
4141
### Example: Linear Regression
4242

4343
```julia
44+
using Julia
45+
using JuliaBUGS.BUGSPrimitives
46+
4447
@model function linear_regression(
4548
(; y, beta, sigma), # y is data, beta and sigma are parameters
46-
X, N # X is covariate matrix, N is size
49+
X, N # X is the covariate matrix, N is the size
4750
)
4851
for i in 1:N
4952
y[i] ~ dnorm(mu[i], sigma)
@@ -91,14 +94,14 @@ When you provide an `of` type annotation, JuliaBUGS automatically validates the
9194
# Create model with no observations (sample from prior)
9295
model = my_model((;), constants...)
9396

94-
# Create model with some observed values
97+
# Create a model with some observed values
9598
model = my_model((; y = observed_data), constants...)
9699

97100
# Create model with all parameters specified
98101
model = my_model((; param1 = val1, param2 = val2), constants...)
99102
```
100103

101-
### Using `unflatten` for Initialization
104+
### Using `unflatten` for Initialisation
102105

103106
The `unflatten` utility helps create parameter instances with missing values:
104107

@@ -109,14 +112,17 @@ using JuliaBUGS: unflatten
109112
params = unflatten(MyParamType, missing)
110113
model = my_model(params, constants...)
111114

112-
# This is useful for models that need initialization
115+
# This is useful for models that need initialisation
113116
```
114117

115118
## Complete Example: Hierarchical Model
116119

117120
Here's a complete example showing all the concepts together:
118121

119122
```julia
123+
using JuliaBUGS
124+
using JuliaBUGS.BUGSPrimitives
125+
120126
# Step 1: Define parameter types
121127
HierarchicalParams = @of(
122128
# Data

0 commit comments

Comments
 (0)