Stats.java 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * def stats(self,r):
  3. #returns the average, standard deviation, and min of a sequence
  4. tot = sum(r)
  5. ave = tot/len(r)
  6. sdsq = sum([(i-ave)**2 for i in r])
  7. s = list(r)
  8. s.sort()
  9. #median = s[len(s)//2]
  10. return ave, (sdsq/(len(r)-1 or 1))**.5
  11. def zscore(self,pop_mean,pop_std,raw_goid):
  12. return (raw_goid - pop_mean)/pop_std
  13. */
  14. /**
  15. *
  16. * @author DTian
  17. */
  18. public class Stats {
  19. /**
  20. *
  21. * @param data the double array
  22. * @return the stand deviation of the array
  23. */
  24. public static double getStdDev(double[] data) {
  25. double result = 0.0;
  26. double ave = getMean(data);
  27. for (double d : data) {
  28. result += Math.pow((d-ave), 2);
  29. }
  30. if (data.length>1) {
  31. return Math.sqrt(result/(data.length-1));
  32. } else {
  33. return Math.sqrt(result/1);
  34. }
  35. }
  36. /**
  37. *
  38. * @param data the double array
  39. * @return the mean of the double array.
  40. */
  41. public static double getMean(double[] data) {
  42. double result = 0.0;
  43. for (double d : data) {
  44. result += d;
  45. }
  46. return (result/data.length);
  47. }
  48. /**
  49. *
  50. * @param size the size of ori cluster File
  51. * @return the mean of the double array.
  52. */
  53. public static double getMeanFromFunc(int size) {
  54. return ( -4.8616 + 71.1806/Math.pow(size, 0.33511));
  55. }
  56. /**
  57. *
  58. * @param size the size of ori cluster File
  59. * @return the mean of the double array.
  60. */
  61. public static double getStdDevFromFunc(int size) {
  62. return ( -0.04943 + 56.634/Math.pow(size, 0.89384));
  63. }
  64. public static double getZscore(double popMean, double popStd, double rawGoid) {
  65. return (rawGoid - popMean)/popStd;
  66. }
  67. }