/ concept-collection / stan-web-ide
Sign in
concept-collection / stan-web-ide
stan-web-ide / src / sampleWorkspace.ts
77 lines · 1.7 KBBlameHistoryRaw
1// Files seeded into new projects.
3const readme = `# stan sample project
4`;
6const linearStan = `// Bayesian linear regression: y ~ normal(alpha + beta * x, sigma)
7data {
8 int<lower=0> N;
9 vector[N] x;
10 vector[N] y;
12parameters {
13 real alpha;
14 real beta;
15 real<lower=0> sigma;
17model {
18 alpha ~ normal(0, 5);
19 beta ~ normal(0, 5);
20 sigma ~ normal(0, 2);
21 y ~ normal(alpha + beta * x, sigma);
23generated quantities {
24 // posterior predictive draw at x = 6
25 real y_at_6 = normal_rng(alpha + beta * 6, sigma);
27`;
29const dataJson = `{
30 "N": 20,
31 "x": [0.17, 0.41, 0.77, 0.96, 1.23, 1.46, 1.66, 1.8, 2.01, 2.32,
32 2.59, 3.05, 3.21, 3.45, 3.61, 3.83, 4.03, 4.52, 4.75, 5.0],
33 "y": [2.13, 2.9, 3.51, 3.69, 3.41, 4.05, 4.56, 3.9, 3.5, 5.17,
34 6.14, 6.62, 6.55, 7.31, 7.34, 6.33, 8.81, 8.79, 8.56, 9.16]
36`;
38const fitSample = `# A sampling run. This file opens as a form; use the tab context menu to
39# edit the raw YAML. Paths are relative to this file.
40stan: linear.stan
41data: data.json
42num_chains: 4
43num_warmup: 1000
44num_samples: 1000
45seed: 42
46`;
48const quickSample = `# A quicker look: fewer iterations, random seed each run.
49stan: linear.stan
50data: data.json
51num_chains: 2
52num_warmup: 200
53num_samples: 200
54`;
56export const sampleWorkspace: Record<string, string> = {
57 '/README.md': readme,
58 '/linear.stan': linearStan,
59 '/data.json': dataJson,
60 '/fit.sample': fitSample,
61 '/quick.sample': quickSample,
62};
64const emptyStan = `// Write your Stan program here.
65parameters {
66 real mu;
68model {
69 mu ~ normal(0, 1);
71`;
73export const emptyWorkspace: Record<string, string> = {
74 '/main.stan': emptyStan,
75 '/data.json': '{}\n',
76 '/fit.sample': `stan: main.stan\ndata: data.json\n`,
77};
moveopenescclose