<
typenameTValue>
69 Uint8total_appearances_arg )
70: first_number(first_number_arg),
71last_number(last_number_arg),
72total_appearances(total_appearances_arg )
86 static_cast<int>(eHistAlgo) );
101 typedef size_tSIndexOfBin;
103 typedefpair<TValue, SIndexOfBin> TDiffAndBinPair;
104 typedefvector<TDiffAndBinPair> TVecOfDiffAndBinPair;
105TVecOfDiffAndBinPair vecOfDiffAndBinPair;
106vecOfDiffAndBinPair.reserve(pAnswer->size());
113 const SBin& this_bin = (*pAnswer)[ii];
114 const SBin& next_bin = (*pAnswer)[ii+1];
116 const TValuedifference = (
118vecOfDiffAndBinPair.push_back(
123 sort( vecOfDiffAndBinPair.begin(),
124vecOfDiffAndBinPair.end(),
125CReverseSort<TVecOfDiffAndBinPair::value_type>() );
143vector<SIndexOfBin> vecNodesThatEndRanges;
144 ITERATE(TVecOfDiffAndBinPair, map_iter,
147 if( vecNodesThatEndRanges.size() >= (num_bins - 1) ) {
150vecNodesThatEndRanges.push_back( map_iter->second );
155 sort( vecNodesThatEndRanges.begin(),
156vecNodesThatEndRanges.end() );
160SIndexOfBin bin_in_range_idx = 0;
161 ITERATE(vector<SIndexOfBin>, range_near_end_it,
162vecNodesThatEndRanges)
164 Uint8total_appearances_in_range = 0;
165 const Uint8lowest_number_in_range =
166(*pAnswer)[bin_in_range_idx].first_number;
167 for( ; bin_in_range_idx != *range_near_end_it ;
170 const SBin& bin = (*pAnswer)[bin_in_range_idx];
174total_appearances_in_range += (*pAnswer)[bin_in_range_idx].total_appearances;
175 const Uint8highest_number_in_range = (*pAnswer)[bin_in_range_idx].last_number;
176pNewAnswer->push_back(
SBin(lowest_number_in_range,
177highest_number_in_range,
178total_appearances_in_range ) );
183 Uint8total_appearances_in_range = 0;
184 const Uint8lowest_number_in_range =
185(*pAnswer)[bin_in_range_idx].first_number;
186 for( ; bin_in_range_idx != pAnswer->size(); ++bin_in_range_idx) {
187total_appearances_in_range += (*pAnswer)[bin_in_range_idx].total_appearances;
190 const Uint8highest_number_in_range = pAnswer->back().last_number;
191pNewAnswer->push_back(
SBin(lowest_number_in_range,
192highest_number_in_range,
193total_appearances_in_range ) );
214 Uint8total_num_data_points = 0;
216total_num_data_points += bin_iter->total_appearances;
220 Uint8total_data_points_remaining = total_num_data_points;
222 const SBin& current_input_bin = *this_bin_iter;
224 const Uint8num_bins_remaining = (num_bins - pNewAnswer->size() );
227 const Uint8bin_size_goal =
228( num_bins_remaining > 0 ?
229( total_data_points_remaining / num_bins_remaining ) :
233 if( pNewAnswer->empty() ) {
234pNewAnswer->push_back(current_input_bin);
235}
else if( pNewAnswer->back().total_appearances >= bin_size_goal )
237pNewAnswer->push_back(current_input_bin);
239 SBin& current_answer_bin = pNewAnswer->back();
246 _ASSERT(total_data_points_remaining == 0);
254 Uint8& out_num_bins)
const 256 _ASSERT( out_listOfBins.empty() );
263 Uint8total_appearances_of_all = 0;
267total_appearances_of_all += value_iter->second;
272 if( out_num_bins <= 0 ) {
273out_num_bins = 1 +
bm::ilog2(total_appearances_of_all);
281 const Uint8total_appearances = value_iter->second;
282out_listOfBins.push_back(
SBin(
value,
value, total_appearances) );
286 if( out_num_bins >= out_listOfBins.size() ) {
Bit manipulation primitives (internal)
Uint8 m_iNumBins
The number of bins to aim for the next time CalcHistogram is called.
EInitStatus x_InitializeHistogramAlgo(TListOfBins &out_listOfBins, Uint8 &out_num_bins) const
This holds the shared logic used by the various histogram algorithms.
vector< SBin > TListOfBins
A histogram is given as a vector of bins.
TListOfBins * CalcHistogram(EHistAlgo eHistAlgo=eHistAlgo_Default) const
Call this after data is loaded via AddNumber, etc.
TListOfBins * x_TryForEvenBins(void) const
Implementation of eHistAlgo_TryForSameNumDataInEachBin NOTE: Caller must deallocate the returned obje...
TListOfBins * x_IdentifyClusters(void) const
Implementation of eHistAlgo_IdentifyClusters NOTE: Caller must deallocate the returned object!
Int8 TValue
The numeric type this bins.
TMapValueToTotalAppearances m_mapValueToTotalAppearances
Maps a value to the number of times it appears, for the data given so far.
EInitStatus
shared by the various histogram algos
@ eInitStatus_AllAlgoWorkDone
This indicates that x_InitializeHistogramAlgo has done all the work required of it and the caller can...
@ eInitStatus_KeepGoing
This means the initialization completed, but the caller will need to do more work to shrink the numbe...
EHistAlgo
Pick which binning algorithm to use when generating the histogram.
@ eHistAlgo_TryForSameNumDataInEachBin
This algorithm tries to make each bin roughly even in size, except the last bin which may be much sma...
@ eHistAlgo_IdentifyClusters
This algorithm tries to make each bin represent values that are clustered together.
#define ITERATE_0_IDX(idx, up_to)
idx loops from 0 (inclusive) to up_to (exclusive)
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
element_type * release(void)
Release will release ownership of pointer to caller.
#define NCBI_USER_THROW_FMT(message)
Throw a "user exception" with message processed as output to ostream.
uint64_t Uint8
8-byte (64-bit) unsigned integer
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Given a set of data points, automatically put them into bins for histogram display.
T ilog2(T x) noexcept
Fast loop-less function to find LOG2.
constexpr auto sort(_Init &&init)
double value_type
The numeric datatype used by the parser.
const GenericPointer< typename T::ValueType > T2 value
Defines NCBI C++ exception handling.
Holds the information about a bin.
Uint8 total_appearances
The total number of data points in this bin for all values from first_number to last_number.
SBin(TValue first_number_arg, TValue last_number_arg, Uint8 total_appearances_arg)
TValue first_number
The start range of the bin (inclusive)
TValue last_number
The end range of the bin (inclusive)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4