Re: Efficient unbiased prefix-free encodings
- From: Ian Parker <ianparker2@xxxxxxxxx>
- Date: Wed, 12 Dec 2007 03:49:29 -0800 (PST)
On 11 Dec, 23:46, "joeship...@xxxxxxx" <JoeShip...@xxxxxxx> wrote:
I am looking for an efficient way to encode an n-letter alphabet so
that a stream of random bits will produce an unbiased stream of random
elements of {0,...,n-1}. An easy way to do this is to encode modulo
the next power of 2 greater than (a multiple of) n, then reduce modulo
n, but in the event of an "overflow" (>= the last multiple of n
available) shift left, add the next bit, and take modulo the next
power of 2 and iterate.
For example, suppose n=23 and the bit stream goes 1 1 1 0 0 1 0 ....
Proceed as follows: The successively longer binary numbers this stream
gives, in decimal, are 1, 3, 7, 14, 28, 57, 114. The first of these
which has a multiple of 23 between it and the next higher power of 2
is 114, so take 114 mod 23 and return 22. Start over with the next bit
to get the next letter. It's easy to show that the resulting stream of
letters is random and unbiased.
This requires, on average, 5.702 bits per letter in a 23-letter
alphabet, and 5.711 bits per letter in a 17-letter alphabet, etc. Can
this be done more efficiently while preserving both the "unbiased" and
"prefix-free decodable" properties? (For example, 23^21 ~
0.996*(2^95), so using 95 bits at a time to get 21 successive letters
would be close to the information-theoretic bound of log(23)/
log(2)=4.52 bits, but it doesn't work "online" and turn a stream of
bits into a stream of letters by using a prefix-free encoding).
Best way is the Huffmann codes. The general principles of which are
given in.
http://www.data-compression.com/theory.html
You take sequences of letters and encode wrt. frequency.
- Ian Parker
.
- Follow-Ups:
- Re: Efficient unbiased prefix-free encodings
- From: joeshipman@xxxxxxx
- Re: Efficient unbiased prefix-free encodings
- From: joeshipman@xxxxxxx
- Re: Efficient unbiased prefix-free encodings
- References:
- Efficient unbiased prefix-free encodings
- From: joeshipman@xxxxxxx
- Efficient unbiased prefix-free encodings
- Prev by Date: Re: Irreducible constant dimensional fibres --> irreducibility?
- Next by Date: Re: Irreducible constant dimensional fibres --> irreducibility?
- Previous by thread: Efficient unbiased prefix-free encodings
- Next by thread: Re: Efficient unbiased prefix-free encodings
- Index(es):
Relevant Pages
|
Loading