📄 example8_1_to_8_3.m
字号:
%Huffman coding example
%ch7-huffman.m
Q=[ 0.6250 0.3750 0.3750 0.3750
0.1875 0.3125 0.1875 0.1875
0.1250 0.1875 0.3125 0.1250
0.0625 0.1250 0.1250 0.3125]
%Q(i,j) is prob(i|j)
%use [W,D]=eig(A) to determine the eigenvector corresponding to eigen value 1
%then normalize the vector to sum 1
p =[
0.5000
0.2143
0.1703
0.1154]
%p(i)=prob(i);
P2=Q*diag(p);
%P2(i,j)=prob(i,j);
%P2 =
% 0.3125 0.0804 0.0639 0.0433
% 0.0937 0.0670 0.0319 0.0216
% 0.0625 0.0402 0.0532 0.0144
% 0.0312 0.0268 0.0213 0.0361
%first order entropy
H1=-sum(p.*log2(p));
%H1=1.7707
%2nd order entropy;
H2=-sum(sum(P2.*log2(P2)));
%H2=3.4629; H2/2=1.73145
%conditional entropy
for (j=1:4)
HC(j)=-sum(Q(:,j).*log2(Q(:,j)));
end;
%HC= 1.5016 1.8829 1.8829 1.8829
HCT=sum(p'.*HC);
%HCT=1.6922
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -