1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| #include <vector>
template<class T> double Mean(std::vector<T> array) { double sum = 0.0;
for (int i = 0; i < array.size(); i++) sum += array[i];
return sum / array.size(); }
template<class T> double StandardDeviation(std::vector<T> array) { double meanValue = Mean<T>(array);
int size = array.size(); if (size < 2) { return sqrt(-1.0); }
double sum = 0.0;
for (int i = 0; i < size; i++) { double diff = array[i] - meanValue; sum += diff * diff; }
return sqrt(sum / (size - 1)); }
|