首页 > 其他分享 >5.9 Shannon-Fano-Elias Coding

5.9 Shannon-Fano-Elias Coding

时间:2023-10-17 12:56:41浏览次数:33  
标签:lfloor ... frac 5.9 decimal Coding Fano overline rfloor

  • Define the modified cdf \(\overline{F}(x)\) based on the standard cdf \(F(x)\):

\[\overline{F}(x)=\sum_{a<x}p(a)+\frac{1}{2}p(x)=F(x-1)-\frac{1}{2}p(x) \]

  • Assume that \(p(x)>0\) for all \(x\in S_X\), then \(\overline{F}(a)\neq \overline{F}(b)\) if \(a\neq b\).

  • So we can determine \(x\) if we know \(\overline{F}(x)\), and we can use the value of \(\overline{F}(x)\) as a code for \(x\).

  • But, in general, \(\overline{F}(x)\) is a infinite decimal. So, we have consider using an approximate value of \(\overline{F}(x)\) and consider the required accuracy.

  • Assume that we truncate \(\overline{F}(x)\) yp \(l(x)\) bits, denoted by \(\lfloor\overline{F}(x)\rfloor_{l(x)}\), i.e. \(\lfloor 0.34\overline{8125}\rfloor_{4}=0.3481\).

  • Get some bounds:

    \[\overline{F}(x)-\lfloor\overline{F}(x)\rfloor_{l(x)} \leq \frac{1}{2^{l(x)}} \]

    it is very straightforward that \(0.34\overline{8125}-\lfloor 0.34\overline{8125}\rfloor_{4}\leq \frac{1}{10^4}\leq \frac{1}{2^4}\), and it is a very loose bound.

    Let \(l(x)=\lceil \log\frac{1}{p(x)}\rceil+1\), then

    \[\frac{1}{2^{l(x)}} < \frac{1}{2^{\log\frac{1}{p(x)}+1}}=\frac{p(x)}{2}=\overline{F}(x)-F(x-1) \]

    Combining above inequalities, we have

    \[\overline{F}(x)-\lfloor\overline{F}(x)\rfloor_{l(x)} < \overline{F}(x)-F(x-1) \]

    That is, $\lfloor\overline{F}(x)\rfloor_{l(x)} $ lies within the step corresponding to \(x\), i.e. \(\lfloor\overline{F}(x)\rfloor_{l(x)} \in (F(x-1), \overline{F}(x)]\), so \(l(x)\) bits suffice to describe \(x\).

  • Then, the code is also required to be prefix-free. The algorithm converts \(\lfloor\overline{F}(x)\rfloor_{l(x)}\) in binary, and uses the first \(l(x)\) bits after the decimal point as the codeword for \(x\).

  • The way to converts a decimal (i.e. \(0.34\overline{8125}\)) in binary:

    1. multiply this decimal by 2 (\(0.34\overline{8125}\times 2=0.69625...\))
    2. record the number before the decimal point (\(0\)), and set it to be 0 (\(0.69625...\rightarrow 0.69625...\)).
    3. multiply the new decimal by 2 (\(0.69625...\times 2=1.3925...\))
    4. record the number before the decimal point (\(1\)), and set it to be 0 (\(1.3925...\rightarrow 0.3925...\)).
    5. multiply the new decimal by 2 (\(0.3925...\times 2=0.785...\))
    6. record the number before the decimal point (\(0\)), and set it to be 0 (\(0.785...\rightarrow 0.785...\)).
    7. repeat above procedure \(l(x)\) times, the binary code is the digits we recorded (i.e. \(010...\))
  • The expected length of Shannon-Fano-Elias Code is:

    \[L=\sum_x p(x) l(x)=\sum_x p(x)(\lceil \log\frac{1}{p(x)}\rceil+1)<H(X)+2 \]

Some examples:

标签:lfloor,...,frac,5.9,decimal,Coding,Fano,overline,rfloor
From: https://www.cnblogs.com/setdong/p/17769430.html

相关文章

  • 解决OSError: cannot open resource self.font = core.getfont(font, size, index, en
    解决OSError:cannotopenresourceself.font=core.getfont(font,size,index,encoding,layout_engin在使用Python编程时,我们有时会遇到OSError:cannotopenresourceself.font=core.getfont(font,size,index,encoding,layout_engin这个错误。这个错误通常是由于缺少......
  • 鹅厂练习 13 年 Coding 后,我悟了
    点击链接了解详情导读本文主要受《程序员修炼之道:通向务实的最高境界》、《架构整洁之道》、《Unix编程艺术》启发。我不是第一个发明这些原则的人,甚至不是第一个总结出来的人,别人都已经写成书了!务实的程序员对于方法的总结,总是殊途同归。目录1细节即是架构2把代码和......
  • CODING 界面全新升级,代码仓库 Rebase 变基合并、批量复制事项等功能上线!
    点击链接了解详情金秋十月,腾讯云CODINGDevOps焕新上线!本次更新,我们不仅推出了全新的用户界面,还推出了一系列重磅产品能力,满足广大用户的日常研发与协作所需。以下是CODING新功能速递,快来看看是否有您期待已久的功能特性:01CODING界面焕新上线,“效率”+“体验”双重升......
  • VS下的Emmet技巧(HTML Coding 效率Kit)
    tag:技巧点VSCode的EmmetAbbreviation参考参考参考2生成4行p标签p*4   E.class E#id E[attr=foo] E{foo} E>N E+N E^N......
  • Go - Decoding Data with a Customized Binary Format to Structs
    Problem: Youwanttodecodethecustomizedbinaryformatbacktostructs.Solution: Usetheencoding/binarypackagetotakedatafromthebinaryformatand reconstructstructsfromit. funcmain(){vardataMeterfile,err......
  • Go - Encoding Data to a Customized Binary Format
    Problem: Youwanttoencodestructdatatoacustomizedbinaryformat.Solution: Designyourcustomizedformatandusetheencoding/binarypackagetowritedatainstructstoit. Usinggobhasacoupleofdrawbacks.First,gobissupportedbyGoonlya......
  • Go - Decoding gob Format Data to Structs
    Problem: Youwanttodecodegobformatdatabacktostructs.Solution: Usetheencoding/gobpackagetodecodethegobformatdatabacktostructs. funcread(datainterface{},filenamestring){file,err:=os.Open(&quo......
  • Go - Encoding Data to gob Format Data
    Problem: Youwanttoencodestructsintobinarygobformat.Solution: Usetheencoding/gobpackagetoencodethestructsintobytesthatcanbestoredorsentelsewhere. Theencoding/gobpackageisaGolibrarytoencodeanddecodeabinaryformat.The......
  • ​​pandas.get_dummies()​​ 是一个用于执行独热编码(One-Hot Encoding)的 pandas 函
    pandas.get_dummies()是一个用于执行独热编码(One-HotEncoding)的pandas函数。它用于将分类(或离散)特征转换为模型可以处理的二进制格式,以便更好地在机器学习算法中使用。独热编码将每个不同的类别值转换为一个新的二进制特征列,其中每个列代表一个类别,并且只有一个值为1,其余为0......
  • 玩转 CODING 自动化助手,助力高效研发!
    点击链接了解详情在日常工作中,您是否会遇到下面的情况:作为研发人员,从需求拆分出来的开发子任务完成时,还要手动修改需求为完成状态,不仅耗时还容易遗漏;作为产品经理,每天都要关注需求/任务的进展,就怕错过deadline没发现也没人通知;作为项目经理,需求/任务拆分之后,缺少各......