-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathTest5.hs
More file actions
46 lines (34 loc) · 1.28 KB
/
Test5.hs
File metadata and controls
46 lines (34 loc) · 1.28 KB
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
module Test5 where
import Graphics.Rendering.Chart
import Data.Colour
import Data.Colour.Names
import Control.Lens
import Data.Default.Class
import System.Random
import Utils
----------------------------------------------------------------------
-- Example thanks to Russell O'Connor
chart :: Double -> Renderable (LayoutPick Double LogValue LogValue)
chart lwidth = layoutToRenderable (layout 1001 (trial bits) :: Layout Double LogValue)
where
bits = randoms $ mkStdGen 0
layout n t = layout_title .~ "Simulation of betting on a biased coin"
$ layout_plots .~ [
toPlot (plot "f=0.05" s1 n 0 (t 0.05)),
toPlot (plot "f=0.1" s2 n 0 (t 0.1))
]
$ def
plot tt s n m t = plot_lines_style .~ s
$ plot_lines_values .~
[[(fromIntegral x, LogValue y) | (x,y) <-
filter (\(x,_)-> x `mod` (m+1)==0) $ take n $ zip [0..] t]]
$ plot_lines_title .~ tt
$ def
b = 0.1
trial bits frac = scanl (*) 1 (map f bits)
where
f True = (1+frac*(1+b))
f False = (1-frac)
s1 = solidLine lwidth $ opaque green
s2 = solidLine lwidth $ opaque blue
-- main = main' "test5" (chart 0.25)