Home | Trees | Indices | Help |
---|
|
Codec --+ | EliasGammaCodec
Encode/Decode integer according to: http://www.inference.phy.cam.ac.uk/mackay/itprnn/code/c/compress/ Integer must be >=1, unless codec is initialized with the "signed=True" FORMAT: -run of zeros of length = 1 - bits needed to encode data -data, first bit MUST be 1 -(optional) 1 bit for the sign notice, that zero cannot be encoded by this scheme. So: if data<=0: we subtract 1 before encoding (add 1 after decoding) to enable zero also, the coding most efficiently enodes, numbers close to 1 (and does one the best). The position of this optimal encoding can be adjusted by setting the "center" option. OPTIONS: 'sign' = DEFAULT=False, allow encoding data less than center? 'center' = DEFAULT=1, most efficient encoding of this integer, and lower bound if sign=False
|
|||
|
|||
|
|||
|
|||
|
>>> CA=EliasGammaCodec() >>> print CA(1), CA(4) 1 00100 >>> for x in xrange(1,100): ... if x!=CA.decode(CA(x)): print x, CA(x), CA.decode(CA(x)) >>> CA=EliasGammaCodec(sign=True) >>> print CA(1), CA(0), CA(-1) 11 10 0100 >>> for x in xrange(-100,100): ... if x!=CA.decode(CA(x)): print x, CA(x), CA.decode(CA(x)) >>> CA=EliasGammaCodec(center=10) >>> print CA(10) 1 >>> for x in xrange(10,100): ... if x!=CA.decode(CA(x)): print x, CA(x), CA.decode(CA(x)) >>> CA=EliasGammaCodec(center=10) >>> print CA(10) 1 >>> CA=EliasGammaCodec(center=10, sign=True) >>> for x in xrange(0,20): ... if x!=CA.decode(CA(x)): print x, CA(x), CA.decode(CA(x))
|
|
|
Home | Trees | Indices | Help |
---|
Generated by Epydoc 3.0beta1 on Thu Nov 8 17:49:33 2007 | http://epydoc.sourceforge.net |