Move constructor.Move 'other' histogram data to the current object. 'other' became invalid.
#ifndef DATA_HISTOGRAM__HPP
#define DATA_HISTOGRAM__HPP
#define _USE_MATH_DEFINES
#include <math.h>
#include <cmath>
#include <memory>
#include <mutex>
template <typename T>
template <typename T>
{
}
template <typename TValue = int, typename TScale = TValue, typename TCounter = Uint8>
{
public:
};
};
template <
typename V,
typename S =
TSum,
std::enable_if_t<g_HistogramValueTypeHavePlus<S>(), int> = 0>
}
template <
typename V,
typename S =
TSum,
std::enable_if_t<!g_HistogramValueTypeHavePlus<S>(), int> = 0>
}
#define RETURN_MT_SAFE(member) \
if (m_IsMT) { \
MT_Lock(); \
auto v = member; \
MT_Unlock(); \
return v; \
} \
return member
}
}
};
};
};
}
}
protected:
unsigned pos,
unsigned n,
TScale start_value, TScale
end_value, TScale step,
TScale*
arr,
unsigned pos,
unsigned n,
TScale*
arr,
unsigned pos,
unsigned n,
protected:
};
template <typename TValue, typename TScale, typename TCounter>
{
public:
struct STimeBin {
{}
{
}
{}
};
private:
void x_Shift(
size_t index,
typename TTimeBins::iterator current_it);
private:
};
template <typename TValue, typename TScale, typename TCounter>
(
TValue max_value,
unsigned n_bins,
EScaleView scale_view
)
: m_Min(
min_value), m_Max(max_value), m_NumBins(n_bins), m_IsMT(
false)
{
if ( m_Min > m_Max ) {
}
if ( !m_NumBins ) {
}
m_Starts.reset(new TScale[m_NumBins]);
m_Counters.reset(new TCounter[m_NumBins]);
x_CalculateBins(m_Min, m_Max, 0, m_NumBins, scale_type, scale_view);
x_Reset();
}
template <typename TValue, typename TScale, typename TCounter>
void
{
}
if ( !n_bins ) {
}
}
std::unique_ptr<TScale[]> tmp_starts(
new TScale[
m_NumBins]);
memcpy(tmp_starts.get() + n_bins,
m_Starts.get(),
sizeof(TScale) * n_prev);
}
template <typename TValue, typename TScale, typename TCounter>
void
TValue max_value,
unsigned n_bins,
EScaleType scale_type)
{
if ( max_value <=
m_Max ) {
}
if ( !n_bins ) {
}
}
std::unique_ptr<TScale[]> tmp_starts(
new TScale[
m_NumBins]);
memcpy(tmp_starts.get(),
m_Starts.get(),
sizeof(TScale) * n_prev);
}
template <typename TValue, typename TScale, typename TCounter>
unsigned
{
switch (rule) {
return (
unsigned) ceil(sqrt(
n));
if (
n <= 1000)
return 10;
return 11;
return 1 + (unsigned) ceil(
log2(
n));
return (
unsigned) ceil(pow(
n,
double(1)/3));
}
return 0;
}
template <typename TValue, typename TScale, typename TCounter>
void
{
}
template <typename TValue, typename TScale, typename TCounter>
void
{
}
template <typename TValue, typename TScale, typename TCounter>
void
{
return;
}
return;
}
return;
}
}
template <typename TValue, typename TScale, typename TCounter>
void
{
break;
}
}
}
template <typename TValue, typename TScale, typename TCounter>
void
{
while (d = (right - left), d > 1) {
} else {
}
}
}
}
template <typename TValue, typename TScale, typename TCounter>
void
(
TScale start_value,
unsigned pos,
EScaleView scale_view
)
{
const char* errmsg_step = "Impossible to calculate scale step, please change TScale type, range, or number of bins";
const char* errmsg_dup = "Impossible to calculate scales bin starting position, please change TScale type, range, or number of bins";
if ( step == 0 ) {
}
return;
}
}
}
return;
}
template <typename TValue, typename TScale, typename TCounter>
void
(
TScale start_value,
TScale step,
unsigned pos,
EScaleView scale_view
)
{
TScale median = start_value + (
end_value - start_value)/2;
} else {
}
return;
}
for (
unsigned i = 0;
i <
n;
i++) {
arr[pos+
i] = start_value + step*
i;
}
}
else {
for (
unsigned i = 1;
i <=
n;
i++) {
arr[pos+1-
i] = start_value - step*
i;
}
}
}
template <typename TValue, typename TScale, typename TCounter>
void
(
TScale start_value,
unsigned pos,
EScaleView scale_view
)
{
TScale median = start_value + (
end_value - start_value)/2;
} else {
return;
}
std::unique_ptr<TScale[]>
tmp(
new TScale[
n*2]);
TScale* tmp_arr =
tmp.get();
arr[pos + n2] = tmp_arr[
n - 1];
arr[pos + n2 + 1] = tmp_arr[
n + 1];
for (
unsigned i = 0;
i < n2;
i++) {
arr[pos +
i] = tmp_arr[
i*2];
}
for (
unsigned i=2, j=
n+3;
i <= n2;
i++, j+=2) {
arr[pos + n2 +
i] = tmp_arr[j];
}
}
return;
}
for (
unsigned i = 1;
i <
n;
i++) {
}
}
else {
for (
unsigned i = 1;
i <
n;
i++) {
}
}
}
template <typename TValue, typename TScale, typename TCounter>
TScale
{
switch (scale_type) {
}
}
template <typename TValue, typename TScale, typename TCounter>
TScale
{
switch (scale_type) {
return (TScale)pow(M_E, scale_value);
return (TScale)pow(2, scale_value);
return (TScale)pow(10, scale_value);
return scale_value;
}
return scale_value;
}
template <typename TValue, typename TScale, typename TCounter>
: m_NumBins(0), m_IsMT(
false)
{
x_Reset();
}
template <typename TValue, typename TScale, typename TCounter>
{
if (this == &other) return;
other.MT_Lock();
other.MT_Unlock();
};
template <typename TValue, typename TScale, typename TCounter>
{
if (this == &other) return *this;
other.MT_Unlock();
return *this;
};
template <typename TValue, typename TScale, typename TCounter>
{
switch (how) {
break;
break;
default:
}
return h;
}
template <typename TValue, typename TScale, typename TCounter>
void
{
return;
}
template <typename TValue, typename TScale, typename TCounter>
bool
{
if (std::numeric_limits<TScale>::is_integer) {
}
}
template <typename TValue, typename TScale, typename TCounter>
void
{
if (this == &other) return;
try {
}
catch (...) {
throw;
}
}
template <typename TValue, typename TScale, typename TCounter>
void
{
if (this == &other) return;
try {
}
catch (...) {
throw;
}
}
template <typename TValue, typename TScale, typename TCounter>
void
{
) {
}
TScale* starts_other = other.
m_Starts.get();
}
}
TCounter* counters_other = other.
m_Counters.get();
counters_cur[
i] += counters_other[
i];
}
}
template <typename TValue, typename TScale, typename TCounter>
: m_CurrentTick(0)
{
x_AppendBin(model_histogram, 1);
}
template <typename TValue, typename TScale, typename TCounter>
void
{
m_TimeBins.front().histogram.Add(
value);
}
template <typename TValue, typename TScale, typename TCounter>
void
{
++m_CurrentTick;
m_Mutex.lock();
x_Shift(0, m_TimeBins.begin());
m_Mutex.unlock();
}
template <typename TValue, typename TScale, typename TCounter>
void
{
m_Mutex.lock();
m_CurrentTick = 0;
while (m_TimeBins.size() > 1)
m_TimeBins.pop_back();
m_TimeBins.front().histogram.Reset();
m_TimeBins.front().n_ticks = 1;
m_Mutex.unlock();
}
template <typename TValue, typename TScale, typename TCounter>
void
typename ncbi::CHistogramTimeSeries<TValue, TScale, TCounter>::TTimeBins::iterator current_it)
{
if (m_TimeBins.size() <= index + 1) {
x_AppendBin(m_TimeBins.front().histogram, TTicks(1) << index);
auto next_it = current_it;
++next_it;
next_it->histogram.StealCountersFrom(current_it->histogram);
if (index != 0)
current_it->n_ticks /= 2;
return;
}
auto next_it = current_it;
++next_it;
if (next_it->n_ticks == TTicks(1) << index) {
next_it->n_ticks *= 2;
next_it->histogram.StealCountersFrom(current_it->histogram);
if (index != 0)
current_it->n_ticks /= 2;
return;
}
x_Shift(index + 1, next_it);
next_it->histogram.StealCountersFrom(current_it->histogram);
if (index != 0)
current_it->n_ticks /= 2;
}
template <typename TValue, typename TScale, typename TCounter>
{
m_Mutex.lock();
TTimeBins ret = m_TimeBins;
m_Mutex.unlock();
return ret;
}
template <typename TValue, typename TScale, typename TCounter>
void
const THistogram& model_histogram, TTicks n_ticks)
{
m_TimeBins.push_back(
STimeBin{model_histogram.Clone(THistogram::eCloneStructureOnly),
n_ticks} );
}
#endif
A series of same-structured histograms covering logarithmically (base 2) increasing time periods....
CHistogram – collect the distribution of the numerical data samples.
Include a standard set of the NCBI C++ Toolkit most basic headers.
static vector< string > arr
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
unsigned GetNumberOfBins() const
Return the number ot bins on the combined scale.
void x_AddCountersFrom(CHistogram &other)
Add counters from 'other' histogram.
TCounter m_UpperAnomalyCount
Number of anomaly values > m_Max.
EEstimateNumberOfBinsRule
Rules to calculate an estimated numbers of bins on the base of the expected number of observations.
std::unique_ptr< TCounter[]> m_Counters
Combined scale: counters - the number of measurements for each bin.
unsigned int TTicks
Type of the unit of time.
typename std::conditional< std::is_floating_point< TValue >::value, double, TIntegral >::type TArithmetic
void x_AddBisection(TValue value)
Add value to the data distribution using a bisection search method.
void x_AppendBin(const THistogram &model_histogram, TTicks n_ticks)
void MT_Lock() const
MT locking.
void x_CalculateBinsLog(TScale start_value, TScale end_value, TScale *arr, unsigned pos, unsigned n, EScaleType scale_type, EScaleView scale_view)
Calculate bins starting positions for a logarithmic scale.
TCounter m_LowerAnomalyCount
Number of anomaly values < m_Min.
CHistogram Clone(EClone how=eCloneAll) const
Clone histogram structure.
void x_Add(TValue value)
Add value to the data distribution (internal version without locking).
TSum m_Sum
Sum of the all added values (if applicable for TValue)
THistogram histogram
Histogram for the ticks.
TTicks GetCurrentTick(void) const
Number of ticks the histogram series has handled.
list< STimeBin > TTimeBins
Type of the series of histograms.
TSum GetSum(void) const
Return the sum of all added values.
TCounter m_Count
Number of counted values (sum all m_Counters[])
void x_CalculateBinsLinear(TScale start_value, TScale end_value, TScale step, TScale *arr, unsigned pos, unsigned n, EScaleView scale_view)
Calculate bins starting positions for a linear scale.
size_t GetLowerAnomalyCount() const
Get number of hits whose values were less than GetMin().
TValue GetMin() const
Get the lower bound of the combined scale.
typename std::conditional< std::is_arithmetic< TValue >::value, TArithmetic, TValue >::type TSum
std::mutex m_Mutex
MT protection mutex.
TScale x_FuncInverse(EScaleType scale_type, TScale scale_value)
Inverse scale function.
void AddCountersFrom(const CHistogram &other)
Add counters from 'other' histogram to this histogram, 'other' doesn't changes.
void GetBinCounters(vector< TCounter > &counters)
Get counters for the combined scale's bins.
void x_CalculateBins(TScale start_value, TScale end_value, unsigned pos, unsigned n, EScaleType scale_type, EScaleView scale_view)
Calculate bins starting positions.
void EnableMT(void)
Add MT protection to histogram.
TValue m_Max
Maximum value (the upper bound of combined scale)
const TScale * GetBinStartsPtr() const
Get starting positions for bins on the combined scale (not MT safe).
bool x_IsEqual(TScale a, TScale b)
Check that 'a' and 'b' scale values are equal (or almost equal for floating scales).
TValue GetMax() const
Get the upper bound of the combined scale.
TValue m_Min
Minimum value (the lower bound of combined scale)
CHistogram & operator=(CHistogram &&other)
TScale x_Func(EScaleType scale_type, TScale value)
Scale function.
void x_AddLinear(TValue value)
Add value to the data distribution using a linear search method.
STimeBin & operator=(const STimeBin &other)
constexpr bool g_HistogramValueTypeHavePlus()
unsigned m_NumBins
Number of bins (m_Starts[]/m_Counts[] length)
void Add(TValue value)
Add value to the data distribution.
void x_MoveFrom(CHistogram &other)
Move data from 'other' histogram. 'other' became invalid.
void AddLeftScale(TValue min_value, unsigned n_bins, EScaleType scale_type)
Add auxiliary left/right scales.
typename std::conditional< std::numeric_limits< TValue >::is_signed, int64_t, uint64_t >::type TIntegral
Sum type: double for all floating points TValue types, int64_t/uint64_t for integral,...
const TCounter * GetBinCountersPtr() const
Get counters for the combined scale's bins (not MT safe).
void Add(const V &v)
Add value to the data distribution.
std::unique_ptr< TScale[]> m_Starts
Combined scale: starting bins positions.
TCounter GetCount() const
Get total number of hits whose value fell between GetMin() and GetMax().
CHistogram(void)
Default constructor.
size_t GetUpperAnomalyCount() const
Get number of hits whose values were greater than GetMax().
void Rotate()
Merge the most recent (now active) histogram data into the time series.
STimeBin(const STimeBin &other)
CHistogram< TValue, TScale, TCounter > THistogram
void x_Shift(size_t index, typename TTimeBins::iterator current_it)
static unsigned EstimateNumberOfBins(size_t n, EEstimateNumberOfBinsRule rule=0)
Estimate numbers of bins on the base of the expected number of observations 'n'.
EScaleView
Methods to build bins for a specified scale.
#define RETURN_MT_SAFE(member)
void Reset()
Reset to the initial state.
CHistogramTimeSeries(THistogram &model_histogram)
void Reset()
Reset all data counters.
bool m_IsMT
MT protection flag.
decltype((T &)(std::declval< T >().operator+=(std::declval< const T & >()))) T_HistogramValueTypeHavePlus
Helper types for CHistogram<>::GetSum() support.
void GetBinStarts(vector< TScale > &positions)
Get starting positions for bins on the combined scale.
void StealCountersFrom(CHistogram &other)
Add counters from 'other' histogram to this histogram, then reset the counters of 'other' histogram.
void x_Reset()
Reset all data counters (internal version without locking).
TTicks n_ticks
Number of ticks in this histogram.
TTimeBins GetHistograms() const
Histograms – in the order from the most recent to the least recent.
void AddRightScale(TValue max_value, unsigned n_bins, EScaleType scale_type)
@ eJuran
Juran's "Quality Control Handbook" that provide guidelines to select the number of bins for histogram...
@ eRice
Rice's rule. Presented as a simple alternative to Sturge's rule.
@ eSquareRoot
Square root rule.
@ eSturge
Herbert Sturge's rule.
@ eLog2
Binary logarithmic scale with a base 2.
@ eLog10
Common logarithmic scale with a base 10.
@ eLog
Natural logarithmic scale with a base e ~ 2.72.
@ eLinear
Arithmetic or linear scale.
@ eCloneStructureOnly
Clone structure only (the counters will be zeroed)
@ eCloneAll
Clone whole histogram, with scale and counters.
@ eMonotonic
Use specified scale method to calculate bins sizes from a minimum to a maximum value.
@ eSymmetrical
Determine a mean for a specified value range and calculates bins sizes using specified scale to both ...
unsigned int
A callback function used to compare two keys in a database.
const GenericPointer< typename T::ValueType > T2 value
The NCBI C++/STL use hints.
Helper template to check that type Type have some method declared using TypeChecker<Type>.