|
ADS
Algorithms and Data Structures
|
The empirical entropies against which the compressors of this folder are measured. More...
Files | |
| file | ADS/compression/Entropy.h |
| The empirical entropies against which the compressors of this folder are measured. | |
Functions | |
| template<class C, class F> | |
| double | ADS::entropy (const std::map< C, F > &freq) |
| the entropy of order 0, in bits per symbol, of the distribution proportional to the frequencies \( f \) of freq | |
| double | ADS::entropy (std::string_view s) |
| the empirical entropy of order 0 of \( s \), in bits per symbol; 0 if \( s \) is empty | |
| double | ADS::entropy (std::string_view s, std::size_t k) |
| the empirical entropy of order \( k \) of \( s \), in bits per symbol; 0 if \( s \) is empty | |
The empirical entropies against which the compressors of this folder are measured.
The definitions, the invariants and the costs of the area are in Theory of compression.
|
nodiscard |
the entropy of order 0, in bits per symbol, of the distribution proportional to the frequencies \( f \) of freq
In pseudocode (Shannon's entropy, beyond the book):
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{entropy}( f ) \cr 2 & \quad N \gets \sum_\sigma f[ \sigma ];\ h \gets 0 \cr 3 & \quad \textbf{foreach}\ \sigma\ \textbf{with}\ f[ \sigma ] > 0 \ \textbf{do} \cr 4 & \qquad p \gets f[ \sigma ] / N;\ h \gets h - p \log_2 p \cr 5 & \quad \textbf{return}\ h \end{array}} \]
|
inlinenodiscard |
the empirical entropy of order 0 of \( s \), in bits per symbol; 0 if \( s \) is empty
It is the entropy above of the counts of the characters of \( s \):
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{entropy}( s ) \cr 2 & \quad \textbf{foreach}\ i \gets 0\ \textbf{to}\ |s| - 1\ \textbf{do} \ f[ s[ i ] ] \gets f[ s[ i ] ] + 1 \cr 3 & \quad \textbf{return}\ \mathrm{entropy}( f ) \end{array}} \]
|
inlinenodiscard |
the empirical entropy of order \( k \) of \( s \), in bits per symbol; 0 if \( s \) is empty
In pseudocode (Manzini's definition, beyond the book), \( f_w \) the counts of the characters that follow the context \( w \):
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{entropy}( s , k ) \cr 2 & \quad \textbf{foreach}\ i \gets k\ \textbf{to}\ |s| - 1\ \textbf{do} \cr 3 & \qquad w \gets s[ i - k .. i - 1 ];\ f_w[ s[ i ] ] \gets f_w[ s[ i ] ] + 1 \cr 4 & \quad h \gets 0 \cr 5 & \quad \textbf{foreach}\ \text{context } w \text{ met}\ \textbf{do} \ h \gets h + |f_w| \cdot \mathrm{entropy}( f_w ) \quad \triangleright\ |f_w| = \sum_c f_w[ c ] \cr 6 & \quad \textbf{return}\ h / |s| \end{array}} \]