20#ifndef OPM_RUNNING_STATISTICS_HPP
21#define OPM_RUNNING_STATISTICS_HPP
34template <
typename Scalar>
43 template <
class Serializer>
58 stat.sampleSize_ = 12;
59 stat.min_ = -
static_cast<Scalar
>(1);
60 stat.max_ =
static_cast<Scalar
>(2);
61 stat.mean_ =
static_cast<Scalar
>(0.03);
62 stat.totalVariance_ =
static_cast<Scalar
>(0.4);
75 return (this->sampleSize_ ==
that.sampleSize_)
76 && (this->min_ ==
that.min_)
77 && (this->max_ ==
that.max_)
78 && (this->mean_ ==
that.mean_)
79 && (this->totalVariance_ ==
that.totalVariance_)
87 this->sampleSize_ = 0;
88 this->min_ = std::numeric_limits<Scalar>::max();
89 this->max_ = std::numeric_limits<Scalar>::lowest();
90 this->mean_ = Scalar{};
91 this->totalVariance_ = Scalar{};
102 if (x > this->max_) { this->max_ = x; }
108 const auto d1 = x - this->
mean();
109 this->mean_ +=
d1 / this->sampleSize_;
111 const auto d2 = x - this->
mean();
112 this->totalVariance_ +=
d1 *
d2;
122 Scalar
min()
const {
return this->min_; }
125 Scalar
max()
const {
return this->max_; }
128 Scalar
mean()
const {
return this->mean_; }
136 if (this->sampleSize_ < 2) {
141 return sqrt(this->totalVariance_ / (this->sampleSize_ - 1));
146 std::size_t sampleSize_{};
149 Scalar min_ { std::numeric_limits<Scalar>::max() };
152 Scalar max_ { std::numeric_limits<Scalar>::lowest() };
158 Scalar totalVariance_{};
Facility for calculating simple sample statistics without having full sample available.
Definition RunningStatistics.hpp:36
Scalar max() const
Retrieve largest sample value seen so far.
Definition RunningStatistics.hpp:125
std::size_t sampleSize() const
Retrieve current sample size.
Definition RunningStatistics.hpp:119
void reset()
Reset internal counters to prepare for calculating a new set of sample statistics.
Definition RunningStatistics.hpp:85
Scalar min() const
Retrieve smallest sample value seen so far.
Definition RunningStatistics.hpp:122
void addSamplePoint(const Scalar x)
Include new element into sample.
Definition RunningStatistics.hpp:99
Scalar mean() const
Retrieve arithmetic average of all sample points seen so far.
Definition RunningStatistics.hpp:128
std::optional< Scalar > stdev() const
Retrieve unbiased standard deviation of all sample points seen so far.
Definition RunningStatistics.hpp:134
void serializeOp(Serializer &serializer)
Convert between byte array and object representation.
Definition RunningStatistics.hpp:44
static RunningStatistics serializationTestObject()
Create a serialisation test object.
Definition RunningStatistics.hpp:54
bool operator==(const RunningStatistics &that) const
Equality predicate.
Definition RunningStatistics.hpp:73
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition blackoilboundaryratevector.hh:37
constexpr auto getPropValue()
get the value data member of a property
Definition propertysystem.hh:242