OpenWalnut  1.5.0dev
Public Member Functions | Private Attributes | List of all members
WHistogramBasic Class Reference

Container which associate values with (uniform width) bins (aka intervals or buckets). More...

#include <WHistogramBasic.h>

+ Inheritance diagram for WHistogramBasic:
+ Collaboration diagram for WHistogramBasic:

Public Member Functions

 WHistogramBasic (double min, double max, std::size_t buckets=1000)
 Default constructor. More...
 
 WHistogramBasic (const WHistogramBasic &hist)
 Copy constructor. More...
 
 ~WHistogramBasic ()
 Default destructor. More...
 
virtual std::size_t operator[] (std::size_t index) const
 Get the count of the specified bucket. More...
 
virtual std::size_t at (std::size_t index) const
 Get the count of the specified bucket. More...
 
virtual double getBucketSize (std::size_t index=0) const
 Return the size of one specific bucket. More...
 
virtual std::pair< double, double > getIntervalForIndex (std::size_t index) const
 Returns the actual interval associated with the given index. More...
 
std::size_t valuesSize () const
 Computes the number of inserted values so far. More...
 
virtual std::size_t insert (double value)
 Inserts a given value within the given range (min, max) into exactly one bin and increment its size. More...
 
- Public Member Functions inherited from WHistogram
 WHistogram (double min, double max, std::size_t buckets=1000)
 Default constructor. More...
 
 WHistogram (const WHistogram &hist)
 Copy constructor. More...
 
virtual ~WHistogram ()
 Default destructor. More...
 
virtual std::size_t size () const
 Returns the number of buckets in the histogram with the actual mapping. More...
 
virtual double getMinimum () const
 Returns the minimum value. More...
 
virtual double getMaximum () const
 Returns the maximum value. More...
 

Private Attributes

std::vector< std::size_t > m_bins
 Bins to associate with the values. More...
 
double m_intervalWidth
 The width of an interval is precomputed to save performance. More...
 

Additional Inherited Members

- Protected Attributes inherited from WHistogram
double m_minimum
 The smallest value. More...
 
double m_maximum
 The biggest value. More...
 
double m_nbBuckets
 The number of buckets. More...
 

Detailed Description

Container which associate values with (uniform width) bins (aka intervals or buckets).

This class implements a very simple and easy to use generic histogram with uniform bucket sizes.

Definition at line 39 of file WHistogramBasic.h.

Constructor & Destructor Documentation

◆ WHistogramBasic() [1/2]

WHistogramBasic::WHistogramBasic ( double  min,
double  max,
std::size_t  buckets = 1000 
)

Default constructor.

Creates an empty histogram covering the specified min and max values with the specified number of buckets.

Parameters
minthe smallest value
maxthe largest value
bucketsthe number of buckets

Definition at line 35 of file WHistogramBasic.cpp.

◆ WHistogramBasic() [2/2]

WHistogramBasic::WHistogramBasic ( const WHistogramBasic hist)

Copy constructor.

Creates a deep copy of the specified histogram.

Parameters
histthe histogram to copy.

Definition at line 42 of file WHistogramBasic.cpp.

◆ ~WHistogramBasic()

WHistogramBasic::~WHistogramBasic ( )

Default destructor.

Definition at line 50 of file WHistogramBasic.cpp.

Member Function Documentation

◆ at()

size_t WHistogramBasic::at ( std::size_t  index) const
virtual

Get the count of the specified bucket.

Testing if the position is valid.

Parameters
indexwhich buckets count is to be returned; starts with 0 which is the bucket containing the smallest values.
Returns
elements in the bucket

Implements WHistogram.

Definition at line 59 of file WHistogramBasic.cpp.

References wlog::error(), and m_bins.

+ Here is the call graph for this function:

◆ getBucketSize()

double WHistogramBasic::getBucketSize ( std::size_t  index = 0) const
virtual

Return the size of one specific bucket.

Parameters
indexthe width for this bucket is queried.
Returns
the size of a bucket.

Implements WHistogram.

Definition at line 69 of file WHistogramBasic.cpp.

References m_intervalWidth.

◆ getIntervalForIndex()

std::pair< double, double > WHistogramBasic::getIntervalForIndex ( std::size_t  index) const
virtual

Returns the actual interval associated with the given index.

The interval is open, meaning that getIntervalForIndex( i ).second == getIntervalForIndex( i + 1 ).first but does not belong anymore to the interval itself but every value smaller than getIntervalForIndex( i ).second.

Parameters
indexthe intex
Returns
the open interval.

Implements WHistogram.

Definition at line 74 of file WHistogramBasic.cpp.

References m_intervalWidth, and WHistogram::m_minimum.

◆ insert()

std::size_t WHistogramBasic::insert ( double  value)
virtual

Inserts a given value within the given range (min, max) into exactly one bin and increment its size.

Parameters
valueValue to insert.
Returns
The index of the bin the value was inserted into or the maximum size_t if it was out of range.

Definition at line 81 of file WHistogramBasic.cpp.

References wlimits::DBL_EPS, m_bins, m_intervalWidth, WHistogram::m_maximum, WHistogram::m_minimum, WHistogram::m_nbBuckets, and wlog::warn().

Referenced by WHistogramBasicTest::testInsert(), WHistogramBasicTest::testInsertAlmostMax(), WHistogramBasicTest::testInsertMax(), WHistogramBasicTest::testInsertMin(), WHistogramBasicTest::testInsertOnIntervalBorder(), WHistogramBasicTest::testInsertOutOfBounds(), and WHistogramBasicTest::testOperatorToGetNumberOfElementsInsideTheBin().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator[]()

size_t WHistogramBasic::operator[] ( std::size_t  index) const
virtual

Get the count of the specified bucket.

Parameters
indexwhich buckets count is to be returned; starts with 0 which is the bucket containing the smallest values.
Returns
elements in the bucket.

Implements WHistogram.

Definition at line 54 of file WHistogramBasic.cpp.

References m_bins.

◆ valuesSize()

size_t WHistogramBasic::valuesSize ( ) const

Computes the number of inserted values so far.

Returns
Number of values so far.

Definition at line 106 of file WHistogramBasic.cpp.

References m_bins.

Referenced by WHistogramBasicTest::testInitialization(), WHistogramBasicTest::testInsert(), and WHistogramBasicTest::testOperatorToGetNumberOfElementsInsideTheBin().

+ Here is the caller graph for this function:

Member Data Documentation

◆ m_bins

std::vector< std::size_t > WHistogramBasic::m_bins
private

Bins to associate with the values.

Each bin has the width of m_intervalWidth;

Definition at line 122 of file WHistogramBasic.h.

Referenced by at(), insert(), operator[](), and valuesSize().

◆ m_intervalWidth

double WHistogramBasic::m_intervalWidth
private

The width of an interval is precomputed to save performance.

Definition at line 127 of file WHistogramBasic.h.

Referenced by getBucketSize(), getIntervalForIndex(), and insert().


The documentation for this class was generated from the following files: