| 1 |
module Model where |
| 2 |
|
| 3 |
import Probability |
| 4 |
import System.Environment |
| 5 |
import Data.Frame |
| 6 |
|
| 7 |
-- Ideally, the categories and their weights would be exchangeable! |
| 8 |
-- Currently if the first category is bad, there is not a good way |
| 9 |
-- to eliminate it. |
| 10 |
|
| 11 |
cluster_dist = do |
| 12 |
mean <- prior $ normal 0 10 |
| 13 |
prec <- prior $ gamma 2 1 |
| 14 |
let sigma = 1/prec |
| 15 |
return (mean,sigma) |
| 16 |
|
| 17 |
model xs = do |
| 18 |
|
| 19 |
let n_points = length xs |
| 20 |
|
| 21 |
alpha <- prior $ gamma 0.5 10.0 |
| 22 |
|
| 23 |
params <- prior $ dp n_points alpha cluster_dist |
| 24 |
|
| 25 |
observe xs $ independent [normal mean sigma | (mean,sigma) <- params] |
| 26 |
|
| 27 |
let loggers = ["alpha" %=% alpha, "params" %=% params] |
| 28 |
|
| 29 |
return loggers |
| 30 |
|
| 31 |
|
| 32 |
main logDir = do |
| 33 |
[filename] <- getArgs |
| 34 |
|
| 35 |
xtable <- readTable filename |
| 36 |
|
| 37 |
let xs = xtable $$ "x" :: [Double] |
| 38 |
|
| 39 |
return $ model xs |
| 40 |
|