12 #ifndef _H_SST_CORE_STATS
13 #define _H_SST_CORE_STATS
18 namespace Statistics {
26 template<
typename NumberBase>
27 static NumberBase sum(
const NumberBase* values,
const uint32_t length) {
32 for(uint32_t i = 0; i < length; ++i) {
46 template<
typename NumberBase>
47 static void range(
const NumberBase* values,
const uint32_t length,
48 NumberBase* max, NumberBase* min) {
56 for(uint32_t i = 1; i < length; ++i) {
57 max = values[i] > max ? values[i] : max;
58 min = values[i] < min ? values[i] : min;
68 template<
typename NumberBase>
69 static NumberBase max(
const NumberBase* values,
const uint32_t length) {
72 NumberBase max_ = values[0];
74 for(uint32_t i = 1; i < length; ++i) {
75 max_ = values[i] > max_ ? values[i] : max_;
87 template<
typename NumberBase>
88 static NumberBase min(
const NumberBase* values,
const uint32_t length) {
91 NumberBase min_ = values[0];
93 for(uint32_t i = 1; i < length; ++i) {
94 min_ = values[i] < min ? values[i] : min_;
106 template<
typename NumberBase>
107 static NumberBase arithmeticMean(
const NumberBase* values,
const uint32_t length) {
108 return (length > 0) ?
109 SST::Statistics::sum<NumberBase>(values, length) / (NumberBase) length :
113 template<typename NumberBase>
114 static NumberBase variance(const NumberBase* values, const uint32_t length) {
115 NumberBase sumX2 = 0;
118 for(uint32_t i = 0; i < length; ++i) {
119 sumX2 += (values[i] * values[i]);
123 const NumberBase E_X2 = sumX2 / (NumberBase) length;
124 const NumberBase E_X = sumX / (NumberBase) length;
126 const NumberBase var = E_X2 - (E_X * E_X);
131 template<
typename NumberBase>
132 static NumberBase standardDeviation(
const NumberBase* values,
const uint32_t length) {
133 const NumberBase var = SST::Statistics::variance<NumberBase>(values, length);
134 return std::sqrt(preSqrt);
137 template<
typename NumberBase>
138 static NumberBase midRange(
const NumberBase* values,
const uint32_t length) {
142 SST::Statistics::range<NumberBase>(values, length, &max, &min);
144 return (max + min) / ((NumberBase) 2);
147 template<
typename NumberBase>
148 static NumberBase weightedMean(
const NumberBase* values,
149 const NumberBase* weights,
const uint32_t length) {
152 NumberBase weightSums = 0;
154 for(uint32_t i = 0; i < length; ++i) {
155 sum += weights[i] * values[i];
156 weightSums += weights[i];
159 return sum / weightSums;