OLD | NEW |
(Empty) | |
| 1 #ifndef Stats_DEFINED |
| 2 #define Stats_DEFINED |
| 3 |
| 4 struct Stats { |
| 5 Stats(const double samples[], int n) { |
| 6 min = samples[0]; |
| 7 max = samples[0]; |
| 8 for (int i = 0; i < n; i++) { |
| 9 if (samples[i] < min) { min = samples[i]; } |
| 10 if (samples[i] > max) { max = samples[i]; } |
| 11 } |
| 12 |
| 13 double sum = 0.0; |
| 14 for (int i = 0 ; i < n; i++) { |
| 15 sum += samples[i]; |
| 16 } |
| 17 mean = sum / n; |
| 18 |
| 19 double err = 0.0; |
| 20 for (int i = 0 ; i < n; i++) { |
| 21 err += (samples[i] - mean) * (samples[i] - mean); |
| 22 } |
| 23 var = err / (n-1); |
| 24 } |
| 25 |
| 26 double min; |
| 27 double max; |
| 28 double mean; // Estimate of population mean. |
| 29 double var; // Estimate of population variance. |
| 30 }; |
| 31 |
| 32 #endif//Stats_DEFINED |
OLD | NEW |