Mohammad
Mohammad

Reputation: 7418

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]]

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!

Upvotes: 0

Views: 1138

Answers (1)

flawr
flawr

Reputation: 11628

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.)

Upvotes: 2

Related Questions