English 中文(简体)
MATLAB矩阵的互信息
原标题:Mutual Information of MATLAB Matrix

我有一个方形矩阵,它表示数据集中同时出现的频率计数。换言之,行表示特征1的所有可能观察,列是特征2的可能观察。单元格中的数字(x,y)是在特征2为y的同时观察到特征1为x的次数。

我想计算这个矩阵中包含的相互信息。MATLAB有一个内置的信息函数,但它需要两个参数,一个用于x,一个为y。我该如何操作这个矩阵来获得它期望的参数?

或者,我写了自己的互信息函数,它采用矩阵,但我不确定它的准确性。它看起来对吗?

function [mutualinfo] = mutualInformation(counts)

  total = sum(counts(:));
  pX = sum(counts, 1) ./ total;
  pY = sum(counts) ./ total;
  pXY = counts ./ total;

  [h, w] = size(counts);

  mutualinfo = 0;

  for row = 1:h
    for col = 1:w
      mutualinfo = mutualinfo + pXY(row, col) * log(pXY(row, col) / (pX(row)*pY(col)));
    end;
  end;

end
最佳回答

我不知道MATLAB中有任何内置的互信息函数。也许您掌握了MathWorks文件交换或某些其他第三方开发人员代码

我认为您计算pXpY的方式可能有问题。此外,您可以向量化您的操作,而不是使用for循环。下面是您要尝试的函数的另一个版本:

function mutualInfo = mutualInformation(counts)

  pXY = counts./sum(counts(:));
  pX = sum(pXY,2);
  pY = sum(pXY,1);

  mutualInfo = pXY.*log(pXY./(pX*pY));
  mutualInfo = sum(mutualInfo(:));

end
问题回答

暂无回答




相关问题
How to manage a pageview DB

I am interested in tracking my users pageviews on my site. Being that traffic is expanding very quickly, I am worried about robots, etc, and I also want to be able to use tracked data live to alter ...

Statistics Question

Suppose I conduct a survey of 10 people asking whether to rank a movie as 0 to 4 stars. Allowable answers are 0, 1, 2, 3, and 4. The mean is 2.0 stars. How do I calculate the certainty (or ...

Calculating variance with large numbers

I haven t really used variance calculation that much, and I don t know quite what to expect. Actually I m not too good with math at all. I have a an array of 1000000 random numeric values in the ...

R statistical package: wrapping GOFrame objects

I m trying to generate GOFrame objects to generate a gene ontology mapping in R for unsupported organisms (see http://www.bioconductor.org/packages/release/bioc/vignettes/GOstats/inst/doc/...

Generating correlated numbers

Here is a fun one: I need to generate random x/y pairs that are correlated at a given value of Pearson product moment correlation coefficient, or Pearson r. You can imagine this as two arrays, array ...

Multivariate time series modelling in R

I want do fit some sort of multi-variate time series model using R. Here is a sample of my data: u cci bci cpi gdp dum1 dum2 dum3 dx 16.50 14.00 53.00 45.70 80....

热门标签