📄 paper1
字号:
that the encoded string falls within the final range.Since $done_encoding( \| )$ (lines 119-123) can be sure that$low$ and $high$ are constrained by either (1a) or (1b) above, it need onlytransmit $01$ in the first case or $10$ in the second to remove the remainingambiguity.It is convenient to do this using the $bit_plus_follow( \| )$ procedurediscussed earlier.The $input_bit( \| )$ procedure will actually read a few more bits than weresent by $output_bit( \| )$ as it needs to keep the low end of the buffer full.It does not matter what value these bits have as the EOF is uniquelydetermined by the last two bits actually transmitted..sh "Models for arithmetic coding".ppThe program of Figure\ 3 must be used with a model which providesa pair of translation tables $index_to_char[ \| ]$ and $char_to_index[ \| ]$,and a cumulative frequency array $cum_freq[ \| ]$.The requirements on the latter are that.LB.NP$cum_freq[ i-1 ] ~ >= ~ cum_freq[ i ]$;.NPan attempt is never made to encode a symbol $i$ for which$cum_freq[i-1] ~=~ cum_freq[i]$;.NP$cum_freq[0] ~ <= ~ Max_frequency$..LEProvided these conditions are satisfied the values in the array need bearno relationship to the actual cumulative symbol frequencies in messages.Encoding and decoding will still work correctly, although encodings willoccupy less space if the frequencies are accurate.(Recall our successfully encoding \fIeaii!\fR according to the model ofTable\ 1, which does not actually reflect the frequencies in the message.) \c.rh "Fixed models."The simplest kind of model is one in which symbol frequencies are fixed.The first model in Figure\ 4 has symbol frequencies which approximate thoseof English (taken from a part of the Brown Corpus, Kucera & Francis, 1967)..[%A Kucera, H.%A Francis, W.N.%D 1967%T Computational analysis of present-day American English%I Brown University Press%C Providence, RI.]However, bytes which did not occur in that sample have been given frequencycounts of 1 in case they do occur in messages to be encoded(so, for example, this model will still work for binary files in which all256\ bytes occur).Frequencies have been normalized to total 8000.The initialization procedure $start_model( \| )$ simply computes a cumulativeversion of these frequencies (lines 48-51), having first initialized thetranslation tables (lines 44-47).Execution speed would be improved if these tables were used to re-ordersymbols and frequencies so that the most frequent came first in the$cum_freq[ \| ]$ array.Since the model is fixed, the procedure $update_model( \| )$, which iscalled from both $encode.c$ and $decode.c$, is null..ppAn \fIexact\fR model is one where the symbol frequencies in the message areexactly as prescribed by the model.For example, the fixed model of Figure\ 4 is close to an exact modelfor the particular excerpt of the Brown Corpus from which it was taken.To be truly exact, however, symbols that did not occur in the excerpt wouldbe assigned counts of 0, not 1 (sacrificing the capability oftransmitting messages containing those symbols).Moreover, the frequency counts would not be scaled to a predeterminedcumulative frequency, as they have been in Figure\ 4.The exact model may be calculated and transmitted before sending the message.It is shown in Cleary & Witten (1984a) that, under quite general conditions,this will \fInot\fR give better overall compression than adaptive coding,described next..[Cleary Witten 1984 enumerative adaptive codes%D 1984a.].rh "Adaptive models."An adaptive model represents the changing symbol frequencies seen \fIso far\fRin the message.Initially all counts might be the same (reflecting no initial information),but they are updated as each symbol is seen, to approximate the observedfrequencies.Provided both encoder and decoder use the same initial values (eg equalcounts) and the same updating algorithm, their models will remain in step.The encoder receives the next symbol, encodes it, and updates its model.The decoder identifies it according to its current model, and then updates itsmodel..ppThe second half of Figure\ 4 shows such an adaptive model.This is the type of model recommended for use with Figure\ 3, for in practiceit will outperform a fixed model in terms of compression efficiency.Initialization is the same as for the fixed model, except that all frequenciesare set to 1.The procedure $update_model(symbol)$ is called by both $encode_symbol( \| )$and $decode_symbol( \| )$ (Figure\ 3 lines 54 and 151) after each symbol isprocessed..ppUpdating the model is quite expensive, because of the need to maintaincumulative totals.In the code of Figure\ 4, frequency counts, which must be maintained anyway,are used to optimize access by keeping the array in frequency order \(em aneffective kind of self-organizing linear search (Hester & Hirschberg, 1985)..[Hester Hirschberg 1985.]$Update_model( \| )$ first checks to see if the new model will exceedthe cumulative-frequency limit, and if so scales all frequencies down by afactor of 2 (taking care to ensure that no count scales to zero) andrecomputes cumulative values (Figure\ 4, lines\ 29-37).Then, if necessary, $update_model( \| )$ re-orders the symbols to place thecurrent one in its correct rank in the frequency ordering, altering thetranslation tables to reflect the change.Finally, it increments the appropriate frequency count and adjusts cumulativefrequencies accordingly..sh "Performance".ppNow consider the performance of the algorithm of Figure\ 3, bothin compression efficiency and execution time..rh "Compression efficiency."In principle, when a message is coded using arithmetic coding, the number ofbits in the encoded string is the same as the entropy of that message withrespect to the model used for coding.Three factors cause performance to be worse than this in practice:.LB.NPmessage termination overhead.NPthe used of fixed-length rather than infinite-precision arithmetic.NPscaling of counts so that their total is at most $Max_frequency$..LENone of these effects is significant, as we now show.In order to isolate the effect of arithmetic coding the model will beconsidered to be exact (as defined above)..ppArithmetic coding must send extra bits at the end of each message, causing amessage termination overhead.Two bits are needed, sent by $done_encoding( \| )$ (Figure\ 3 lines 119-123),in order to disambiguate the final symbol.In cases where a bit-stream must be blocked into 8-bit characters beforeencoding, it will be necessary to round out to the end of a block.Combining these, an extra 9\ bits may be required..ppThe overhead of using fixed-length arithmeticoccurs because remainders are truncated on division.It can be assessed by comparing the algorithm's performance withthe figure obtained from a theoretical entropy calculationwhich derives its frequencies from counts scaled exactly as for coding.It is completely negligible \(em on the order of $10 sup -4$ bits/symbol..ppThe penalty paid by scaling counts is somewhat larger, but still verysmall.For short messages (less than $2 sup 14$ bytes) no scaling need be done.Even with messages of $10 sup 5$ to $10 sup 6$ bytes, the overhead was foundexperimentally to be less than 0.25% of the encoded string..ppThe adaptive model of Figure\ 4 scales down all counts whenever the totalthreatens to exceed $Max_frequency$.This has the effect of weighting recent events more heavily compared withthose earlier in the message.The statistics thus tend to track changes in the input sequence, which can bevery beneficial.(For example, we have encountered cases where limiting counts to 6 or 7\ bitsgives better results than working to higher precision.) \cOf course, this depends on the source being modeled.Bentley \fIet al\fR (1986) consider other, more explicit, ways ofincorporating a recency effect..[Bentley Sleator Tarjan Wei 1986 locally adaptive%J Communications of the ACM.].rh "Execution time."The program in Figure\ 3 has been written for clarity, not execution speed.In fact, with the adaptive model of Figure\ 4, it takes about 420\ $mu$s perinput byte on a VAX-11/780 to encode a text file, and about the same fordecoding.However, easily avoidable overheads such as procedure calls account for muchof this, and some simple optimizations increase speed by a factor of 2.The following alterations were made to the C version shown:.LB.NPthe procedures $input_bit( \| )$, $output_bit( \| )$, and$bit_plus_follow( \| )$ were converted to macros to eliminateprocedure-call overhead;.NPfrequently-used quantities were put in register variables;.NPmultiplies by two were replaced by additions (C ``+='');.NParray indexing was replaced by pointer manipulation in the loopsat line 189 of Figure\ 3 and lines 49-52 of the adaptive model in Figure\ 4..LE.ppThis mildly-optimized C implementation has an execution time of214\ $mu$s/262\ $mu$s, per input byte,for encoding/decoding 100,000\ bytes of English text on a VAX-11/780, as shownin Table\ 2.Also given are corresponding figures for the same program on anApple Macintosh and a SUN-3/75.As can be seen, coding a C source program of the same length took slightlylonger in all cases, and a binary object program longer still.The reason for this will be discussed shortly.Two artificial test files were included to allow readers to replicate theresults.``Alphabet'' consists of enough copies of the 26-letter alphabet to fillout 100,000\ characters (ending with a partially-completed alphabet).``Skew-statistics'' contains 10,000 copies of the string\fIaaaabaaaac\fR\^; it demonstrates that files may be encoded into less than1\ bit per character (output size of 12,092\ bytes = 96,736\ bits).All results quoted used the adaptive model of Figure\ 4..ppA further factor of 2 can be gained by reprogramming in assembly language.A carefully optimized version of Figures\ 3 and 4 (adaptive model) waswritten in both VAX and M68000 assembly language.Full use was made of registers.Advantage was taken of the 16-bit $code_value$ to expedite some crucialcomparisons and make subtractions of $Half$ trivial.The performance of these implementations on the test files is also shown inTable\ 2 in order to give the reader some idea of typical execution speeds..ppThe VAX-11/780 assembly language timings are broken down in Table\ 3.These figures were obtained with the U\s-2NIX\s+2 profile facility and areaccurate only to within perhaps 10%\(dg..FN\(dg This mechanism constructs a histogram of program counter values atreal-time clock interrupts, and suffers from statistical variation as well assome systematic errors..EF``Bounds calculation'' refers to the initial part of $encode_symbol( \| )$and $decode_symbol( \| )$ (Figure\ 3 lines 90-94 and 190-193)which contain multiply and divide operations.``Bit shifting'' is the major loop in both the encode and decode routines(lines 95-113 and 194-213).The $cum$ calculation in $decode_symbol( \| )$, which requires amultiply/divide, and the following loop to identify the next symbol(lines\ 187-189), is ``Symbol decode''.Finally, ``Model update'' refers to the adaptive$update_model( \| )$ procedure of Figure\ 4 (lines\ 26-53)..ppAs expected, the bounds calculation and model update take the same time forboth encoding and decoding, within experimental error.Bit shifting was quicker for the text file than for the C program and objectfile because compression performance was better.The extra time for decoding over encoding is due entirely to the symboldecode step.This takes longer in the C program and object file tests because the loop ofline\ 189 was executed more often (on average 9\ times, 13\ times, and35\ times respectively).This also affects the model update time because it is the number of cumulativecounts which must be incremented in Figure\ 4 lines\ 49-52.In the worst case, when the symbol frequencies are uniformly distributed,these loops are executed an average of 128 times.Worst-case performance would be improved by using a more complex treerepresentation for frequencies, but this would likely be slower for textfiles..sh "Some applications".ppApplications of arithmetic coding are legion.By liberating \fIcoding\fR with respect to a model from the \fImodeling\fRrequired for prediction, it encourages a whole new view of data compression(Rissanen & Langdon, 1981)..[Rissanen Langdon 1981 Universal modeling and coding.]This separation of function costs nothing in compression performance, sincearithmetic coding is (practically) optimal with respect to the entropy ofthe model.Here we intend to do no more than suggest the scope of this viewby briefly considering.LB.NPadaptive text compression.NPnon-adaptive coding.NPcompressing black/white images.NPcoding arbitrarily-distributed integers..LEOf course, as noted earlier, greater coding efficiencies could easily beachieved with more sophisticated models.Modeling, however, is an extensive topic in its own right and is beyond thescope of this paper..pp.ulAdaptive text compressionusing single-character adaptive frequencies shows off arithmetic coding togood effect.The results obtained using the program of Figures\ 3 and 4 vary from4.8\-5.3\ bit/char for short English text files ($10 sup 3$\ to $10 sup 4$bytes) to 4.5\-4.7\ bit/char for long ones ($10 sup 5$ to $10 sup 6$ bytes).Although adaptive Huffman techniques do exist (eg Gallagher, 1978;Cormack & Horspool, 1984) they lack the conceptual simplicity ofarithmetic coding..[Gallagher 1978 variations on a theme by Huffman.].[Cormack Horspool 1984 adaptive Huffman codes.]While competitive in compression efficiency for many files, they are slower.For example, Table\ 4 compares the performance of the mildly-optimized Cimplementation of arithmetic coding with that of the U\s-2NIX\s+2\fIcompact\fR program which implements adaptive Huffman coding usinga similar model\(dg..FN\(dg \fICompact\fR's model is essentially the same for long files (like thoseof Table\ 4) but is better for short files than the model used as an examplein this paper..EFCasual examination of \fIcompact\fR indicates that the care taken inoptimization is roughly comparable for both systems, yet arithmetic codinghalves execution time.Compression performance is somewhat better with arithmetic coding on all the
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -