FCF 2.0 development in progress...
> > > > > >
[News] [C++ Libraries API] [C++ Downloads] [Donate to the project] [Contacts]

countVector() method from fcf::NTest::HistogramBasic class

void countVector() const
void countVector(size_t a_size) const
void countVector(TItem a_min, TItem a_max) const
[STATIC] std::vector<TCounter> countVector(TItem a_min, TItem a_max, size_t a_size)

Class: fcf::NTest::HistogramBasic

Package: fcfTest

File: test.hpp

Available from version: 1.2.5

Creates a new vector of counts by redistributing values into a specified range or size.

The countVector method is a powerful tool for data re-binning and resampling.

It allows you to take the existing distribution of data and project it into a new structure, such as a different number of bins or a different numerical range. This is extremely useful for:

  • Resampling: Changing the resolution of your histogram.
  • Normalization: Mapping data from one range to another.
  • Visualization: Preparing data for different chart types with varying bin requirements.

Result
std::vector<TCounter>
- A new vector containing the redistributed counts.

Example: Resampling Data

Redistributing data from a 10-bin histogram into a 5-bin histogram.

#define FCF_TEST_IMPLEMENTATION #include <fcfTest/test.hpp> #include <iostream> FCF_TEST_DEFINE("HistogramDemo", "Basic", "ResamplingTest") { // Create a histogram with 10 bins in range [0, 100] fcf::NTest::HistogramBasic<int> hist(10, 0, 100); hist.append(10, 1); hist.append(25, 1); hist.append(50, 1); hist.append(75, 1); hist.append(90, 1); // 1. Resample the data into 5 bins instead of 10 std::vector<size_t> newCounts = hist.countVector(5); fcf::NTest::log() << "New bin count size: " << newCounts.size() << std::endl; FCF_TEST(newCounts.size() == 5); FCF_TEST(newCounts[0] + newCounts[1] + newCounts[2] + newCounts[3] + newCounts[4] == 5); } int main(int a_argc, char* a_argv[]) { bool error = false; fcf::NTest::cmdRun(a_argc, a_argv, fcf::NTest::CRM_RUN, &error); return error ? 1 : 0; }

Output:

Performing the test: "HistogramDemo" -> "Basic" -> "ResamplingTest" ... > New bin count size: 5 [SUCCESS] Test completed successfully (0.000`016`024 sec) [SUCCESS] All tests were completed. Tests: 1 passed, 0 failed, 0 skipped, 1 total Duration: 0.000`016`024 sec

The countVector method is the standard way to obtain a raw data vector for custom processing or external visualization.