RSieve

EPS formulas

Sep 9th, 2018
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- EPS formulas for mean and variance calculations
  2. mean :: [Float] -> Float
  3. mean [] = 0
  4. mean x = sum x / fromIntegral (length x)
  5.  
  6. s :: [Float] -> Float
  7. s [] = 0
  8. s x = sqrt ((sum (map (\xs -> (xs - (mean x)) ** 2) x)) / (fromIntegral ((length x) - 1)))
  9.  
  10. -- recursive versions
  11.  
  12. s_recursive :: [Float] -> Float
  13. s_recursive [] = 0
  14. s_recursive x = sqrt ((aux x (mean x)) / (fromIntegral ((length x) - 1)))
  15.     where
  16.         aux [] _ = 0
  17.         aux (x : xs) y = ((x - y) ** 2) + aux xs y
  18.  
  19. mean_recursive :: [Float] -> Float
  20. mean_recursive [] = 0
  21. mean_recursive x = aux x / fromIntegral (length x)
  22.     where
  23.         aux [] = 0
  24.         aux (x : xs) = x + aux xs
Advertisement