123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- using System;
- using System.Collections.Generic;
- namespace WingAIDiagnosisService.Carotid.Utilities
- {
- public class GeneralFormulas
- {
- public static bool StatisticsThickness(List<float> thicknessList, out float max,
- out float min, out float average, out float variance)
- {
- max = 0;
- min = 0;
- average = 0;
- variance = 0;
- if (thicknessList != null && thicknessList.Count > 1)
- {
- max = thicknessList[0];
- min = thicknessList[1];
- float sum = 0;
- variance = StandardDeviation(thicknessList);
- foreach (var value in thicknessList)
- {
- if (value > max)
- {
- max = value;
- }
- else if (value < min)
- {
- min = value;
- }
- sum += value;
- }
- average = sum / thicknessList.Count;
- return true;
- }
- return false;
- }
- private static float StandardDeviation(IList<float> thickness)
- {
- float variance = 0;
- if (thickness != null && thickness.Count > 0)
- {
- double sum = 0;
- for (var i = 0; i < thickness.Count; i++)
- {
- sum += thickness[i];
- }
- var avg = (float)(sum / thickness.Count);
- foreach (var value in thickness)
- {
- variance += (float)Math.Pow(value - avg, 2);
- }
- variance = (float)Math.Sqrt((variance / thickness.Count));
- }
- return variance;
- }
- }
- }
|