OpenWalnut
1.5.0dev
|
Used to find the occurrence frequencies of values in a value set. More...
#include <WValueSetHistogram.h>
Public Member Functions | |
WValueSetHistogram (std::shared_ptr< WValueSetBase > valueSet, size_t buckets=1000) | |
Constructor. More... | |
WValueSetHistogram (const WValueSetBase &valueSet, size_t buckets=1000) | |
Constructor. More... | |
WValueSetHistogram (std::shared_ptr< WValueSetBase > valueSet, double min, double max, size_t buckets=1000) | |
Constructor. More... | |
WValueSetHistogram (const WValueSetBase &valueSet, double min, double max, size_t buckets=1000) | |
Constructor. More... | |
WValueSetHistogram (const WValueSetHistogram &histogram, size_t buckets=0) | |
Copy constructor. More... | |
~WValueSetHistogram () | |
Destructor. More... | |
WValueSetHistogram & | operator= (const WValueSetHistogram &other) |
Copy assignment. More... | |
virtual size_t | operator[] (size_t index) const |
Get the count of the bucket. More... | |
virtual size_t | at (size_t index) const |
Get the count of the bucket. More... | |
virtual size_t | size () const |
Returns the number of buckets in the histogram with the actual mapping. More... | |
virtual double | getBucketSize (size_t index=0) const |
Return the size of one bucket. More... | |
virtual std::pair< double, double > | getIntervalForIndex (size_t index) const |
Returns the actual interval associated with the given index. More... | |
virtual size_t | getIndexForValue (double value) const |
Returns the right index to the bucket containing the given value. More... | |
virtual size_t | getTotalElementCount () const |
This returns the number of value set entries added to the histogram. More... | |
virtual size_t | accumulate (size_t startIndex, size_t endIndex) const |
Sums up the buckets in the specified interval. 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 | operator[] (std::size_t index) const =0 |
Get the count of the specified bucket. More... | |
virtual std::size_t | at (std::size_t index) const =0 |
Get the count of the specified bucket. More... | |
virtual double | getMinimum () const |
Returns the minimum value. More... | |
virtual double | getMaximum () const |
Returns the maximum value. More... | |
virtual double | getBucketSize (std::size_t index=0) const =0 |
Return the size of one specific bucket. More... | |
virtual std::pair< double, double > | getIntervalForIndex (std::size_t index) const =0 |
Returns the actual interval associated with the given index. More... | |
Protected Member Functions | |
boost::shared_array< size_t > | getInitialBuckets () const |
Return the initial buckets. More... | |
size_t | getNInitialBuckets () const |
Return the number of initial buckets. More... | |
double | getInitialBucketSize () const |
Return the size of one initial bucket. More... | |
virtual void | insert (double value) |
increment the value by one, contains the logic to find the element place in the array. More... | |
Private Member Functions | |
void | buildHistogram (const WValueSetBase &valueSet) |
Actually builds the histogram. More... | |
Private Attributes | |
double | m_initialBucketSize |
Size of one bucket in the initial histogram. More... | |
boost::shared_array< size_t > | m_initialBuckets |
Pointer to all initial buckets of the histogram. More... | |
size_t | m_nInitialBuckets |
Number of buckets in the initial histogram. More... | |
boost::shared_array< size_t > | m_mappedBuckets |
Pointer to all initial buckets of the histogram. More... | |
size_t | m_nMappedBuckets |
Tracks the number of a buckets in the mapped histogram. More... | |
double | m_mappedBucketSize |
Size of one bucket in the mapped histogram. More... | |
size_t | m_nbTotalElements |
The number of elements distributed in the buckets. More... | |
Friends | |
class | WValueSetHistogramTest |
Only UnitTests should be friends. 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... | |
Used to find the occurrence frequencies of values in a value set.
It implements a classical histogram but allows easy modification of bucket sizes without unnecessary recalculation of the whole histogram. This histogram uses right-open intervals for counting, which is why there always is a bucket at the end from max to infinity which holds all the max values.
Definition at line 47 of file WValueSetHistogram.h.
|
explicit |
Constructor.
Creates the histogram for the specified value set.
valueSet | source of the data for the histogram |
buckets | the number of buckets to use. If not specified, 1000 is used as default. Must be larger than 1. |
Definition at line 38 of file WValueSetHistogram.cpp.
References buildHistogram().
|
explicit |
Constructor.
Creates the histogram for the specified value set.
valueSet | source of the data for the histogram |
buckets | the number of buckets to use. If not specified, 1000 is used as default. Must be larger than 1. |
Definition at line 44 of file WValueSetHistogram.cpp.
References buildHistogram().
WValueSetHistogram::WValueSetHistogram | ( | std::shared_ptr< WValueSetBase > | valueSet, |
double | min, | ||
double | max, | ||
size_t | buckets = 1000 |
||
) |
Constructor.
Creates a histogram from the specified value set but allows cropping of values below the given min and above the given max. It actually interprets all values below min and above max to be exactly min and exactly max and sorts them into the appropriate bin. This is especially useful to filter out outliers in data.
valueSet | source data |
min | the new minimum to use |
max | the maximum to use |
buckets | the number of buckets to use. If not specified, 1000 is used as default. Must be larger than 1. |
Definition at line 50 of file WValueSetHistogram.cpp.
References buildHistogram().
WValueSetHistogram::WValueSetHistogram | ( | const WValueSetBase & | valueSet, |
double | min, | ||
double | max, | ||
size_t | buckets = 1000 |
||
) |
Constructor.
Creates a histogram from the specified value set but allows cropping of values below the given min and above the given max. It actually interprets all values below min and above max to be exactly min and exactly max and sorts them into the appropriate bin. This is especially useful to filter out outliers in data.
valueSet | source data |
min | the new minimum to use |
max | the maximum to use |
buckets | the number of buckets to use. If not specified, 1000 is used as default. Must be larger than 1. |
Definition at line 56 of file WValueSetHistogram.cpp.
References buildHistogram().
WValueSetHistogram::WValueSetHistogram | ( | const WValueSetHistogram & | histogram, |
size_t | buckets = 0 |
||
) |
Copy constructor.
If another interval size is given the histogram gets matched to it using the initial bucket data.
histogram | another WValueSetHistogram |
buckets | the new number of buckets. Must be larger than 1 if specified. |
Definition at line 99 of file WValueSetHistogram.cpp.
References m_initialBuckets, m_mappedBuckets, m_mappedBucketSize, WHistogram::m_maximum, WHistogram::m_minimum, m_nInitialBuckets, and m_nMappedBuckets.
WValueSetHistogram::~WValueSetHistogram | ( | ) |
Destructor.
Definition at line 167 of file WValueSetHistogram.cpp.
|
virtual |
Sums up the buckets in the specified interval.
Especially useful for cumulative distribution functions or similar.
startIndex | the index where to start counting including this one |
endIndex | the index where to end summing up excluding this one. |
WOutOfBounds | if one of the indices is invalid. |
Definition at line 228 of file WValueSetHistogram.cpp.
References m_mappedBuckets, and size().
|
virtual |
Get the count of the bucket.
Testing if the position is valid.
index | which buckets count is to be returned; starts with 0 which is the bucket containing the smallest values. |
Definition at line 203 of file WValueSetHistogram.cpp.
References m_mappedBuckets, and m_nMappedBuckets.
|
private |
Actually builds the histogram.
This function is simply used for avoiding code duplication in all these constructors.
valueSet | the value set. |
Definition at line 62 of file WValueSetHistogram.cpp.
References WValueSetBase::getScalarDouble(), insert(), m_initialBuckets, m_initialBucketSize, m_mappedBuckets, m_mappedBucketSize, WHistogram::m_maximum, WHistogram::m_minimum, WHistogram::m_nbBuckets, m_nbTotalElements, m_nInitialBuckets, m_nMappedBuckets, and WValueSetBase::size().
Referenced by WValueSetHistogram().
|
virtual |
Return the size of one bucket.
index | the width for this bucket is queried. |
Definition at line 186 of file WValueSetHistogram.cpp.
References m_mappedBucketSize.
|
inlinevirtual |
Returns the right index to the bucket containing the given value.
If a value larger than the maximum, the maximum index is returned. Same for minimum; if the value is smaller than the minimum, 0 is returned.
value | the value to search the index for |
Definition at line 270 of file WValueSetHistogram.h.
References m_mappedBucketSize, WHistogram::m_minimum, and m_nMappedBuckets.
Referenced by insert().
|
protected |
Return the initial buckets.
Definition at line 171 of file WValueSetHistogram.cpp.
References m_initialBuckets.
|
protected |
Return the size of one initial bucket.
Definition at line 181 of file WValueSetHistogram.cpp.
References m_initialBucketSize.
|
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.
index | the intex |
Definition at line 221 of file WValueSetHistogram.cpp.
References m_mappedBucketSize, and WHistogram::m_minimum.
|
protected |
Return the number of initial buckets.
Definition at line 176 of file WValueSetHistogram.cpp.
References m_nInitialBuckets.
|
virtual |
This returns the number of value set entries added to the histogram.
This is especially useful to normalize the histogram counts.
Definition at line 216 of file WValueSetHistogram.cpp.
References m_nbTotalElements.
|
protectedvirtual |
increment the value by one, contains the logic to find the element place in the array.
Should only be used in the constructor i.e. while iterating over WValueSet.
value | value to increment |
Definition at line 192 of file WValueSetHistogram.cpp.
References getIndexForValue(), and m_mappedBuckets.
Referenced by buildHistogram().
WValueSetHistogram & WValueSetHistogram::operator= | ( | const WValueSetHistogram & | other | ) |
Copy assignment.
Copies the contents of the specified histogram to this instance.
other | the other instance |
Definition at line 148 of file WValueSetHistogram.cpp.
References m_initialBuckets, m_initialBucketSize, m_mappedBuckets, m_mappedBucketSize, WHistogram::m_maximum, WHistogram::m_minimum, m_nInitialBuckets, and m_nMappedBuckets.
|
virtual |
Get the count of the bucket.
index | which buckets count is to be returned; starts with 0 which is the bucket containing the smallest values. |
Definition at line 197 of file WValueSetHistogram.cpp.
References m_mappedBuckets.
|
virtual |
Returns the number of buckets in the histogram with the actual mapping.
Reimplemented from WHistogram.
Definition at line 211 of file WValueSetHistogram.cpp.
References m_nMappedBuckets.
Referenced by accumulate(), and WMTransferFunction1D::moduleMain().
|
friend |
Only UnitTests should be friends.
Definition at line 52 of file WValueSetHistogram.h.
|
private |
Pointer to all initial buckets of the histogram.
Definition at line 230 of file WValueSetHistogram.h.
Referenced by buildHistogram(), getInitialBuckets(), operator=(), and WValueSetHistogram().
|
private |
Size of one bucket in the initial histogram.
Definition at line 225 of file WValueSetHistogram.h.
Referenced by buildHistogram(), getInitialBucketSize(), and operator=().
|
private |
Pointer to all initial buckets of the histogram.
Definition at line 240 of file WValueSetHistogram.h.
Referenced by accumulate(), at(), buildHistogram(), insert(), operator=(), operator[](), and WValueSetHistogram().
|
private |
Size of one bucket in the mapped histogram.
Definition at line 250 of file WValueSetHistogram.h.
Referenced by buildHistogram(), getBucketSize(), getIndexForValue(), getIntervalForIndex(), operator=(), and WValueSetHistogram().
|
private |
The number of elements distributed in the buckets.
Definition at line 255 of file WValueSetHistogram.h.
Referenced by buildHistogram(), and getTotalElementCount().
|
private |
Number of buckets in the initial histogram.
Definition at line 235 of file WValueSetHistogram.h.
Referenced by buildHistogram(), getNInitialBuckets(), operator=(), and WValueSetHistogram().
|
private |
Tracks the number of a buckets in the mapped histogram.
Definition at line 245 of file WValueSetHistogram.h.
Referenced by at(), buildHistogram(), getIndexForValue(), operator=(), size(), and WValueSetHistogram().