在 Matlab 中计算二维点列表的熵 [英] Calculate the entropy of a list of 2D points in Matlab
问题描述
我有一个像这样的数组中的点列表
I have a list of points in an array like this
points = [[1,2];[2,5];[7,1]...[x,y]]
x 在 0 到 1020 之间,y 在 0 到 1920 之间.
The x is between 0 and 1020 and y is between 0 and 1920.
如何在 Matlab 中计算点数组的熵?
How can I calculate the entropy of the points array in Matlab?
非常感谢!
推荐答案
我假设您想将每个 [x,y]
点视为一个数据点.让我们定义一些示例数据:
I assume you want to consider each [x,y]
point as one data point. Let us define some exemplary data:
A = [[1,2];[2,5];[7,1];[1,2]];
首先我们给相等的点相等的标识符,我们可以使用
First we give equal points equal identifiers, we can do this using
[~,~,ic] = unique(A, 'rows');
然后我们计算频率以及每个标识符的概率:
Then we compute the frequency and with that the probability of each identifier:
[frequency, ~] = histcounts(ic,max(ic));
probability = frequency/sum(frequency);
有了这个,我们可以立即计算熵:
With this we can immediately compute the entropy:
entropy = -sum(probability .* log(probability))
(确保使用正确的对数,不同的字段通常使用不同的底数.)
(Make sure you use the right logarithm, different fields conventionally use different bases.)
这篇关于在 Matlab 中计算二维点列表的熵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!