forked from mikeizbicki/hmm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HMMPerf.hs
94 lines (77 loc) · 2.82 KB
/
HMMPerf.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
-- module HMMPerf
-- ( verifyhmm
-- )
-- where
import HMM
import qualified OldHMM as OldHMM
import Criterion.Config
import Criterion.Main
import Data.Array
import Debug.Trace
import System.IO
-- | Define the tests
myConfig = defaultConfig
{ cfgPerformGC = ljust True
, cfgSamples = ljust 3
-- , cfgReport = ljust "perf.txt"
, cfgSummaryFile = ljust "perf.csv"
-- , cfgResamples = ljust 0
-- , cfgVerbosity = ljust Quiet
}
genString n = take n $ cycle "AGCT"
genArray n = listArray (1,n) $ genString n
forceEval x = putStrLn $ (show $ length str) ++ " -> " ++ (take 30 str)
where str = show x
main = defaultMainWith myConfig (return ())
-- [ bench ("baumWelch (itr="++show itr++",ord="++show order++",len="++(show arraylen)++")") $
-- whnf (baumWelch (simpleMM "AGCT" order) (genArray arraylen)) itr
--
-- | arraylen <- [1000]
-- , order <- [1..6]
-- , itr <- [1]
-- ]
[ bench ("newHMM - viterbi (states="++show states++",len="++show len++")") $ putStrLn $ show $ viterbi (simpleHMM [1..states] "AGCT") $ genArray len
| len <- [1000] -- [10,100,1000,10000,20000,30000,40000,50000,60000,70000,80000,90000,100000,200000,300000,400000,500000,1000000]
, states <- [1..100]
]
-- [ bench "newHMM - forward" $ forceEval $ forward newHMM $ genString len
-- , bench "newHMM - backward" $ forceEval $ backward newHMM $ genString len
-- , bench "oldHMM" $ forceEval $ OldHMM.sequenceProb oldHMM $ genString len
-- | len <- [100,1000,10000]
-- ]
-- | OldHMM definition
-- data HMM state observation = HMM [state] [Prob] [[Prob]] (observation -> [Prob])
oldHMM :: OldHMM.HMM Int Char
oldHMM = OldHMM.HMM [1,2]
[0.1, 0.9]
[[0.9,0.1],[0.5,0.5]]
(\obs -> case obs of
'A' -> [0.4,0.1]
'G' -> [0.1,0.4]
'C' -> [0.1,0.4]
'T' -> [0.4,0.1]
)
-- | HMM definition
newHMM = HMM { states=[1,2]
, events=['A','G','C','T']
, initProbs = ipTest
, transMatrix = tmTest
, outMatrix = omTest
}
ipTest s
| s == 1 = 0.1
| s == 2 = 0.9
tmTest s1 s2
| s1==1 && s2==1 = 0.9
| s1==1 && s2==2 = 0.1
| s1==2 && s2==1 = 0.5
| s1==2 && s2==2 = 0.5
omTest s e
| s==1 && e=='A' = 0.4
| s==1 && e=='G' = 0.1
| s==1 && e=='C' = 0.1
| s==1 && e=='T' = 0.4
| s==2 && e=='A' = 0.1
| s==2 && e=='G' = 0.4
| s==2 && e=='C' = 0.4
| s==2 && e=='T' = 0.1