Statistics
| Branch: | Tag: | Revision:

## root / src / Utils.hs @ e4f08c46

 1 ```{-| Utility functions -} ``` ```module Utils where ``` ```import Data.List ``` ```import Debug.Trace ``` ```-- | To be used only for debugging, breaks referential integrity. ``` ```debug :: Show a => a -> a ``` ```debug x = trace (show x) x ``` ```-- | Comma-join a string list. ``` ```commaJoin :: [String] -> String ``` ```commaJoin = intercalate "," ``` ```-- | Split a string on a separator and return an array. ``` ```sepSplit :: Char -> String -> [String] ``` ```sepSplit sep s ``` ``` | x == "" && xs == [] = [] ``` ``` | xs == [] = [x] ``` ``` | ys == [] = x:"":[] ``` ``` | otherwise = x:(sepSplit sep ys) ``` ``` where (x, xs) = break (== sep) s ``` ``` ys = drop 1 xs ``` ```-- | Partial application of sepSplit to @'.'@ ``` ```commaSplit :: String -> [String] ``` ```commaSplit = sepSplit ',' ``` ```-- | Swap a list of @(a, b)@ into @(b, a)@ ``` ```swapPairs :: [(a, b)] -> [(b, a)] ``` ```swapPairs = map (\ (a, b) -> (b, a)) ``` ```-- Simple and slow statistical functions, please replace with better versions ``` ```-- | Mean value of a list. ``` ```meanValue :: Floating a => [a] -> a ``` ```meanValue lst = (sum lst) / (fromIntegral \$ length lst) ``` ```-- | Standard deviation. ``` ```stdDev :: Floating a => [a] -> a ``` ```stdDev lst = ``` ``` let mv = meanValue lst ``` ``` square = (^ (2::Int)) -- silences "defaulting the constraint..." ``` ``` av = sum \$ map square \$ map (\e -> e - mv) lst ``` ``` bv = sqrt (av / (fromIntegral \$ length lst)) ``` ``` in bv ``` ```-- | Coefficient of variation. ``` ```varianceCoeff :: Floating a => [a] -> a ``` ```varianceCoeff lst = (stdDev lst) / (fromIntegral \$ length lst) ```