30 #ifndef MATH_UTIL_STAT_BUFFER_H_ 31 #define MATH_UTIL_STAT_BUFFER_H_ 34 #define PI 3.14159265358979 153 int NumElems = this->
size();
154 if (NumElems <= 0)
return (T)(0.0);
157 NumToAvg = std::min(NumToAvg, NumElems);
158 for (
int i = 0; i < NumToAvg; ++i)
163 T mean = sum/((T)NumToAvg);
169 int NumElems = this->
size();
170 if (NumElems <= 0)
return false;
173 T &min = RetainedStats.
min;
174 T &max = RetainedStats.
max;
175 T &mean = RetainedStats.
mean;
176 T &median = RetainedStats.
median;
177 T &
std = RetainedStats.
std;
180 T CurVal = *this->
get(0);
190 for (
int i = 1; i < NumElems; i++)
192 CurVal = *this->
get(i);
194 if (CurVal > max) max = CurVal;
195 else if (CurVal < min) min = CurVal;
197 mean = sum/((T)NumElems);
203 T *vec1 =
new T[NumElems];
204 for (
int i = 0; i < NumElems; i++)
206 CurVal = *this->
get(i);
207 sum += (CurVal-mean)*(CurVal-mean);
210 std=(T)sqrt(static_cast<double>(sum/(NumElems-1)));
214 std::sort(vec1, vec1+NumElems);
215 if (NumElems % 2 == 0)
217 median = (vec1[NumElems/2-1] + vec1[NumElems/2])/2;
221 median = vec1[NumElems/2];
238 int NumElems = this->
size();
239 if (NumElems <= 1)
return false;
242 T &min = RetainedDiffStats.
min;
243 T &max = RetainedDiffStats.
max;
244 T &mean = RetainedDiffStats.
mean;
245 T &median = RetainedDiffStats.
median;
247 T *vec1 =
new T[NumElems];
249 T CurVal1 = *this->
get(0);
250 T CurVal2 = *this->
get(1);
251 T CVDiff = CurVal2-CurVal1;
260 for (
int i = 1; i < NumElems-1; i++)
262 CurVal1 = *this->
get(i);
263 CurVal2 = *this->
get(i+1);
264 CVDiff = CurVal2-CurVal1;
267 if (CVDiff > max) max = CVDiff;
268 else if (CVDiff < min) min = CVDiff;
270 mean = sum/((T)NumElems);
273 std::sort(vec1, vec1+NumElems);
274 if (NumElems % 2 == 0)
276 median = (vec1[NumElems/2-1] + vec1[NumElems/2])/2;
280 median = vec1[NumElems/2];
291 #endif // MATH_UTIL_STAT_BUFFER_H_
T * getTail(int i=0) const
void modifyBufferSize(int NumElements)
void realloc_mem(int NumElements2Alloc)
T reportPartialMean(int NumToAvg)
StatPack RetainedDiffStats
StatBuffer(int NumElements)
T computeMean(int NumToAvg)