For a discrete memoryless channel , the capacity is defined as

where  and  denote the input and output variables of the channel respectively, and the maximization is taken over all input distributions .

Given a channel transition matrix whose -entry is the conditional probability , the Blahut-Arimoto algorithm computes the capacity of the discrete memoryless channel, and the input distribution  that attains the maximum.

Reference: Chapter 9 in the book Information Theory and Network Coding by Raymond Yeung.

function [C r] = BlahutArimoto(p)

disp('BlahutArimoto')

% Capacity of discrete memoryless channel
% Blahut-Arimoto algorithm % Input
% p: m x n matrix
% p is the transition matrix for a channel with m inputs and n outputs
%
% The input matrix p should contain no zero row and no zero column.
%
% p(i,j) is the condition probability that the channel output
% is j given that the input is i
% (i=1,2,...,m and j = 1,2,...,n)
%
%
% Output
% capacity : capacity in bits
% r: channel input distribution which achieves capacity
% % For example, the transition matrix for the erasure channel is
% can be calculated as
% e = 0.5;
% p = [1-e e 0; 0 e 1-e]; % conditional prob. for erasure channel
% The capacity can be calculated by BlahutArimoto(p), and is equal to 1-e
% % Check that the entries of input matrix p are non-negative
if ~isempty(find(p < 0))
disp('Error: some entry in the input matrix is negative')
C = 0; return;
end % Check that the input matrix p does not have zero column
column_sum = sum(p);
if ~isempty(find(column_sum == 0))
disp('Error: there is a zero column in the input matrix');
C = 0; return;
end % Check that the input matrix p does not have zero row
row_sum = sum(p,2);
if ~isempty(find(row_sum == 0))
disp('Error: there is a zero row in the input matrix');
C = 0; return;
else
p = diag(sum(p,2))^(-1) * p; % Make sure that the row sums are 1
end [m n] = size(p); r = ones(1,m)/m; % initial distribution for channel input
q = zeros(m,n);
error_tolerance = 1e-5/m;
r1 = [];
for i = 1:m
p(i,:) = p(i,:)/sum(p(i,:));
end
for iter = 1:10000
for j = 1:n
q(:,j) = r'.*p(:,j);
q(:,j) = q(:,j)/sum(q(:,j));
end for i = 1:m
r1(i) = prod(q(i,:).^p(i,:));
end r1 = r1/sum(r1);
if norm(r1 - r) < error_tolerance
break
else
r = r1;
end
end C = 0;
for i = 1:m
for j = 1:n
if r(i) > 0 && q(i,j) > 0
C = C+ r(i)*p(i,j)* log(q(i,j)/r(i));
end
end
end C = C/log(2); % Capacity in bits

