GeneralFormulas.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System;
  2. using System.Collections.Generic;
  3. namespace WingAIDiagnosisService.Carotid.Utilities
  4. {
  5. public class GeneralFormulas
  6. {
  7. public static bool StatisticsThickness(List<float> thicknessList, out float max,
  8. out float min, out float average, out float variance)
  9. {
  10. max = 0;
  11. min = 0;
  12. average = 0;
  13. variance = 0;
  14. if (thicknessList != null && thicknessList.Count > 1)
  15. {
  16. max = thicknessList[0];
  17. min = thicknessList[1];
  18. float sum = 0;
  19. variance = StandardDeviation(thicknessList);
  20. foreach (var value in thicknessList)
  21. {
  22. if (value > max)
  23. {
  24. max = value;
  25. }
  26. else if (value < min)
  27. {
  28. min = value;
  29. }
  30. sum += value;
  31. }
  32. average = sum / thicknessList.Count;
  33. return true;
  34. }
  35. return false;
  36. }
  37. private static float StandardDeviation(IList<float> thickness)
  38. {
  39. float variance = 0;
  40. if (thickness != null && thickness.Count > 0)
  41. {
  42. double sum = 0;
  43. for (var i = 0; i < thickness.Count; i++)
  44. {
  45. sum += thickness[i];
  46. }
  47. var avg = (float)(sum / thickness.Count);
  48. foreach (var value in thickness)
  49. {
  50. variance += (float)Math.Pow(value - avg, 2);
  51. }
  52. variance = (float)Math.Sqrt((variance / thickness.Count));
  53. }
  54. return variance;
  55. }
  56. }
  57. }