fork download
  1. regressionLine ps = let
  2. xs = map fst ps
  3. ys = map snd ps
  4. avg ds = (/n) $ sum ds
  5. rval ds es
  6. = (avg $ zipWith (*) ds es) - (avg ds)*(avg es)
  7. val ds = rval ds ds
  8. avgx = avg xs
  9. valx = val xs
  10. avgy = avg ys
  11. valy = val ys
  12. rvalxy = rval xs ys
  13. a = rvalxy/valx
  14. b = avgy-a*avgx
  15. in
  16. (a,b)
  17.  
  18. dailyNewCasesInOsaka = []
  19. ++ [74,52,55,88,40,85,54]
  20. ++ [31,35,31,29,16,30,32]
  21. ++ [44]
  22.  
  23. points = id
  24. $ zip [0..]
  25. $ map log
  26. $ drop 0 dailyNewCasesInOsaka
  27.  
  28. patsAt a b x = exp $ a *x + b
  29.  
  30.  
  31. april15 = 0 + 15 - 15
  32. may06 = 30 + 06 - 15
  33.  
  34. main = do
  35. let (a,b) = regressionLine points
  36. print $ "April 15th : " ++ (show $ patsAt a b april15)
  37. print $ "The average ratio : " ++ (show $ exp a)
  38. print $ "May 6th : " ++ (show $ patsAt a b may06)
  39. print $ "Lists of the expecred number of new patients from May 1st"
  40. print $ [round $ patsAt a b x | x<-[16..22]]
  41. print $ [round $ patsAt a b x | x<-[23..29]]
  42. print $ [round $ patsAt a b x | x<-[30..36]]
  43. print $ [round $ patsAt a b x | x<-[37..43]]
Success #stdin #stdout 0s 4520KB
stdin
Standard input is empty
stdout
"April 15th : 68.97613696989895"
"The average ratio : 0.9316696264403739"
"May 6th : 15.60269248285008"
"Lists of the expecred number of new patients from May 1st"
[22,21,19,18,17,16,15]
[14,13,12,11,10,10,9]
[8,8,7,7,6,6,5]
[5,5,4,4,4,4,3]