Blahut-Arimoto algorithm Matlab源码的更多相关文章

  1. GWO(灰狼优化)算法MATLAB源码逐行中文注解(转载)

    以优化SVM算法的参数c和g为例,对GWO算法MATLAB源码进行了逐行中文注解. tic % 计时器 %% 清空环境变量 close all clear clc format compact %% ...

  2. 层次分析法、模糊综合评测法实例分析(涵盖各个过程讲解、原创实例示范、MATLAB源码公布)

    目录 一.先定个小目标 二.层次分析法部分 2.1 思路总括 2.2 构造两两比较矩阵 2.3 权重计算方法 2.3.1 算术平均法求权重 2.3.2 几何平均法求权重 2.3.3 特征值法求权重 2 ...

  3. Bag of Words/Bag of Features的Matlab源码发布

    2010年11月19日 ⁄ 技术, 科研 ⁄ 共 1296字 ⁄ 评论数 26 ⁄ 被围观 4,150 阅读+ 由于自己以前发过一篇文章讲bow特征的matlab代码的优化的<Bag-Of-Wo ...

  4. 群智能优化算法-测试函数matlab源码

    群智能优化算法测试函数matlab源代码 global M; creatematrix(2); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %画ackley图. %%%% ...

  5. 非线性回归支持向量机——MATLAB源码

    支持向量机和神经网络都可以用来做非线性回归拟合,但它们的原理是不相同的,支持向量机基于结构风险最小化理论,普遍认为其泛化能力要比神经网络的强.大量仿真证实,支持向量机的泛化能力强于神经网络,而且能避免 ...

  6. 红外图像处理之直方图均衡的matlab源码与效果验证

    红外图像是热辐射成像,由于场景中的目标与背景的温差相对较小,红外图像的动态范围大.对比度 低, 信噪比也较可见光图像的低.为了能够从红外图像中正确地识别出目标,必须对红外图像进行增强处理.一般红外探测 ...

  7. 偏微分方程数值解法的MATLAB源码

    原文出处http://wenku.baidu.com/view/df412e115f0e7cd184253653.html 因为不太喜欢百度文库的格式,所以写到个人博客里面方便使用 <ifram ...

  8. Matlab 绘图全方位分析及源码

    Matlab绘图 强大的绘图功能是Matlab的特点之一,Matlab提供了一系列的绘图函数,用户不需要过多的考虑绘图的细节,只需要给出一些基本参数就能得到所需图形,这类函数称为高层绘图函数.此外,M ...

  9. Matlab.NET混合编程技巧之——直接调用Matlab内置函数(附源码)

    原文:[原创]Matlab.NET混合编程技巧之--直接调用Matlab内置函数(附源码) 在我的上一篇文章[原创]Matlab.NET混编技巧之——找出Matlab内置函数中,已经大概的介绍了mat ...

随机推荐

  1. 谷歌与Airbnb的JS代码规范

    谷歌JS代码规范 规范代码原因:代码规范是为了保持源代码编写模式一致,便于维护代码,可读性高. 1.使用空格代替tab 规范随后指出应该使用2个,而不是4个空格带实现缩进.(除了每一行的终止符序列,A ...

  2. 反射与类加载之ClassLoader与类加载器(二)

    更多Android高级架构进阶视频学习请点击:https://space.bilibili.com/474380680本篇文章将从以下几个内容来阐述反射与类加载: [动态代理模式] [Android ...

  3. C# Windows服务相关

    代码及注释 ServiceController sc = new ServiceController("gupdatem"); sc.Stop();//停止服务 sc.Start( ...

  4. 多个串的最长公共子串 SPOJ - LCS2 后缀自动机

    题意: 求多个串的最长公共子串 这里用的是O(n)的后缀自动机写法 我后缀数组的专题有nlog(n)写法的 题解: 对于其中的一个串建立后缀自动机 然后对于后缀自动机上面的每一个节点求出每一个节点最长 ...

  5. Xn数列

     题目描述 Description 给你6个数,m, a, c, x0, n, g Xn+1 = ( aXn + c ) mod m,求Xn m, a, c, x0, n, g<=10^18 输 ...

  6. java oop第10章_JDBC03(MVC分层模式)

    引言:在进行程序开发的时候,为了更加利于程序的管理我们引入了新的开发模式MVC分层模式,即按功能将程序代码分别分为M(Model模型).V(View视图).C(Controller控制器)三个组成部分 ...

  7. 网络编程之 OSI七层协议

    内容目录: 1.软件开发架构 2.OSI七层协议 3.每层协议介绍 1.软件开发架构 c/s架构: c:客户端 s:服务端 b/s架构: b:浏览器 s:服务器 本质:b/s其实也是c/s 2.OSI ...

  8. linux常用命令-2网络相关命令

    1.ip  [选项]  操作对象{link|addr|route...} ip addr show #显示网卡IP信息 2.修改IP配置 1)     root权限 2)     cd /etc/sy ...

  9. [学习笔记]最小割树(Gomory-Hu Tree)

    最小割树(\(\mathcal{Gomory-Hu Tree}\))简明指南 对于单源最短路径,我们有\(SPFA\)和\(Dijkstra\),对于多源最短路径,我们有\(Floyd\):对于两点间 ...

  10. HashMap和Hashtable有什么区别

    HashMap和Hashtable都实现了Map接口,因此很多特性非常相似.但是,他们有以下不同点: HashMap允许键和值是null,而Hashtable不允许键或者值是null. Hashtab ...