@@ -100,15 +100,19 @@ Turing is written entirely in Julia, and is interoperable with its powerful ecos
100100
101101:::
102102
103- ::: {.code-window-title }
103+ ::: {.code-window-tabs }
104104``` {=html}
105- <span>linear_regression.jl</span>
105+ <span class="tab active" onclick="switchTab('define', this)">Define</span>
106+ <span class="tab" onclick="switchTab('inference', this)">Inference</span>
107+ <span class="tab" onclick="switchTab('prior', this)">Prior</span>
108+ <span class="tab" onclick="switchTab('return', this)">Return</span>
109+ <span class="tab" onclick="switchTab('predict', this)">Predict</span>
106110```
107111:::
108112
109-
110113:::
111114
115+ ::: {#define .code-content .active}
112116``` {.julia .code-overflow-scroll}
113117using Turing
114118
@@ -121,16 +125,79 @@ using Turing
121125 # Likelihood
122126 μ = α .+ β .* x
123127 y ~ MvNormal(μ, σ² * I)
128+
129+ # Return the mean
130+ return μ
124131end
132+ ```
133+ :::
134+
135+ ::: {#inference .code-content}
136+ ``` {.julia .code-overflow-scroll}
137+ # Data
138+ x_data = rand(10)
139+ y_data = rand(10)
125140
126- x, y = rand(10), rand(10)
127- posterior = linear_regression(x) | (; y = y)
128- chain = sample(posterior, NUTS(), 1000)
141+ # Condition the model on data
142+ model = linear_regression(x_data) | (; y = y_data)
143+
144+ # Run the NUTS sampler
145+ chain = sample(model, NUTS(), 1000)
129146```
147+ :::
130148
149+ ::: {#prior .code-content}
150+ ``` {.julia .code-overflow-scroll}
151+ # Fix parameters to specific values
152+ fixed_model = fix(
153+ linear_regression(x_data),
154+ (α = 0.5, β = 2.0, σ² = 1.0)
155+ )
156+
157+ # Sample from the prior predictive distribution
158+ prior_sample = rand(fixed_model)
159+ ```
131160:::
161+
162+ ::: {#return .code-content}
163+ ``` {.julia .code-overflow-scroll}
164+ # Get generated quantities (the returned μ)
165+ generated = generated_quantities(model, chain)
166+ ```
167+ :::
168+
169+ ::: {#predict .code-content}
170+ ``` {.julia .code-overflow-scroll}
171+ # Make predictions on new data
172+ predictions = predict(linear_regression(x_new), chain)
173+ ```
132174:::
133175
176+ :::
177+ :::
178+
179+ ``` {=html}
180+ <script>
181+ function switchTab(tabId, element) {
182+ // Remove active class from all tabs
183+ document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
184+ // Add active class to clicked tab
185+ element.classList.add('active');
186+
187+ // Hide all code contents
188+ document.querySelectorAll('.code-content').forEach(c => {
189+ c.classList.remove('active');
190+ c.style.display = 'none';
191+ });
192+
193+ // Show target content
194+ const target = document.getElementById(tabId);
195+ target.classList.add('active');
196+ target.style.display = 'block';
197+ }
198+ </script>
199+ ```
200+
134201:::
135202<!-- What is Turing.jl Section Ends Here -->
136203
0 commit comments