preCICE v3.1.2
Loading...
Searching...
No Matches
Statistics.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <boost/accumulators/accumulators.hpp>
4#include <boost/accumulators/statistics/count.hpp>
5#include <boost/accumulators/statistics/max.hpp>
6#include <boost/accumulators/statistics/mean.hpp>
7#include <boost/accumulators/statistics/min.hpp>
8#include <boost/accumulators/statistics/stats.hpp>
9#include <boost/accumulators/statistics/variance.hpp>
10#include <fmt/ostream.h>
11#include <iosfwd>
12
13namespace precice {
14namespace utils {
15namespace statistics {
16
21public:
23 void operator()(double value)
24 {
25 _acc(value);
26 }
27
29 double min() const
30 {
31 return empty() ? std::nan("") : boost::accumulators::extract::min(_acc);
32 }
33
35 double max() const
36 {
37 return empty() ? std::nan("") : boost::accumulators::extract::max(_acc);
38 }
39
41 double mean() const
42 {
43 return empty() ? std::nan("") : boost::accumulators::extract::mean(_acc);
44 }
45
47 double variance() const
48 {
49 return empty() ? std::nan("") : boost::accumulators::extract::variance(_acc);
50 }
51
54 {
55 return boost::accumulators::extract::count(_acc);
56 }
57
59 bool empty() const
60 {
61 return count() == 0;
62 }
63
64private:
65 boost::accumulators::accumulator_set<double, boost::accumulators::stats<
66 boost::accumulators::tag::min,
67 boost::accumulators::tag::max,
68 boost::accumulators::tag::mean,
69 boost::accumulators::tag::lazy_variance>>
71};
72
74{
75 if (accumulator.empty()) {
76 out << "empty";
77 } else {
78 out << "min:" << accumulator.min()
79 << " max:" << accumulator.max()
80 << " avg: " << accumulator.mean()
81 << " var: " << accumulator.variance()
82 << " cnt: " << accumulator.count();
83 }
84 return out;
85}
86
87} // namespace statistics
88} // namespace utils
89} // namespace precice
90
91template <>
92struct fmt::formatter<precice::utils::statistics::DistanceAccumulator> : ostream_formatter {
93};
std::ostream & out
double min() const
Returns the minimum of all accumulated values.
double mean() const
Returns the mean of all accumulated values.
boost::accumulators::accumulator_set< double, boost::accumulators::stats< boost::accumulators::tag::min, boost::accumulators::tag::max, boost::accumulators::tag::mean, boost::accumulators::tag::lazy_variance > > _acc
void operator()(double value)
Accumulates value.
double max() const
Returns the maximum of all accumulated values.
double variance() const
Returns the sample variance based on all accumulated values.
bool empty() const
Returns count == 0.
std::size_t count() const
Returns how many values have been accumulated.
std::ostream & operator<<(std::ostream &out, const DistanceAccumulator &accumulator)
Main namespace of the precice library.
T nan(T... args)