ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
Entropy.h File Reference

The empirical entropies against which the compressors of this folder are measured. More...

#include "ADS/Contract.h"
#include <cmath>
#include <cstddef>
#include <map>
#include <string>
#include <string_view>
#include "ADS/compression/impl/Entropy.tpp"

Go to the source code of this file.

Namespaces

namespace  ADS

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

Detailed description

The empirical entropies against which the compressors of this folder are measured.

The entropy of order 0 of a distribution \( P \) on an alphabet \( \Sigma \) is \( H_0 = \sum_{\sigma \in \Sigma} P[ \sigma ] \log_2( 1 / P[ \sigma ] ) \) bits per symbol, and that of a string \( s \) takes \( P[ \sigma ] = n_\sigma / |s| \), with \( n_\sigma \) the number of occurrences of \( \sigma \) in \( s \); it bounds from below the average length of a prefix-free code (Shannon), and the code of Huffman stays within one bit of it, \( H_0 \le \bar\ell < H_0 + 1 \) [see CanonicalHuffman.h], while the arithmetic code of \( s \) takes at most \( 2 + |s| H_0 \) bits [see ArithmeticCoding.h]. The entropy of order \( k \) of \( s \) is \( H_k( s ) = \frac{1}{|s|} \sum_{w \in \Sigma^k} |w_s| H_0( w_s ) \), where \( w_s \) is the string of the symbols that follow the occurrences of \( w \) in \( s \), in their order; one has \( H_k \le H_0 \), and \( H_k \) is the measure reached by the models of context [see PPM.h] and by the compressors built on the Burrows-Wheeler transform [see BurrowsWheeler.h]. Each function takes \( O( |s| \log |s| ) \) time, the counts being kept in ordered maps.

The contracts [see Contract.h]: the frequencies are not negative and not all 0, and \( H_k( s ) \le H_0( s ) \) is checked on the result. The functions are defined in Entropy.tpp.

See also
P. Ferragina, Pearls of Algorithm Engineering, Cambridge University Press, 2023, chapters 12, Statistical Coding, and 14, Block-Sorting Compression, doi:10.1017/9781009128933
C. E. Shannon, A mathematical theory of communication, Bell System Technical Journal 27(3), 379-423, 1948, doi:10.1002/j.1538-7305.1948.tb01338.x
G. Manzini, An analysis of the Burrows-Wheeler transform, Journal of the ACM 48(3), 407-430, 2001, doi:10.1145/382780.382782
Author
Donato Meoli
Dipartimento di Informatica
Università di Pisa