Matlab solves the probability density distribution of discrete two-dimensional random variables

No math formulas or anything.

Doing experiments to calculate joint entropy requires the use of probability densities.

The function accumarray is not very good. Many 0s in the square matrix waste memory. I don’t have hundreds of gigabytes of memory ε=(´ο`*))) Alas.

Matlab code implementation

function tong1joint = calmi(u1, u2, wind_size)
x = [u1, u2];   //% x是2个列向量组成的矩阵
n = wind_size; // % 列向量长度
xmax = max(x(:,1));
tongwidth = xmax;
tong1 = zeros(2,tongwidth);	// % 这算是桶吧
for i = 1:n
   if x(i,2) == 1
       tong1(1,x(i,1)) = tong1(1,x(i,1)) +1;
   else
       tong1(2,x(i,1)) = tong1(2,x(i,1)) +1;
   end
end
tong1pmf = tong1/n;  													 //% u1和u2的联合概率密度
tong1joint = (tong1pmf(:))'*log2((tong1pmf(:))+eps);   // % 联合熵

example

There are no instances.

Guess you like

Origin blog.csdn.net/Chauncyxu/article/details/117330483