Debian Codegraph @

tests/prob_prog/regression/LinearRegression.hs

raw
1 module LinearRegression where
2
3 import Probability
4 import Data.Frame
5
6 model xs ys = do
7
8 b <- prior $ normal 0 1
9
10 a <- prior $ normal 0 1
11
12 sigma <- prior $ exponential 1
13
14 let f x = b * x + a
15
16 observe ys $ independent [ normal (f x) sigma | x <- xs ]
17
18 return ["b" %=% b, "a" %=% a, "sigma" %=% sigma]
19
20 main logDir = do
21 xy_data <- readTable "xy.csv"
22
23 let xs = xy_data $$ "x" :: [Double]
24 ys = xy_data $$ "y" :: [Double]
25
26 return $ model xs ys
27