66 static_assert(std::is_default_constructible_v<T>,
67 "Accumulator type parameters must be default constructible.");
70 void add(
const T& val) {
75 Avg_ += (val - Avg_) /
static_cast<RealType
>(Count_);
76 Avg2_ += (val * val - Avg2_) /
static_cast<RealType
>(Count_);
82 Max_ = val > Max_ ? val : Max_;
83 Min_ = val < Min_ ? val : Min_;
87 std::size_t getCount()
const {
return Count_; }
89 T getLastValue()
const {
return Val_; }
96 RealType getMax()
const {
97 static_assert(std::is_arithmetic<T>::value,
98 "getMax() requires a RealType Accumulator.");
103 RealType getMin()
const {
104 static_assert(std::is_arithmetic<T>::value,
105 "getMin() requires a RealType Accumulator.");
110 RealType getAverage()
const {
115 RealType getVariance()
const {
117 T var = (Avg2_ - Avg_ * Avg_);
118 if (var < 0) var = 0;
123 RealType getStdDev()
const {
125 T sd = std::sqrt(this->getVariance());
130 RealType get95percentConfidenceInterval()
const {
133 1.960 * this->getStdDev() / std::sqrt(
static_cast<RealType
>(Count_));
139 std::size_t Count_ {};
140 T Val_ {}, Total_ {};
141 RealType Max_ {}, Min_ {}, Avg_ {}, Avg2_ {};
150 constexpr static RealType BinEmptyFlag =
151 std::numeric_limits<RealType>::max();
153 void add(
const std::vector<RealType>& val) {
154 if (val.empty() || (val.size() != Avg_.size() && !Avg_.empty())) {
155 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
156 "Size of vector passed to add() did not "
157 "match the size of the StaticAccumulator.");
158 painCave.isFatal = 1;
165 Val_.resize(val.size());
166 Total_.resize(val.size());
167 Avg_.resize(val.size());
168 Avg2_.resize(val.size());
171 for (std::size_t i = 0; i < val.size(); i++) {
174 if (val[i] == BinEmptyFlag)
continue;
177 Avg_[i] += (val[i] - Avg_[i]) /
static_cast<RealType
>(Count_);
179 (val[i] * val[i] - Avg2_[i]) /
static_cast<RealType
>(Count_);
183 std::size_t getCount()
const {
return Count_; }
185 std::vector<RealType> getLastValue()
const {
return Val_; }
187 std::vector<RealType> getTotal()
const {
return Total_; }
189 std::vector<RealType> getAverage()
const {
return Avg_; }
191 std::vector<RealType> getVariance()
const {
192 std::vector<RealType> var(Avg_.size());
194 for (std::size_t i = 0; i < Avg_.size(); i++) {
195 var[i] = (Avg2_[i] - Avg_[i] * Avg_[i]);
196 if (var[i] < 0) var[i] = 0;
202 std::vector<RealType> getStdDev()
const {
203 std::vector<RealType> sd(Avg_.size());
204 std::vector<RealType> variance = this->getVariance();
206 for (std::size_t i = 0; i < variance.size(); i++) {
207 sd[i] = std::sqrt(variance[i]);
213 std::vector<RealType> get95percentConfidenceInterval()
const {
214 std::vector<RealType> ci(Avg_.size());
215 std::vector<RealType> stdDev = this->getStdDev();
217 for (std::size_t i = 0; i < stdDev.size(); i++) {
218 ci[i] = 1.960 * stdDev[i] / std::sqrt(
static_cast<RealType
>(Count_));
225 std::size_t Count_ {};
226 std::vector<RealType> Val_ {}, Total_ {}, Avg_ {}, Avg2_ {};
235 for (std::size_t i = 0; i < Dim; i++) {
238 Avg_[i] += (val[i] - Avg_[i]) /
static_cast<RealType
>(Count_);
240 (val[i] * val[i] - Avg2_[i]) /
static_cast<RealType
>(Count_);
244 std::size_t getCount()
const {
return Count_; }
265 for (std::size_t i = 0; i < Dim; i++) {
266 var[i] = (Avg2_[i] - Avg_[i] * Avg_[i]);
267 if (var[i] < 0) var[i] = 0;
279 for (std::size_t i = 0; i < Dim; i++) {
280 sd[i] = std::sqrt(variance[i]);
292 for (std::size_t i = 0; i < Dim; i++) {
293 ci[i] = 1.960 * stdDev[i] / std::sqrt(
static_cast<RealType
>(Count_));
300 std::size_t Count_ {};
310 for (std::size_t i = 0; i < 3; i++) {
311 for (std::size_t j = 0; j < 3; j++) {
312 Val_(i, j) = val(i, j);
313 Total_(i, j) += val(i, j);
315 (val(i, j) - Avg_(i, j)) /
static_cast<RealType
>(Count_);
316 Avg2_(i, j) += (val(i, j) * val(i, j) - Avg2_(i, j)) /
317 static_cast<RealType
>(Count_);
322 std::size_t getCount()
const {
return Count_; }
324 Mat3x3d getLastValue()
const {
return Val_; }
343 for (std::size_t i = 0; i < 3; i++) {
344 for (std::size_t j = 0; j < 3; j++) {
345 var(i, j) = (Avg2_(i, j) - Avg_(i, j) * Avg_(i, j));
346 if (var(i, j) < 0) var(i, j) = 0;
357 Mat3x3d variance = this->getVariance();
359 for (std::size_t i = 0; i < 3; i++) {
360 for (std::size_t j = 0; j < 3; j++) {
361 sd(i, j) = std::sqrt(variance(i, j));
368 Mat3x3d get95percentConfidenceInterval()
const {
372 Mat3x3d stdDev = this->getStdDev();
374 for (std::size_t i = 0; i < 3; i++) {
375 for (std::size_t j = 0; j < 3; j++) {
377 1.960 * stdDev(i, j) / std::sqrt(
static_cast<RealType
>(Count_));
385 std::size_t Count_ {};
386 Mat3x3d Val_ {}, Total_ {}, Avg_ {}, Avg2_ {};