43 #include <boost/format.hpp>
51 filePrefix,
const bool dumpStdErrOnExit):
54 filePrefix(filePrefix),
55 dumpStdErrOnExit(dumpStdErrOnExit)
62 T meanV, varV, medianV, lowQt, highQt, minV, maxV;
64 if (!dumpStdErrOnExit && filePrefix.empty())
67 const vector<uint64_t> bins(computeStats(meanV, varV, medianV, lowQt, highQt, minV, maxV, maxBinC));
69 if (!filePrefix.empty())
71 std::cerr <<
"writing to " << (filePrefix + name +
"Stats.csv") << std::endl;
72 std::ofstream ofs_stats((filePrefix + name +
"Stats.csv").c_str());
73 dumpStatsHeader(ofs_stats);
77 std::cerr <<
"writing to " << (filePrefix + name +
".csv") << std::endl;
78 std::ofstream ofs((filePrefix + name +
".csv").c_str());
79 for (
size_t i = 0; i < this->size(); ++i)
80 ofs << ((*
this)[i]) <<
"\n";
85 std::cerr.precision(4);
87 std::cerr.flags(std::ios::left);
88 std::cerr <<
"Histogram " << name <<
":\n";
89 std::cerr <<
" count: " << this->size() <<
", mean: " << meanV <<
", var: " << varV <<
", median: " << medianV <<
", min: " << minV <<
", max: " << maxV <<
", lowQt: " << lowQt <<
", highQt: " << highQt <<
", maxBinC: " << maxBinC <<
"\n";
92 for (
size_t i = 0; i < binCount; ++i)
94 const T v(minV + i * (maxV - minV) / T(binCount));
95 std::cerr <<
" " << std::setw(10) << v <<
" (" << std::setw(6) << bins[i] <<
") : ";
98 for (
size_t j = 0; j < (bins[i] * 60) / maxBinC; ++j)
103 std::cerr << std::endl;
111 typedef typename std::vector<T>::iterator Iterator;
112 vector<uint64_t> bins(binCount, 0);
119 minV = std::numeric_limits<T>::max();
120 maxV = std::numeric_limits<T>::min();
121 for (
size_t i = 0; i < this->size(); ++i)
123 const T v((*
this)[i]);
125 minV = std::min<T>(minV, v);
126 maxV = std::max<T>(maxV, v);
128 meanV /= T(this->size());
130 std::fill(bins.begin(), bins.end(), uint64_t(0));
135 medianV = lowQt = highQt = minV;
138 for (
size_t i = 0; i < this->size(); ++i)
140 const T v((*
this)[i]);
141 varV += (v - meanV)*(v - meanV);
142 const size_t index((v - minV) * (binCount) / ((maxV - minV) * (1+std::numeric_limits<T>::epsilon()*10)));
145 maxBinC = std::max<uint64_t>(maxBinC, bins[index]);
147 varV /= T(this->size());
149 const Iterator lowQtIt(this->begin() + (this->size() / 4));
150 const Iterator medianIt(this->begin() + (this->size() / 2));
151 const Iterator highQtIt(this->begin() + (3*this->size() / 4));
152 std::nth_element(this->begin(), medianIt, this->end());
154 std::nth_element(this->begin(), lowQtIt, this->end());
156 std::nth_element(this->begin(), highQtIt, this->end());
161 meanV = std::numeric_limits<T>::quiet_NaN();
162 varV = std::numeric_limits<T>::quiet_NaN();
163 medianV = std::numeric_limits<T>::quiet_NaN();
164 lowQt = std::numeric_limits<T>::quiet_NaN();
165 highQt = std::numeric_limits<T>::quiet_NaN();
166 minV = std::numeric_limits<T>::quiet_NaN();
167 maxV = std::numeric_limits<T>::quiet_NaN();
176 T meanV, varV, medianV, lowQt, highQt, minV, maxV;
178 const vector<uint64_t> bins(computeStats(meanV, varV, medianV, lowQt, highQt, minV, maxV, maxBinC));
179 os << this->size() <<
", " << meanV <<
", " << varV <<
", " << medianV <<
", " << lowQt <<
", " << highQt <<
", " << minV <<
", " << maxV <<
", " << binCount <<
", ";
181 for (
size_t i = 0; i < binCount; ++i)
182 os << bins[i] <<
", ";
189 os << name +
"_count, ";
190 os << name +
"_mean, ";
191 os << name +
"_var, ";
192 os << name +
"_median, ";
193 os << name +
"_low_quartile, ";
194 os << name +
"_high_quartile, ";
195 os << name +
"_min_value, ";
196 os << name +
"_max_value, ";
197 os << name +
"_bin_count, ";
198 for (
size_t i = 0; i < binCount; ++i)
199 os << (boost::format(
"%1%_bin_%2%,") % name % i).str();
200 os << name +
"_max_elements_per_bin ";