forked from nsmryan/HEAL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstdev.hs
More file actions
33 lines (25 loc) · 737 Bytes
/
stdev.hs
File metadata and controls
33 lines (25 loc) · 737 Bytes
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
import System
import System.IO
import Data.List.Split
import Data.List
gens = 500
trials = 10
fitness = "BestFit: "
process :: String -> String
process s = show $ stdev $ splitUp $ toNumbers $ getFits s where
toNumbers :: [String] -> [Double]
toNumbers s = map read s
splitUp :: [a] -> [a]
splitUp s = map last $ splitEvery gens s
getFits :: String -> [String]
getFits s = map (drop (length fitness)) $ filter (isPrefixOf fitness) $ lines s
stdev :: [Double] -> Double
stdev nums = sqrt $ (/len) $ sum $ map (\i -> (avg-i)^2) nums where
len = fromIntegral $ length nums
avg = (sum nums) / len
main = do
args <- getArgs
let name = args !! 0
contents <- readFile name
let result = process contents
putStrLn result