Debian Codegraph @

tests/prob_prog/regression/rb-command.Rev

raw
1
2 #
3 # Bayesian linear regression example
4 #
5 # by Will Freyman
6 #
7
8
9 x_obs <- readDataDelimitedFile(file="x.csv", header=FALSE, delimiter=",")[1]
10 y_obs <- readDataDelimitedFile(file="y.csv", header=FALSE, delimiter=",")[1]
11
12 beta ~ dnNormal(0, 1)
13 alpha ~ dnNormal(0, 1)
14 sigma ~ dnExponential(1)
15
16 for (i in 1:x_obs.size()) {
17 mu_y[i] := (beta * x_obs[i]) + alpha
18 y[i] ~ dnNormal(mu_y[i], sigma)
19 y[i].clamp(y_obs[i])
20 }
21
22 mymodel = model(beta)
23
24 moves[1] = mvSlide(beta)
25 moves[2] = mvSlide(alpha)
26 moves[3] = mvSlide(sigma)
27
28 monitors[1] = mnFile(alpha,beta,sigma,filename="linear_regression.log",printgen=10)
29 # monitors[2] = mnModel("linear_regression.log",printgen=1000)
30 # monitors[3] = mnScreen()
31
32 mymcmc = mcmc(mymodel, moves, monitors)
33 mymcmc.burnin(generations=1000,tuningInterval=100)
34 mymcmc.run(100000)
35
36 q()