参考书《数据压缩导论(第4版)》 Page 100
5、给定如表4-9所示的概率模型,求出序列a1a1a3a2a3a1 的实值标签。
答:
由题意可得:求序列a1a1a3a2a3a1 的实值标签就是求序列113231的实值标签。
设上界 u(0) =1, 下界 l(0)=0,符号集A={a1,a2,a3},且P(a1)=0.2,P(a2)=0.3,P(a3)=0.5
由于P(x=i)=P(ai),所以P(x=1)=P(a1)=0.2,
P(x=2)= P(a2)=0.3,
P(x=3)=P(a3)=0.5.
Fx(0)=0, Fx(1)=P(a0)+ P(a1)=0.2, Fx(2)=P(a1)+ P(a2)=0.5, Fx(3)=P(a1)+ P(a2)+P(a3)=1
又由于u(k)=l(k-1)+(u(k-1)-l(k-1))*Fx(xk)
l(k)=l(k-1)+(u(k-1)-l(k-1))*Fx(xk-1)
所以结果如下:
该序列的第一个元素为1
u(1)=l(0)+(u(0)-l(0))*Fx(1)=0+(1-0)*0.2=0.2
l(1)=l(0)+(u(0)-l(0))*Fx(0)=0+(1-0)*0=0
所以该标签的区间[0,0.2)
该序列的第二个元素为1
u(2)=l(1)+(u(1)-l(1))*Fx(1)=0+(0.2-0)*0.2=0.04
l(2)=l(1)+(u(1)-l(1))*Fx(0)=0+(0.2-0)*0=0
所以序列1 1标签的区间[0,0.04)
该序列的第三个元素为3
u(3)=l(2)+(u(2)-l(2))*Fx(3)=0+(0.04-0)*1 =0.04
l(3)=l(2)+(u(2)-l(2))*Fx(2)=0+(0.04-0)*0.5=0.02
所以该序列标签的区间[0.02,0.04)
该序列的第四个元素为2
u(4)=l(3)+(u(3)-l(3))*Fx(2)=0.02+(0.04-0.02)*0.5 =0.03
l(4)=l(3)+(u(3)-l(3))*Fx(1)=0.02+(0.04-0.02)*0.2=0.024
所以序列2 3标签的区间[0.024,0.03)
该序列的第五个元素为3
u(5)=l(4)+(u(4)-l(4))*Fx(3)=0.024+(0.03-0.024)*1=0.03
l(5)=l(4)+(u(4)-l(4))*Fx(2)=0.024+(0.03-0.024)*0.5=0.027
所以该序列标签的区间[0.027,0.03)
该序列的第六个元素为1
u(6)=l(5)+(u(5)-l(5))*Fx(1)=0.027+(0.03-0.027)*0.2=0.0276
l(6)=l(5)+(u(5)-l(5))*Fx(0)=0.027+(0.03-0.027)*0=0.027
所以该序列标签的区间[0.027,0.0276)
综上可得序列a1a1a3a2a3a1 的实值标签为:
Tx(113231)= ( u(6) + l(6) )/2
=(0.0276+0.027)/2
=0.0546/2
=0.0273
6、对于表4-9所示的概率模型,对于一个标签为0.63215699的长度为10的序列进行解码。
答:
根据题意可得:
第一种方法:
#include<stdio.h> int main() { int a[10]; double t,F[100]; F[0]=0,F[1]=0.2,F[2]=0.5,F[3]=1; double l[100]={0.0},u[100]={1.0}; double tag=0.63215699; int n=10,k; for(k=1;k<=10;k++) { t=(tag-l[k-1])/(u[k-1]-l[k-1]); if(t>F[0]&&t<F[1]) { l[k]=l[k-1]+(u[k-1]-l[k-1])*F[0]; u[k]=l[k-1]+(u[k-1]-l[k-1])*F[1]; a[k]=1; } else if(t>F[1]&&t<F[2]) { l[k]=l[k-1]+(u[k-1]-l[k-1])*F[1]; u[k]=l[k-1]+(u[k-1]-l[k-1])*F[2]; a[k]=2; } else { l[k]=l[k-1]+(u[k-1]-l[k-1])*F[2]; u[k]=l[k-1]+(u[k-1]-l[k-1])*F[3]; a[k]=3; } printf("%d",a[k]); } return 0; }
调试结果如下:
综上可得:对于一个标签为0.63215699的长度为10的序列进行解码结果为:3221213223。
第二种方法:
由表4-9可得: Fx(0)=0, Fx(1)=P(a0)+ P(a1)=0.2, Fx(2)=P(a1)+ P(a2)=0.5, Fx(3)=P(a1)+ P(a2)+P(a3)=1
设上界 u(0) =1, 下界 l(0)=0
u(1)=l(0)+(u(0)-l(0))*Fx(x1)= 0+(1-0)*Fx(x1)=Fx(x1)
l(1)=l(0)+(u(0)-l(0))*Fx(x1-1)= 0+(1-0)*Fx(x1-1)=Fx(x1-1)
当x1=3时,则区间为[0.5,1),标签为0.63215699在区间为[0.5,1)内,所以满足条件;
u(2)=l(1)+(u(1)-l(1))*Fx(x2)=0.5+(1-0.5)*Fx(x2)=0.5+0.5Fx(x2)
l(2)=l(1)+(u(1)-l(1))*Fx(x2-1)=0.5+(1-0.5)*Fx(x2-1)=0.5+0.5Fx(x2-1)
当x2=2时,则区间为[0.6,0.75),标签为0.63215699在区间为[0.6,0.75)内,所以满足条件;
u(3)=l(2)+(u(2)-l(2))*Fx(x3)=0.6+(0.75-0.6)*Fx(x2)=0.6+0.15Fx(x3)
l(3)=l(32+(u(2)-l(2))*Fx(x3-1)=0.6+(0.75-0.6)*Fx(x2-1)=0.6+0.15Fx(x3-1)
当x3=2时,则区间为[0.63,0.675),标签为0.63215699在区间为[0.63,0.675)内,所以满足条件;
u(4)=l(3)+(u(3)-l(3))*Fx(x4)=0.63+(0.675-0.63)*Fx(x4)=0.63+0.045*Fx(x4)
l(4)=l(3)+(u(3)-l(3))*Fx(x4-1)=0.63+(0.675-0.63)*Fx(x4-1)=0.63+0.045*Fx(x4-1)
当x4=1时,则区间为[0.63,0.639),标签为0.63215699在区间为[0.63,0.639)内,所以满足条件;
u(5)=l(4)+(u(4)-l(4))*Fx(x5)=0.63+(0.639-0.63)*Fx(x5)=0.63+0.009*Fx(x5)
l(5)=l(4)+(u(4)-l(4))*Fx(x5-1)=0.63+(0.639-0.63)*Fx(x5-1)=0.63+0.009*Fx(x5-1)
当x5=2时,则区间为[0.6318,0.6345),标签为0.63215699在区间为[0.6318,0.6345)内,所以满足条件;
u(6)=l(5)+(u(5)-l(5))*Fx(x6)=0.6318+(0.6345-0.6318)*Fx(x6)=0.6318+0.0027*Fx(x6)
l(6)=l(5)+(u(5)-l(5))*Fx(x6-1)=0.6318+(0.6345-0.6318)*Fx(x6-1)=0.6318+0.0027*Fx(x6-1)
当x6=1时,则区间为[0.6318,0.63234),标签为0.63215699在区间为[0.6318,0.63234)内,所以满足条件;
u(7)=l(6)+(u(6)-l(6))*Fx(x7)=0.6318+(0.63234-0.6318)*Fx(x7)=0.6318+0.00054*Fx(x7)
l(7)=l(6)+(u(6)-l(6))*Fx(x7-1)=0.6318+(0.63234-0.6318)*Fx(x7-1)=0.6318+0.00054*Fx(x7-1)
当x7=3时,则区间为[0.63207,0.63234),标签为0.63215699在区间为[0.63207,0.63234)内,所以满足条件;
u(8)=l(7)+(u(7)-l(7))*Fx(x8)=0.63207+(0.63234-0.63207)*Fx(x8)=0.63207+0.00027*Fx(x8)
l(8)=l(7)+(u(7)-l(7))*Fx(x8-1)=0.63207+(0.63234-0.63207)*Fx(x8-1)=0.63207+0.00027*Fx(x8-1)
当x8=2时,则区间为[0.632124,0.632205),标签为0.63215699在区间为[0.632124,0.632205)内,所以满足条件;
u(9)=l(8)+(u(8)-l(8))*Fx(x9)=0.632124+(0.632205-0.632124)*Fx(x9)=0.632124+(8.1e-5)*Fx(x9)
l(9)=l(8)+(u(8)-l(8))*Fx(x9-1)=0.632124+(0.632205-0.632124)*Fx(x9-1)=0.632124+(8.1e-5)*Fx(x9-1)
当x9=2时,则区间为[0.6321402,0.6321645),标签为0.63215699在区间为[0.6321402,0.6321645)内,所以满足条件;
u(10)=l(9)+(u(9)-l(9))*Fx(x10)=0.6321402+(0.6321645-0.6321402)*Fx(x10)=0.6321402+(2.43e-5)*Fx(x10)
l(10)=l(9)+(u(9)-l(9))*Fx(x10-1)=0.6321402+(0.6321645-0.6321402)*Fx(x10-1)=0.6321402+(2.43e-5)*Fx(x10-1)
当x10=3时,则区间为[0.63215235,0.6321645),标签为0.63215699在区间为[0.63215235,0.6321645)内,所以满足条件。
综上可得对于一个标签为0.63215699的长度为10的序列进行解码结果为:3221213223
从今天起,做个幸福的人。