16#ifndef RANS_INTERNAL_METRICS_METRICS_H_
17#define RANS_INTERNAL_METRICS_METRICS_H_
21#include <fairlogger/Logger.h>
35template <
typename source_T>
38 inline static constexpr float_t defaultCutoffPrecision = 0.999;
60 template <
typename histogram_T>
61 void init(
const histogram_T& histogram, std::optional<source_type>
min, std::optional<source_type>
max,
float_t cutoffPrecision);
63 template <
typename histogram_T>
64 void computeMetrics(
const histogram_T& histogram, std::optional<source_type>
min, std::optional<source_type>
max);
72template <
typename source_T>
73template <
typename histogram_T>
76 computeMetrics(histogram,
min,
max);
77 mCoderProperties.renormingPrecisionBits = computeRenormingPrecision(cutoffPrecision);
78 mCoderProperties.nIncompressibleSymbols = computeIncompressibleCount(mDatasetProperties.symbolLengthDistribution, *mCoderProperties.renormingPrecisionBits);
79 mCoderProperties.nIncompressibleSamples = computeIncompressibleCount(mDatasetProperties.weightedSymbolLengthDistribution, *mCoderProperties.renormingPrecisionBits);
82template <
typename source_T>
83template <
typename histogram_T>
87 using namespace utils;
88 using source_type =
typename histogram_T::source_type;
89 using value_type =
typename histogram_T::value_type;
90 static_assert(std::is_same_v<source_type, source_T>);
92 mCoderProperties.dictSizeEstimate = DictSizeEstimate{histogram.getNumSamples()};
93 if (histogram.getNumSamples() > 0) {
94 const auto [trimmedBegin, trimmedEnd] =
trim(histogram);
95 if (
min.has_value()) {
96 mDatasetProperties.min = *
min;
97 mDatasetProperties.max = *
max;
99 std::tie(mDatasetProperties.min, mDatasetProperties.max) =
getMinMax(histogram, trimmedBegin, trimmedEnd);
101 assert(mDatasetProperties.max >= mDatasetProperties.min);
102 mDatasetProperties.numSamples = histogram.getNumSamples();
103 mDatasetProperties.alphabetRangeBits = getRangeBits(mDatasetProperties.min, mDatasetProperties.max);
105 const double_t reciprocalNumSamples = 1.0 /
static_cast<double_t
>(histogram.getNumSamples());
109 forEachIndexValue(histogram, trimmedBegin, trimmedEnd, [&,
this](
const source_type&
index,
const uint32_t& frequency) {
111 assert(lastIndex <=
index);
113 mCoderProperties.dictSizeEstimate.updateIndexSize(delta + (delta == 0));
115 mCoderProperties.dictSizeEstimate.updateFreqSize(frequency);
116 ++mDatasetProperties.nUsedAlphabetSymbols;
118 const double_t probability =
static_cast<double_t
>(frequency) * reciprocalNumSamples;
119 const float_t fractionalBitLength = -fastlog2(probability);
120 const uint32_t bitLength = std::ceil(fractionalBitLength);
122 assert(bitLength > 0);
123 const uint32_t symbolDistributionBucket = bitLength - 1;
124 mDatasetProperties.entropy += probability * fractionalBitLength;
125 ++mDatasetProperties.symbolLengthDistribution[symbolDistributionBucket];
126 mDatasetProperties.weightedSymbolLengthDistribution[symbolDistributionBucket] += frequency;
132template <
typename source_T>
136 size_t incompressibleCount = 0;
137 if (renormingPrecision > 0) {
138 incompressibleCount = std::accumulate(
utils::advanceIter(distribution.data(), renormingPrecision), distribution.data() + distribution.size(), incompressibleCount);
142 incompressibleCount = 1;
144 return incompressibleCount;
147template <
typename source_T>
151 const auto& dp = this->mDatasetProperties;
153 constexpr size_t SafetyMargin = 1;
154 const size_t cutoffSamples = std::ceil(
static_cast<double_t
>(cutoffPrecision) *
155 static_cast<double_t
>(dp.numSamples));
156 size_t cumulatedSamples = 0;
158 size_t renormingBits = std::count_if(dp.weightedSymbolLengthDistribution.begin(),
159 dp.weightedSymbolLengthDistribution.end(),
160 [&cumulatedSamples, cutoffSamples](
const uint32_t& frequency) {
161 if (cumulatedSamples < cutoffSamples) {
162 cumulatedSamples += frequency;
169 if (cumulatedSamples == 0) {
178 return renormingBits;
Histogram for source symbols used to estimate symbol probabilities for entropy coding.
configStandalone Light OpenGL display display_light Apply smoothing to points Enable Z buffer Highlight links Highlight seeds Highlight sector tracks Highlight final tracks Show individual Show related Highlight grid Show only individual collision Color clusters belonging to track objects Set line Enable drawing TPC data Enable drawing TOF data Enable drawing magnetic field Set field line step count Invert colors configStandalone Heavy OpenGL display display_heavy Show tracks with ITS contribution Show tracks with TOF contribution Enable propagation of loopers Show clusters at nominal x of pad row for early transformed data Split CE tracks when they cross the central Mark clusters Mark adjacent clusters Hide rejected tracks Apply filter on tracks to be displayed Separate increase X h configStandalone Camera window renderer OpenGL display display_camera Orient the camera such that the y axis is always upwards Full Screen MultiSample Anti Downsampling Anti Enable Vertical Sync Target frame or if the backend cannot limit to the refresh Use OpenGL indirect draws to reduce number of draw calls Display h configStandalone Vulkan display display_vulkan Have uniform buffers in host accessible device memory h internal
Estimate sizes of different rANS Buffers and decide if packing should be prefered over compression.
common helper classes and functions
utility functions related to calculating different dataset metrics
helper functionalities useful for packing operations
void computeMetrics(const histogram_T &histogram, std::optional< source_type > min, std::optional< source_type > max)
CoderProperties< source_type > mCoderProperties
DatasetProperties< source_type > & getDatasetProperties() noexcept
Metrics(const SparseHistogram< source_type > &histogram, float_t cutoffPrecision=defaultCutoffPrecision)
void init(const histogram_T &histogram, std::optional< source_type > min, std::optional< source_type > max, float_t cutoffPrecision)
SizeEstimate getSizeEstimate() const noexcept
Metrics(const AdaptiveHistogram< source_type > &histogram, float_t cutoffPrecision=defaultCutoffPrecision)
Metrics(const AdaptiveHistogram< source_type > &histogram, source_type min, source_type max, float_t cutoffPrecision=defaultCutoffPrecision)
Metrics(const DenseHistogram< source_type > &histogram, source_type min, source_type max, float_t cutoffPrecision=defaultCutoffPrecision)
const DatasetProperties< source_type > & getDatasetProperties() const noexcept
CoderProperties< source_type > & getCoderProperties() noexcept
Metrics(const DenseHistogram< source_type > &histogram, float_t cutoffPrecision=defaultCutoffPrecision)
Metrics(const SparseHistogram< source_type > &histogram, source_type min, source_type max, float_t cutoffPrecision=defaultCutoffPrecision)
DatasetProperties< source_type > mDatasetProperties
const CoderProperties< source_type > & getCoderProperties() const noexcept
size_t computeIncompressibleCount(gsl::span< uint32_t > distribution, uint32_t renormingPrecision) noexcept
size_t computeRenormingPrecision(float_t cutoffPrecision) noexcept
constexpr bool isValidRenormingPrecision(size_t renormPrecision)
size_t sanitizeRenormingBitRange(size_t renormPrecision)
Freq_IT advanceIter(Freq_IT iter, std::ptrdiff_t distance)
HistogramView< Hist_IT > trim(const HistogramView< Hist_IT > &buffer)
std::pair< source_T, source_T > getMinMax(const AdaptiveSymbolTable< source_T, symbol_T > &symbolTable)
Common utility functions.
Essential properties of the dataset used for building dictionaries and coders.