信息论实验作业

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

实验一信息量的计算

1、基本要求:编写计算离散随机变量的熵、联合熵、条件熵、互信息的Matlab程序

2、输入:一个离散的概率分布

3、输出:信息量(单位比特)

4、函数说明:

熵e=Entropy(x)

x 是一个向量表示一个离散的概率分布

联合熵e=JEntropy(xy)

xy 联合分布密度函数

条件熵e=CEntropy(xy,sign)

xy 联合分布密度函数,sign=‘x’表示y关于x的条件概率,sign=‘y’表示x关于y 的条件概率

互信息e=IInfo(xy)

xy 联合分布密度函数%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 程序:

function e=Entropy(x)

%熵,x 是一个向量表示一个离散的概率分布

x(x==0)=1;

e=-sum(x.*log2(x)) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function e=JEntropy(xy)

%联合熵,xy 联合分布密度函数

xy(xy==0)=1;

e=-sum(sum(xy.*log2(xy))) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function e=CEntropy(xy,sign)

%条件熵. xy =联合分布密度函数,sign=‘x’表示y关于x的条件概率

x=sum(xy,2);

y=sum(xy,1);

if sign=='x'

e=JEntropy(xy)-Entropy(x);

elseif sign=='y'

e=JEntropy(xy)-Entropy(y);

else e=FALSE

end

end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function e=IInfo(xy)

% 互信息, xy 联合分布密度函数

x=sum(xy,2);

y=sum(xy,1);

e=log2(xy)-log2(x*y) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

测试结果:

>>x=[11/36 4/9 1/4]

>> Entropy(x)

e = 1.5426

>>xy=[1/4 1/18 0

1/18 1/3 1/18

0 1/18 7/36]

>> JEntropy(xy)

e = 2.4144

>> CEntropy(xy,'y')

e = 0.8717

>> e=IInfo(xy)

e = 1.4210 -1.2895 -Inf

-1.2895 0.7549 -1.0000

-Inf -1.0000 1.6374

相关文档
最新文档