10#ifndef OPENVDB_MATH_STATS_HAS_BEEN_INCLUDED 
   11#define OPENVDB_MATH_STATS_HAS_BEEN_INCLUDED 
   14#include <openvdb/version.h> 
   30template <
typename ValueType, 
typename Less = std::less<ValueType> >
 
   33    using Limits = std::numeric_limits<ValueType>;
 
   41        static_assert(std::numeric_limits<ValueType>::is_specialized,
 
   42                      "openvdb::math::MinMax default constructor requires a std::numeric_limits specialization");
 
 
   50    inline void add(
const ValueType &val, 
const Less &less = Less())
 
 
   57    inline const ValueType& 
min()
 const { 
return mMin; }
 
   60    inline const ValueType& 
max()
 const { 
return mMax; }
 
   63    inline void add(
const MinMax& other, 
const Less &less = Less())
 
 
   70    void print(
const std::string &name= 
"", std::ostream &strm=std::cout, 
int precision=3)
 const 
   74        std::ostringstream os;
 
   75        os << std::setprecision(precision) << std::setiosflags(std::ios::fixed);
 
   77        if (!name.empty()) os << 
"for \"" << name << 
"\" ";
 
   78        os << 
"  Min="  << 
mMin << 
", Max="  << 
mMax << std::endl;
 
 
 
  111    void add(
double val, uint64_t n)
 
 
  137    void print(
const std::string &name= 
"", std::ostream &strm=std::cout, 
int precision=3)
 const 
  141        std::ostringstream os;
 
  142        os << std::setprecision(precision) << std::setiosflags(std::ios::fixed);
 
  144        if (!name.empty()) os << 
"for \"" << name << 
"\" ";
 
  146            os << 
"with "   << 
mSize << 
" samples:\n" 
  149               << 
", Range="<< this->
range() << std::endl;
 
  151            os << 
": no samples were added." << std::endl;
 
 
 
  193        const double delta = val - 
mAvg;
 
 
  199    void add(
double val, uint64_t n)
 
  201        const double denom = 1.0/double(
mSize + n);
 
  202        const double delta = val - 
