NCBI C++ ToolKit
|
Classes | |
class | CHistogram< TValue, TScale, TCounter > |
CHistogram – collect the distribution of the numerical data samples. More... | |
class | CHistogramTimeSeries< TValue, TScale, TCounter > |
A series of same-structured histograms covering logarithmically (base 2) increasing time periods... More... | |
struct | CHistogramTimeSeries< TValue, TScale, TCounter >::STimeBin |
A histograms which covers a certain number of ticks. More... | |
Macros | |
#define | RETURN_MT_SAFE(member) |
Typedefs | |
template<typename T > | |
using | T_HistogramValueTypeHavePlus = decltype((T &)(std::declval< T >().operator+=(std::declval< const T & >()))) |
Helper types for CHistogram<>::GetSum() support. More... | |
using | CHistogram< TValue, TScale, TCounter >::TIntegral = typename std::conditional< std::numeric_limits< TValue >::is_signed, int64_t, uint64_t >::type |
Sum type: double for all floating points TValue types, int64_t/uint64_t for integral, and TValue otherwise. More... | |
using | CHistogram< TValue, TScale, TCounter >::TArithmetic = typename std::conditional< std::is_floating_point< TValue >::value, double, TIntegral >::type |
using | CHistogram< TValue, TScale, TCounter >::TSum = typename std::conditional< std::is_arithmetic< TValue >::value, TArithmetic, TValue >::type |
using | CHistogramTimeSeries< TValue, TScale, TCounter >::THistogram = CHistogram< TValue, TScale, TCounter > |
using | CHistogramTimeSeries< TValue, TScale, TCounter >::TTicks = unsigned int |
Type of the unit of time. More... | |
using | CHistogramTimeSeries< TValue, TScale, TCounter >::TTimeBins = list< STimeBin > |
Type of the series of histograms. More... | |
#define RETURN_MT_SAFE | ( | member | ) |
Definition at line 228 of file data_histogram.hpp.
using T_HistogramValueTypeHavePlus = decltype((T&)(std::declval<T>().operator+=(std::declval<const T&>()))) |
Helper types for CHistogram<>::GetSum() support.
Definition at line 65 of file data_histogram.hpp.
using CHistogram< TValue, TScale, TCounter >::TArithmetic = typename std::conditional<std::is_floating_point<TValue>::value, double, TIntegral>::type |
Definition at line 202 of file data_histogram.hpp.
using CHistogramTimeSeries< TValue, TScale, TCounter >::THistogram = CHistogram<TValue,TScale,TCounter> |
model_histogram | This histogram will be used as a template for all histogram objects in this time series. |
Definition at line 548 of file data_histogram.hpp.
using CHistogram< TValue, TScale, TCounter >::TIntegral = typename std::conditional<std::numeric_limits <TValue>::is_signed, int64_t, uint64_t >::type |
Sum type: double for all floating points TValue types, int64_t/uint64_t for integral, and TValue otherwise.
Definition at line 201 of file data_histogram.hpp.
using CHistogram< TValue, TScale, TCounter >::TSum = typename std::conditional<std::is_arithmetic <TValue>::value, TArithmetic, TValue >::type |
Definition at line 203 of file data_histogram.hpp.
using CHistogramTimeSeries< TValue, TScale, TCounter >::TTicks = unsigned int |
Type of the unit of time.
Definition at line 565 of file data_histogram.hpp.
using CHistogramTimeSeries< TValue, TScale, TCounter >::TTimeBins = list<STimeBin> |
Type of the series of histograms.
Definition at line 590 of file data_histogram.hpp.
enum CHistogram::EClone |
Enumerator | |
---|---|
eCloneAll | Clone whole histogram, with scale and counters. |
eCloneStructureOnly | Clone structure only (the counters will be zeroed) |
Definition at line 417 of file data_histogram.hpp.
enum CHistogram::EEstimateNumberOfBinsRule |
Rules to calculate an estimated numbers of bins on the base of the expected number of observations.
Note, that there is no "best" number of bins, and different bin sizes can reveal different features of the data. All these methods generally make strong assumptions about the shape of the distribution. Depending on the actual data distribution and the goals of the analysis, different bin widths may be appropriate, so experimentation is usually needed to determine an appropriate width.
Enumerator | |
---|---|
eSquareRoot | Square root rule. Used by Excel histograms and many others. Default value for EstimateNumberOfBins() as well. |
eJuran | Juran's "Quality Control Handbook" that provide guidelines to select the number of bins for histograms. |
eSturge | Herbert Sturge's rule. It works best for continuous data that is normally distributed and symmetrical. As long as your data is not skewed, using Sturge's rule should give you a nice-looking, easy to read histogram that represents the data well. |
eRice | Rice's rule. Presented as a simple alternative to Sturge's rule. |
Definition at line 361 of file data_histogram.hpp.
enum CHistogram::EScaleType |
Scale type.
Most common is a linear scale, where each bin have the same size. It is good if you have a limited range, but sometimes values are distributed very wide, and if you want to count all of them, but concentrate on a some range with most significant values, logarithmic scales helps a lot. For logarithmic scales each next bin have a greater size. Bins size increasing depends on a logarithmic base (used scale type).
Enumerator | |
---|---|
eLinear | Arithmetic or linear scale. |
eLog | Natural logarithmic scale with a base e ~ 2.72. |
eLog2 | Binary logarithmic scale with a base 2. |
eLog10 | Common logarithmic scale with a base 10. |
Definition at line 125 of file data_histogram.hpp.
enum CHistogram::EScaleView |
Methods to build bins for a specified scale.
Applies to the main scale, defined in constructor, only.
Definition at line 134 of file data_histogram.hpp.
|
inline |
Add value to the data distribution.
Try to find an appropriate bin for a specified value and increase its counter on 1. Also, calculates a sum of all added values if TValue type have addition support.
Definition at line 212 of file data_histogram.hpp.
void CHistogramTimeSeries< TValue, TScale, TCounter >::Add | ( | TValue | value | ) |
Add value to the data distribution.
Try to find an appropriate bin for a specified value and increment its counter by 1.
Definition at line 1283 of file data_histogram.hpp.
References rapidjson::value.
void CHistogram< TValue, TScale, TCounter >::AddCountersFrom | ( | const CHistogram< TValue, TScale, TCounter > & | other | ) |
Add counters from 'other' histogram to this histogram, 'other' doesn't changes.
Referenced by CPSGTimingBase::SerializeCombined().
void CHistogram< TValue, TScale, TCounter >::AddLeftScale | ( | TValue | min_value, |
unsigned | n_bins, | ||
EScaleType | scale_type | ||
) |
Add auxiliary left/right scales.
The CHistogram constructor defines a main scale for some data range. It can be very limited to get more precise results for the value distribution. You can get the number of hits whose values fall outside the range of the main scale using GetLowerAnomalyCount()/GetUpperAnomalyCount() methods, but each returns a single number of hits outside of the range. The other method is to use auxiliary scale(s) to count the number of hits for the less significant range(s). You can add any number of scales from each side. So, you can use linear scale with much greater bin sizes, or logarithmic scales, that allow to cover a very wide range of data with a limited number of bins. See EScaleType for details.
min_value | Minimum allowed value for the auxiliary scale. Its maximum value is the same as a minimum value for the main scale, or previously added scale. |
n_bins | Number of bins for the auxiliary scale. |
scale_type | Predefined scale type. Corresponding scale function will be used to calculate scale's bin ranges. |
void CHistogram< TValue, TScale, TCounter >::AddRightScale | ( | TValue | max_value, |
unsigned | n_bins, | ||
EScaleType | scale_type | ||
) |
CHistogram< TValue, TScale, TCounter >::CHistogram | ( | CHistogram< TValue, TScale, TCounter > && | other | ) |
|
protected |
Prevent copying.
See move constructor and move assignment operator to use with move-semantics.
CHistogram< TValue, TScale, TCounter >::CHistogram | ( | TValue | min_value, |
TValue | max_value, | ||
unsigned | n_bins, | ||
EScaleType | scale_type = eLinear , |
||
EScaleView | scale_view = eMonotonic |
||
) |
Constructor.
min_value | Minimum allowed value in range [min_value, max_value]. |
max_value | Maximum allowed value in range [min_value, max_value]. |
n_bins | Number of bins for the histogram (main scale). |
scale_type | Predefined scale type. Corresponding scale function will be used to calculate scale's bin ranges. |
scale_view | Scale view (symmetrical or monotonic). |
CHistogram< TValue, TScale, TCounter >::CHistogram | ( | void | ) |
CHistogramTimeSeries< TValue, TScale, TCounter >::CHistogramTimeSeries | ( | THistogram & | model_histogram | ) |
Definition at line 1273 of file data_histogram.hpp.
References CHistogramTimeSeries< TValue, TScale, TCounter >::x_AppendBin().
CHistogram CHistogram< TValue, TScale, TCounter >::Clone | ( | EClone | how = eCloneAll | ) | const |
Clone histogram structure.
Creates a copy of the histogram structure depending on clone method. By default it is a whole copy, but you can clone histogram's structure only, without counters.
Referenced by CHistogramTimeSeries< TValue, TScale, TCounter >::STimeBin::operator=(), CPSGTimingBase::SerializeCombined(), and CHistogramTimeSeries< TValue, TScale, TCounter >::x_AppendBin().
|
inline |
Add MT protection to histogram.
By default CHistogram is not MT protected and intended to be created and used withing the same thread. Calling this method add MT protection on adding additional scales, adding and resetting values, cloning and moving histograms. Please call this method immediately after creating each histogram, before accessing it from any other thread, or deadlock can occurs.
Definition at line 441 of file data_histogram.hpp.
|
static |
Estimate numbers of bins on the base of the expected number of observations 'n'.
|
constexpr |
Definition at line 69 of file data_histogram.hpp.
References rapidjson::value.
|
inline |
Get counters for the combined scale's bins.
Populate a vector with counters for the combined scale's bins. The size of the vector changes to be equal to the number of bins.
Definition at line 314 of file data_histogram.hpp.
|
inline |
Get counters for the combined scale's bins (not MT safe).
Returns a pointer to array. The number of bins can be obtained with GetNumberOfBins().
Definition at line 329 of file data_histogram.hpp.
Referenced by SerializeHistogram().
|
inline |
Get starting positions for bins on the combined scale.
Populate a vector with starting positions for bins on the combined scale. The size of the vector changes to be equal the number of bins.
Definition at line 287 of file data_histogram.hpp.
|
inline |
Get starting positions for bins on the combined scale (not MT safe).
Returns a pointer to array. The number of bins can be obtained with GetNumberOfBins(). and a number of a counters in each bin – with GetBinCounters().
Definition at line 303 of file data_histogram.hpp.
Referenced by SerializeHistogram().
|
inline |
Get total number of hits whose value fell between GetMin() and GetMax().
The number of hits whose values fall outside that range can be obtained using GetLowerAnomalyCount() and GetUpperAnomalyCount() methods.
Definition at line 335 of file data_histogram.hpp.
Referenced by SerializeHistogram().
|
inline |
Number of ticks the histogram series has handled.
Initially the number of ticks is zero.
Definition at line 597 of file data_histogram.hpp.
References CHistogramTimeSeries< TValue, TScale, TCounter >::m_CurrentTick.
CHistogramTimeSeries< TValue, TScale, TCounter >::TTimeBins CHistogramTimeSeries< TValue, TScale, TCounter >::GetHistograms |
Histograms – in the order from the most recent to the least recent.
Definition at line 1359 of file data_histogram.hpp.
|
inline |
Get number of hits whose values were less than GetMin().
Definition at line 339 of file data_histogram.hpp.
Referenced by SerializeHistogram().
|
inline |
Get the upper bound of the combined scale.
Definition at line 276 of file data_histogram.hpp.
Referenced by SerializeHistogram().
|
inline |
Get the lower bound of the combined scale.
Definition at line 273 of file data_histogram.hpp.
|
inline |
Return the number ot bins on the combined scale.
Definition at line 280 of file data_histogram.hpp.
Referenced by SerializeHistogram().
|
inline |
Return the sum of all added values.
Definition at line 252 of file data_histogram.hpp.
Referenced by SerializeHistogram().
|
inline |
Get number of hits whose values were greater than GetMax().
Definition at line 343 of file data_histogram.hpp.
Referenced by SerializeHistogram().
|
inline |
MT locking.
Definition at line 445 of file data_histogram.hpp.
Referenced by CHistogram< TValue, TScale, TCounter >::Add(), CHistogram< TValue, TScale, TCounter >::GetBinCounters(), and CHistogram< TValue, TScale, TCounter >::GetBinStarts().
|
inline |
Definition at line 449 of file data_histogram.hpp.
Referenced by CHistogram< TValue, TScale, TCounter >::Add(), CHistogram< TValue, TScale, TCounter >::GetBinCounters(), and CHistogram< TValue, TScale, TCounter >::GetBinStarts().
CHistogram& CHistogram< TValue, TScale, TCounter >::operator= | ( | CHistogram< TValue, TScale, TCounter > && | other | ) |
|
protected |
|
inline |
Definition at line 577 of file data_histogram.hpp.
References CHistogram< TValue, TScale, TCounter >::Clone(), CHistogram< TValue, TScale, TCounter >::eCloneAll, CHistogramTimeSeries< TValue, TScale, TCounter >::STimeBin::histogram, and CHistogramTimeSeries< TValue, TScale, TCounter >::STimeBin::n_ticks.
void CHistogram< TValue, TScale, TCounter >::Reset | ( | ) |
Reset all data counters.
void CHistogramTimeSeries< TValue, TScale, TCounter >::Reset | ( | void | ) |
Reset to the initial state.
Definition at line 1304 of file data_histogram.hpp.
void CHistogramTimeSeries< TValue, TScale, TCounter >::Rotate |
Merge the most recent (now active) histogram data into the time series.
This method is generally supposed to be called periodically, thus defining the unit of time (tick) as far as this API is concerned.
Definition at line 1292 of file data_histogram.hpp.
void CHistogram< TValue, TScale, TCounter >::StealCountersFrom | ( | CHistogram< TValue, TScale, TCounter > & | other | ) |
Add counters from 'other' histogram to this histogram, then reset the counters of 'other' histogram.
|
inline |
Definition at line 573 of file data_histogram.hpp.
|
inline |
Definition at line 582 of file data_histogram.hpp.
|
protected |
Add value to the data distribution (internal version without locking).
Referenced by CHistogram< TValue, TScale, TCounter >::Add().
|
protected |
Add value to the data distribution using a bisection search method.
Usually faster on a long scales with a lot of bins.
|
protected |
Add counters from 'other' histogram.
|
protected |
Add value to the data distribution using a linear search method.
Usually faster than bisection method on a small number of bins, or if the values have a tendency to fall into the starting bins for a used scale.
|
private |
Definition at line 1370 of file data_histogram.hpp.
References CHistogram< TValue, TScale, TCounter >::Clone().
Referenced by CHistogramTimeSeries< TValue, TScale, TCounter >::CHistogramTimeSeries().
|
protected |
Calculate bins starting positions.
Calculate positions for 'n' number of bins in [start,end] value range, starting from 'pos' bin index. If start_value > end_value, calculating going from the right to left. This is applicable for symmetrical scales, or multi-scales, with left scale added.
|
protected |
Calculate bins starting positions for a linear scale.
Account for an integer TScale type and calculation truncation.
|
protected |
Calculate bins starting positions for a logarithmic scale.
|
protected |
Scale function.
Calculates scale position on a base of data value.
|
protected |
Inverse scale function.
Calculates a data value on a base of scale value/position.
|
protected |
Check that 'a' and 'b' scale values are equal (or almost equal for floating scales).
|
protected |
Move data from 'other' histogram. 'other' became invalid.
|
protected |
Reset all data counters (internal version without locking).
|
private |
Definition at line 1318 of file data_histogram.hpp.
THistogram CHistogramTimeSeries< TValue, TScale, TCounter >::STimeBin::histogram |
Histogram for the ticks.
Definition at line 586 of file data_histogram.hpp.
Referenced by CHistogramTimeSeries< TValue, TScale, TCounter >::STimeBin::operator=().
|
protected |
Number of counted values (sum all m_Counters[])
Definition at line 528 of file data_histogram.hpp.
Referenced by CHistogram< TValue, TScale, TCounter >::GetCount().
|
protected |
Combined scale: counters - the number of measurements for each bin.
Definition at line 526 of file data_histogram.hpp.
Referenced by CHistogram< TValue, TScale, TCounter >::GetBinCounters(), and CHistogram< TValue, TScale, TCounter >::GetBinCountersPtr().
|
private |
Definition at line 606 of file data_histogram.hpp.
Referenced by CHistogramTimeSeries< TValue, TScale, TCounter >::GetCurrentTick().
|
protected |
MT protection flag.
Definition at line 532 of file data_histogram.hpp.
Referenced by CHistogram< TValue, TScale, TCounter >::EnableMT(), CHistogram< TValue, TScale, TCounter >::MT_Lock(), and CHistogram< TValue, TScale, TCounter >::MT_Unlock().
|
protected |
Number of anomaly values < m_Min.
Definition at line 529 of file data_histogram.hpp.
Referenced by CHistogram< TValue, TScale, TCounter >::GetLowerAnomalyCount().
|
protected |
Maximum value (the upper bound of combined scale)
Definition at line 521 of file data_histogram.hpp.
Referenced by CHistogram< TValue, TScale, TCounter >::GetMax().
|
protected |
Minimum value (the lower bound of combined scale)
Definition at line 520 of file data_histogram.hpp.
Referenced by CHistogram< TValue, TScale, TCounter >::GetMin().
|
mutableprotected |
MT protection mutex.
Definition at line 533 of file data_histogram.hpp.
Referenced by CHistogram< TValue, TScale, TCounter >::MT_Lock(), and CHistogram< TValue, TScale, TCounter >::MT_Unlock().
|
mutableprivate |
Definition at line 605 of file data_histogram.hpp.
|
protected |
Number of bins (m_Starts[]/m_Counts[] length)
Definition at line 522 of file data_histogram.hpp.
Referenced by CHistogram< TValue, TScale, TCounter >::GetBinCounters(), CHistogram< TValue, TScale, TCounter >::GetBinStarts(), and CHistogram< TValue, TScale, TCounter >::GetNumberOfBins().
|
protected |
Combined scale: starting bins positions.
Definition at line 525 of file data_histogram.hpp.
Referenced by CHistogram< TValue, TScale, TCounter >::GetBinStarts(), and CHistogram< TValue, TScale, TCounter >::GetBinStartsPtr().
|
protected |
Sum of the all added values (if applicable for TValue)
Definition at line 523 of file data_histogram.hpp.
Referenced by CHistogram< TValue, TScale, TCounter >::Add(), and CHistogram< TValue, TScale, TCounter >::GetSum().
|
private |
Definition at line 604 of file data_histogram.hpp.
|
protected |
Number of anomaly values > m_Max.
Definition at line 530 of file data_histogram.hpp.
Referenced by CHistogram< TValue, TScale, TCounter >::GetUpperAnomalyCount().
TTicks CHistogramTimeSeries< TValue, TScale, TCounter >::STimeBin::n_ticks |
Number of ticks in this histogram.
Definition at line 587 of file data_histogram.hpp.
Referenced by CHistogramTimeSeries< TValue, TScale, TCounter >::STimeBin::operator=().