the model of contexts of PPM, version C with exclusion, of order \( K \) on the symbols \( [ 0 , \sigma ) \)
More...
#include <ADS/compression/PPM.h>
|
| struct | Step |
| | a step of the code: the cumulative counts \( [ \mathit{low} , \mathit{high} ) \) of the symbol or of the escape, out of total More...
|
|
| | PPMModel (int order, std::uint32_t sigma=256) |
| | the model of order \( K \) = order on \( \sigma \) = sigma symbols, with no symbol seen
|
| int | order (void) const |
| | the order \( K \)
|
| std::uint32_t | sigma (void) const |
| | the size \( \sigma \) of the alphabet
|
| std::map< std::uint32_t, std::uint64_t > | counts (const std::vector< std::uint32_t > &ctx) const |
| | the counts of the symbols seen after the context ctx (the oldest symbol first), empty if ctx was never seen
|
| std::vector< Step > | steps (std::uint32_t c) const |
| | the steps that code \( c \) after the symbols seen: the escapes, then \( c \)
|
| void | encode (std::uint32_t c, RangeEncoder &e) const |
| | codes \( c \) after the symbols seen, by the steps of steps()
|
| std::uint32_t | decode (RangeDecoder &d) const |
| | the symbol coded next in \( d \), after the symbols seen, by the walk of steps() that reads in \( d \) whether each context escapes
|
| void | update (std::uint32_t c) |
| | adds \( c \) to the symbols seen
|
the model of contexts of PPM, version C with exclusion, of order \( K \) on the symbols \( [ 0 , \sigma ) \)
◆ PPMModel()
| ADS::PPMModel::PPMModel |
( |
int | order, |
|
|
std::uint32_t | sigma = 256 ) |
the model of order \( K \) = order on \( \sigma \) = sigma symbols, with no symbol seen
- Precondition
- \( K \ge 0 \), \( 1 \le \sigma \le 2^{16} \)
◆ counts()
| std::map< std::uint32_t, std::uint64_t > ADS::PPMModel::counts |
( |
const std::vector< std::uint32_t > & | ctx | ) |
const |
|
nodiscard |
the counts of the symbols seen after the context ctx (the oldest symbol first), empty if ctx was never seen
◆ decode()
| std::uint32_t ADS::PPMModel::decode |
( |
RangeDecoder & | d | ) |
const |
|
nodiscard |
the symbol coded next in \( d \), after the symbols seen, by the walk of steps() that reads in \( d \) whether each context escapes
◆ encode()
| void ADS::PPMModel::encode |
( |
std::uint32_t | c, |
|
|
RangeEncoder & | e ) const |
codes \( c \) after the symbols seen, by the steps of steps()
- Precondition
- \( c < \) sigma()
◆ order()
| int ADS::PPMModel::order |
( |
void | | ) |
const |
|
inlinenodiscard |
◆ sigma()
| std::uint32_t ADS::PPMModel::sigma |
( |
void | | ) |
const |
|
inlinenodiscard |
the size \( \sigma \) of the alphabet
◆ steps()
| std::vector< Step > ADS::PPMModel::steps |
( |
std::uint32_t | c | ) |
const |
|
nodiscard |
the steps that code \( c \) after the symbols seen: the escapes, then \( c \)
In pseudocode (chapter 12, Statistical Coding, of Ferragina's book, with the exclusion of the symbols of the longer contexts), \( h \) the last \( K \) symbols seen and \( X \) the symbols excluded:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{steps}( c ) \cr
2 & \quad X \gets \emptyset;\ P \gets ( ) \cr
3 & \quad \textbf{for}\ l \gets |h|\ \textbf{downto}\ 0\ \textbf{do} \cr
4 & \qquad \alpha \gets \text{the last } l \text{ symbols of } h;
\ A \gets \text{the symbols seen after } \alpha \text{, not in } X \cr
5 & \qquad \textbf{if}\ A = \emptyset\ \textbf{then continue} \cr
6 & \qquad N \gets \sum_{a \in A} \mathit{count}_\alpha( a ) + q_\alpha
\quad \triangleright\ q_\alpha \text{ the symbols seen after }
\alpha \cr
7 & \qquad \textbf{if}\ c \in A\ \textbf{then return}\ P \cdot (
\text{the range of } c \text{ in } A \text{, out of } N ) \cr
8 & \qquad P \gets P \cdot ( \text{the range of the escape, out of }
N );\ X \gets X \cup A \cr
9 & \quad \textbf{return}\ P \cdot ( \text{the range of } c \text{ among}
\text{ the symbols not in } X \text{, each of count } 1 )
\end{array}}
\]
- Precondition
- \( c < \) sigma()
◆ update()
| void ADS::PPMModel::update |
( |
std::uint32_t | c | ) |
|
adds \( c \) to the symbols seen
In pseudocode (chapter 12, Statistical Coding, of Ferragina's book), with the halving of the counts:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{procedure}\ \mathrm{update}( c ) \cr
2 & \quad \textbf{for}\ l \gets 0\ \textbf{to}\ |h|\ \textbf{do} \cr
3 & \qquad \alpha \gets \text{the last } l \text{ symbols of } h;
\ \mathit{count}_\alpha( c ) \gets \mathit{count}_\alpha( c ) + 1 \cr
4 & \qquad \textbf{if}\ \sum_a \mathit{count}_\alpha( a ) > 2^{16}
\ \textbf{then}\ \text{halve the counts of } \alpha
\text{, rounding up}
\cr
5 & \quad h \gets h \cdot c;\ \textbf{if}\ |h| > K\ \textbf{then}
\ \text{drop the first symbol of } h
\end{array}}
\]
- Precondition
- \( c < \) sigma()
The documentation for this class was generated from the following file: