Calculate the entropy of a list of 2D points in Matlab

半城伤御伤魂 提交于 2020-01-30 11:28:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!