Skip to content

Commit 52a017f

Browse files
Tabbed View
1 parent 4df9894 commit 52a017f

File tree

2 files changed

+116
-6
lines changed

2 files changed

+116
-6
lines changed

index.qmd

Lines changed: 73 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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}
113117
using Turing
114118
@@ -121,16 +125,79 @@ using Turing
121125
# Likelihood
122126
μ = α .+ β .* x
123127
y ~ MvNormal(μ, σ² * I)
128+
129+
# Return the mean
130+
return μ
124131
end
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

theming/rules/_layouts.scss

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@
184184
align-items: center;
185185
border-bottom: 1px solid lighten($btn-border-color, 5%);
186186
position: relative;
187+
justify-content: space-between; /* Changed to space-between to push tabs to right */
187188
}
188189

189190
.code-window-dots {
@@ -200,6 +201,48 @@
200201
font-size: 0.8rem;
201202
}
202203

204+
.code-window-tabs {
205+
display: flex;
206+
gap: 1rem;
207+
z-index: 10; /* Ensure tabs are clickable above title if they overlap */
208+
}
209+
210+
.tab {
211+
cursor: pointer;
212+
color: $text-muted;
213+
font-size: 0.85rem;
214+
font-weight: 600;
215+
padding: 0.2rem 0.6rem;
216+
border-radius: 4px;
217+
transition: all 0.2s ease;
218+
user-select: none;
219+
220+
&:hover {
221+
color: $text-color;
222+
background-color: rgba(0,0,0,0.05);
223+
}
224+
225+
&.active {
226+
color: $primary;
227+
background-color: rgba($primary, 0.1);
228+
}
229+
}
230+
231+
.code-content {
232+
display: none;
233+
234+
&.active {
235+
display: block;
236+
animation: fadeIn 0.3s ease;
237+
}
238+
}
239+
240+
@keyframes fadeIn {
241+
from { opacity: 0; }
242+
to { opacity: 1; }
243+
}
244+
245+
203246
.dot {
204247
width: 13px;
205248
height: 13px;

0 commit comments

Comments
 (0)