mAvg;
 
  203        mAvg += denom * delta * double(n);
 
  204        mAux += denom * delta * delta * double(
mSize) * double(n);
 
 
  211        if (other.
mSize > 0) {
 
  212            const double denom = 1.0/double(
mSize + other.
mSize);
 
  213            const double delta = other.
mAvg - 
mAvg;
 
  214            mAvg += denom * delta * double(other.
mSize);
 
 
  237    inline double std()
    const { 
return sqrt(this->
var()); }
 
  242    void print(
const std::string &name= 
"", std::ostream &strm=std::cout, 
int precision=3)
 const 
  246        std::ostringstream os;
 
  247        os << std::setprecision(precision) << std::setiosflags(std::ios::fixed);
 
  249        if (!name.empty()) os << 
"for \"" << name << 
"\" ";
 
  251            os << 
"with " << 
mSize << 
" samples:\n" 
  255               << 
", Std=" << this->
stdDev()
 
  256               << 
", Var=" << this->
variance() << std::endl;
 
  258            os << 
": no samples were added." << std::endl;
 
 
 
  281        : mSize(0), mMin(
min), mMax(
max + 1e-10),
 
  284        if ( mMax <= mMin ) {
 
  289        for (
size_t i=0; i<
numBins; ++i) mBins[i]=0;
 
 
  295        mSize(0), mMin(s.
min()), mMax(s.
max()+1e-10),
 
  298        if ( mMax <= mMin ) {
 
  303        for (
size_t i=0; i<
numBins; ++i) mBins[i]=0;
 
 
  309    inline bool add(
double val, uint64_t n = 1)
 
  311        if (val<mMin || val>mMax) 
return false;
 
  312        mBins[size_t(mDelta*(val-mMin))] += n;
 
 
  322            mBins.size() != other.mBins.size()) 
return false;
 
  323        for (
size_t i=0, e=mBins.size(); i!=e; ++i) mBins[i] += other.mBins[i];
 
  324        mSize += other.mSize;
 
 
  329    inline size_t numBins()
 const { 
return mBins.size(); }
 
  331    inline double min()
 const { 
return mMin; }
 
  333    inline double max()
 const { 
return mMax; }
 
  335    inline double min(
int n)
 const { 
return mMin+n/mDelta; }
 
  337    inline double max(
int n)
 const { 
return mMin+(n+1)/mDelta; }
 
  339    inline uint64_t 
count(
int n)
 const { 
return mBins[n]; }
 
  341    inline uint64_t 
size()
 const { 
return mSize; }
 
  344    void print(
const std::string& name = 
"", std::ostream& strm = std::cout)
 const 
  348        std::ostringstream os;
 
  349        os << std::setprecision(6) << std::setiosflags(std::ios::fixed) << std::endl;
 
  351        if (!name.empty()) os << 
"for \"" << name << 
"\" ";
 
  353            os << 
"with " << mSize << 
" samples:\n";
 
  354            os << 
"==============================================================\n";
 
  355            os << 
"||  #   |       Min      |       Max      | Frequency |  %  ||\n";
 
  356            os << 
"==============================================================\n";
 
  357            for (
int i = 0, e = 
int(mBins.size()); i != e; ++i) {
 
  358                os << 
"|| " << std::setw(4) << i << 
" | " << std::setw(14) << this->
min(i) << 
" | " 
  359                   << std::setw(14) << this->
max(i) << 
" | " << std::setw(9) << mBins[i] << 
" | " 
  360                   << std::setw(3) << (100*mBins[i]/mSize) << 
" ||\n";
 
  362            os << 
"==============================================================\n";
 
  364            os << 
": no samples were added." << std::endl;
 
 
  371    double mMin, mMax, mDelta;
 
  372    std::vector<uint64_t> mBins;
 
 
#define OPENVDB_ASSERT(X)
Definition Assert.h:41
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
Definition Exceptions.h:65
void add(double val)
Add a single sample.
Definition Stats.h:103
void add(const Extrema &other)
Add the samples from the other Stats instance.
Definition Stats.h:131
Extrema()
Constructor.
Definition Stats.h:95
double mMax
Definition Stats.h:167
uint64_t mSize
Definition Stats.h:166
double range() const
Return the range defined as the maximum value minus the minimum value.
Definition Stats.h:128
double min() const
Return the minimum value.
Definition Stats.h:122
uint64_t size() const
Return the size of the population, i.e., the total number of samples.
Definition Stats.h:119
void add(double val, uint64_t n)
Add n samples with constant value val.
Definition Stats.h:111
void join(const Extrema &other)
Definition Stats.h:158
double mMin
Definition Stats.h:167
void print(const std::string &name="", std::ostream &strm=std::cout, int precision=3) const
Print extrema to the specified output stream.
Definition Stats.h:137
double max() const
Return the maximum value.
Definition Stats.h:125
void print(const std::string &name="", std::ostream &strm=std::cout) const
Print the histogram to the specified output stream.
Definition Stats.h:344
uint64_t count(int n) const
Return the number of samples in the nth bin.
Definition Stats.h:339
bool add(double val, uint64_t n=1)
Add n samples with constant value val, provided that the val falls within this histogram's value rang...
Definition Stats.h:309
double min(int n) const
Return the minimum value in the nth bin.
Definition Stats.h:335
double min() const
Return the lower bound of this histogram's value range.
Definition Stats.h:331
uint64_t size() const
Return the population size, i.e., the total number of samples.
Definition Stats.h:341
Histogram(const Stats &s, size_t numBins=10)
Construct with the given bin count and with minimum and maximum values taken from a Stats object.
Definition Stats.h:294
double max(int n) const
Return the maximum value in the nth bin.
Definition Stats.h:337
size_t numBins() const
Return the number of bins in this histogram.
Definition Stats.h:329
bool add(const Histogram &other)
Add all the contributions from the other histogram, provided that it has the same configuration as th...
Definition Stats.h:319
double max() const
Return the upper bound of this histogram's value range.
Definition Stats.h:333
Histogram(double min, double max, size_t numBins=10)
Construct with given minimum and maximum values and the given bin count.
Definition Stats.h:280
ValueType mMin
Definition Stats.h:84
ValueType mMax
Definition Stats.h:84
const ValueType & max() const
Return the maximum value.
Definition Stats.h:60
void add(const ValueType &val, const Less &less=Less())
Add a single sample.
Definition Stats.h:50
MinMax(const ValueType &min, const ValueType &max)
Constructor.
Definition Stats.h:46
void print(const std::string &name="", std::ostream &strm=std::cout, int precision=3) const
Print MinMax to the specified output stream.
Definition Stats.h:70
MinMax()
Empty constructor.
Definition Stats.h:39
const ValueType & min() const
Return the minimum value.
Definition Stats.h:57
void add(const MinMax &other, const Less &less=Less())
Add the samples from the other Stats instance.
Definition Stats.h:63
This class computes statistics (minimum value, maximum value, mean, variance and standard deviation) ...
Definition Stats.h:180
double var() const
Return the population variance.
Definition Stats.h:230
void add(double val)
Add a single sample.
Definition Stats.h:190
double mAvg
Definition Stats.h:267
double mMax
Definition Stats.h:167
void add(const Stats &other)
Add the samples from the other Stats instance.
Definition Stats.h:209
uint64_t mSize
Definition Stats.h:166
double mean() const
Definition Stats.h:223
double variance() const
Definition Stats.h:231
void add(double val, uint64_t n)
Add n samples with constant value val.
Definition Stats.h:199
double stdDev() const
Definition Stats.h:238
double mAux
Definition Stats.h:267
double mMin
Definition Stats.h:167
double std() const
Return the standard deviation (=Sqrt(variance)) as defined from the (biased) population variance.
Definition Stats.h:237
void print(const std::string &name="", std::ostream &strm=std::cout, int precision=3) const
Print statistics to the specified output stream.
Definition Stats.h:242
double avg() const
Return the arithmetic mean, i.e. average, value.
Definition Stats.h:222
Stats()
Definition Stats.h:182
bool isApproxEqual(const Type &a, const Type &b, const Type &tolerance)
Return true if a is equal to b to within the given tolerance.
Definition Math.h:406
Definition Exceptions.h:13
#define OPENVDB_THROW(exception, message)
Definition Exceptions.h:74
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition version.h.in:121
#define OPENVDB_USE_VERSION_NAMESPACE
Definition version.h.in:218