6 #ifndef UTILS_STATISTICS_H 7 #define UTILS_STATISTICS_H 8 #include <glm/detail/func_common.hpp> 9 #include <glm/detail/func_exponential.hpp> 33 template<
typename Type>
47 data_.reserve(initial_capacity);
53 data_.reserve(data_vector.size());
54 for (
const auto &value : data_vector)
71 data_min_ = std::numeric_limits<Type>::max();
72 data_max_ = std::numeric_limits<Type>::lowest();
76 void Add(
const Type value)
78 if (data_.capacity() == data_.size())
80 data_.reserve(2 * data_.capacity());
82 data_.push_back(value);
84 data_min_ = glm::min(value, data_min_);
85 data_max_ = glm::max(value, data_max_);
107 return data_sum_ / Type(data_.size());
127 for (
size_t i = 0; i < data_.size(); ++i)
129 const auto dev = avg - data_[i];
132 return glm::sqrt(sum / Type(data_.size()));
139 text +=
"Statistic data: ";
140 text += std::to_string(data_.size()) +
" records, ";
141 text +=
"sum of elements " + std::to_string(data_sum_) +
", ";
142 text +=
"min " + std::to_string(data_min_) +
", ";
143 text +=
"max " + std::to_string(data_max_) +
", ";
144 text +=
"average " + std::to_string(
Average()) +
".";
149 std::vector<Type> data_;
150 Type data_sum_ = Type(0);
151 Type data_min_ = std::numeric_limits<Type>::max();
152 Type data_max_ = std::numeric_limits<Type>::lowest();
Type Min() const
Returns minimal value of the data set.
Definition: Statistics.h:111
Statistics()
Creates new instance with default capacity of the data set.
Definition: Statistics.h:39
bool IsEmpty() const
Checks if there are no data records.
Definition: Statistics.h:61
std::string ToString() const
Prints all statistical values to the string and returns it.
Definition: Statistics.h:136
void Add(const Type value)
Stores a data record in the data set.
Definition: Statistics.h:76
Type Average() const
Returns average value of the data set.
Definition: Statistics.h:101
void Clear()
Removes all stored data.
Definition: Statistics.h:67
Type StandardDeviation() const
Returns standard deviation of the data set.
Definition: Statistics.h:123
Type Sum() const
Returns a sum of all elements in the data set.
Definition: Statistics.h:95
Statistics(const std::vector< Type > &data_vector)
Creates new instance with initialized data set.
Definition: Statistics.h:51
General namespace for utilities.
Definition: BulletConversions.h:9
Statistics(size_t initial_capacity)
Creates new instance with specific capacity of the data set.
Definition: Statistics.h:45
Type Max() const
Returns maximal value of the data set.
Definition: Statistics.h:117
Calculates statistical evaluation on a data set.
Definition: Statistics.h:34
size_t Count() const
Returns number of stored data records.
Definition: Statistics.h:89