问题
I have a list of points in an array like this
points = [[1,2];[2,5];[7,1]...[x,y]]
The x is between 0 and 1020 and y is between 0 and 1920.
How can I calculate the entropy of the points array in Matlab?
Many thanks!
回答1:
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.)
来源:https://stackoverflow.com/questions/58289817/calculate-the-entropy-of-a-list-of-2d-points-in-matlab