44 #include <boost/format.hpp>
52 filePrefix,
const bool dumpStdErrOnExit):
55 filePrefix(filePrefix),
56 dumpStdErrOnExit(dumpStdErrOnExit)
63 T meanV, varV, medianV, lowQt, highQt, minV, maxV;
65 if (!dumpStdErrOnExit && filePrefix.empty())
68 const vector<uint64_t> bins(computeStats(meanV, varV, medianV, lowQt, highQt, minV, maxV, maxBinC));
70 if (!filePrefix.empty())
73 std::ofstream ofs_stats((filePrefix +
name +
"Stats.csv").c_str());
74 dumpStatsHeader(ofs_stats);
79 std::ofstream ofs((filePrefix +
name +
".csv").c_str());
80 for (
size_t i = 0; i < this->size(); ++i)
81 ofs << ((*
this)[i]) <<
"\n";
86 std::cerr.precision(4);
88 std::cerr.flags(std::ios::left);
89 std::cerr <<
"Histogram " <<
name <<
":\n";
90 std::cerr <<
" count: " << this->size() <<
", mean: " << meanV <<
", var: " << varV <<
", median: " << medianV <<
", min: " << minV <<
", max: " << maxV <<
", lowQt: " << lowQt <<
", highQt: " << highQt <<
", maxBinC: " << maxBinC <<
"\n";
93 for (
size_t i = 0; i < binCount; ++i)
95 const T v(minV + i * (maxV - minV) /
T(binCount));
96 std::cerr <<
" " << std::setw(10) << v <<
" (" << std::setw(6) << bins[i] <<
") : ";
99 for (
size_t j = 0; j < (bins[i] * 60) / maxBinC; ++j)
104 std::cerr << std::endl;
112 typedef typename std::vector<T>::iterator Iterator;
113 vector<uint64_t> bins(binCount, 0);
120 minV = std::numeric_limits<T>::max();
121 maxV = std::numeric_limits<T>::min();
122 for (
size_t i = 0; i < this->size(); ++i)
124 const T v((*
this)[i]);
126 minV = std::min<T>(minV, v);
127 maxV = std::max<T>(maxV, v);
129 meanV /=
T(this->size());
131 std::fill(bins.begin(), bins.end(), uint64_t(0));
136 medianV = lowQt = highQt = minV;
139 for (
size_t i = 0; i < this->size(); ++i)
141 const T v((*
this)[i]);
142 varV += (v - meanV)*(v - meanV);
143 const size_t index((v - minV) * (binCount) / ((maxV - minV) * (1+std::numeric_limits<T>::epsilon()*10)));
146 maxBinC = std::max<uint64_t>(maxBinC, bins[index]);
148 varV /=
T(this->size());
150 std::vector<T> hystCpy((*
this));
151 const Iterator lowQtIt(hystCpy.begin() + (hystCpy.size() / 4));
152 const Iterator medianIt(hystCpy.begin() + (hystCpy.size() / 2));
153 const Iterator highQtIt(hystCpy.begin() + (3*hystCpy.size() / 4));
154 std::nth_element(hystCpy.begin(), medianIt, hystCpy.end());
156 std::nth_element(hystCpy.begin(), lowQtIt, hystCpy.end());
158 std::nth_element(hystCpy.begin(), highQtIt, hystCpy.end());
163 meanV = std::numeric_limits<T>::quiet_NaN();
164 varV = std::numeric_limits<T>::quiet_NaN();
165 medianV = std::numeric_limits<T>::quiet_NaN();
166 lowQt = std::numeric_limits<T>::quiet_NaN();
167 highQt = std::numeric_limits<T>::quiet_NaN();
168 minV = std::numeric_limits<T>::quiet_NaN();
169 maxV = std::numeric_limits<T>::quiet_NaN();
178 T meanV, varV, medianV, lowQt, highQt, minV, maxV;
180 const vector<uint64_t> bins(computeStats(meanV, varV, medianV, lowQt, highQt, minV, maxV, maxBinC));
181 os << this->size() <<
", " << meanV <<
", " << varV <<
", " << medianV <<
", " << lowQt <<
", " << highQt <<
", " << minV <<
", " << maxV <<
", " << binCount <<
", ";
183 for (
size_t i = 0; i < binCount; ++i)
184 os << bins[i] <<
", ";
191 os <<
name +
"_count, ";
192 os <<
name +
"_mean, ";
193 os <<
name +
"_var, ";
194 os <<
name +
"_median, ";
195 os <<
name +
"_low_quartile, ";
196 os <<
name +
"_high_quartile, ";
197 os <<
name +
"_min_value, ";
198 os <<
name +
"_max_value, ";
199 os <<
name +
"_bin_count, ";
200 for (
size_t i = 0; i < binCount; ++i)
201 os << (boost::format(
"%1%_bin_%2%,") %
name % i).str();
202 os <<
name +
"_max_elements_per_bin ";