36 typename std::vector<double>;
49 template <
typename InputIterator>
50 Histogram(InputIterator first, InputIterator last,
const int nr_bins = 16,
51 const bool computeHistogram =
true)
54 init(computeHistogram);
63 explicit Histogram(std::vector<T> data,
const unsigned int nr_bins = 16,
64 const bool computeHistogram =
true)
67 init(computeHistogram);
89 auto it =
data_.begin();
90 for (
unsigned int bin = 0; bin <
nr_bins_; bin++)
92 auto itEnd = std::upper_bound(it,
data_.end(),
118 void prettyPrint(std::ostream& os,
const unsigned int line_width = 16)
const
120 const std::size_t count_max =
122 for (
unsigned int bin = 0; bin <
nr_bins_; ++bin)
129 std::ceil(line_width * ((
double)
histogram_[bin] / count_max));
130 for (
int star = 0; star < n_stars; star++)
138 int write(std::string
const& file_name, std::string
const& data_set_name,
139 std::string
const& param_name)
const
141 if (file_name.empty())
143 ERR(
"No file name specified.");
147 std::ofstream out(file_name);
150 ERR(
"Error writing histogram: Could not open file.");
154 out <<
"# Histogram for parameter " << param_name <<
" of data set "
155 << data_set_name <<
"\n";
157 std::vector<std::size_t>
const& bin_cnts(this->
getBinCounts());
161 for (std::size_t k(0); k < n_bins; k++)
163 out << min + k * bin_width <<
" " << bin_cnts[k] <<
"\n";
172 void init(
const bool computeHistogram =
true)
181 if (computeHistogram)
202 template <
typename T>
208 std::ostream_iterator<T>(os,
" "));
209 return os << std::endl;
void ERR(char const *fmt, Args const &... args)
const T & getBinWidth() const
const unsigned int & getNumberOfBins() const
bool dirty_
When set update() will recompute histogram.
const T & getMinimum() const
void setMaximum(const T &maximum)
T max_
Minimum and maximum input data values.
void init(const bool computeHistogram=true)
void prettyPrint(std::ostream &os, const unsigned int line_width=16) const
Histogram(std::vector< T > data, const unsigned int nr_bins=16, const bool computeHistogram=true)
const std::vector< std::size_t > & getBinCounts() const
const Data & getSortedData() const
typename std::vector< double > Data
std::vector< std::size_t > histogram_
const T & getMaximum() const
Histogram(InputIterator first, InputIterator last, const int nr_bins=16, const bool computeHistogram=true)
Underlying input data vector type.
void setMinimum(const T &minimum)
const unsigned int nr_bins_
int write(std::string const &file_name, std::string const &data_set_name, std::string const ¶m_name) const
std::ostream & operator<<(std::ostream &os, const Histogram< T > &h)
void copy(PETScVector const &x, PETScVector &y)