Shannon's Entropy calculation

Composer picture Composer · Feb 27, 2014 · Viewed 15.6k times · Source

I have a probability distribution that defines the probability of occurrence of n possible states.

I would like to calculate the value of Shannon's entropy, in bits, of the given probability distribution.

Can I use wentropy(x,'shannon') to get the value and if so where can I define the number of possible states a system has?

Answer

chappjc picture chappjc · Feb 27, 2014

Since you already have the probability distribution, call it p, you can do the following formula for Shannon Entropy instead of using wentropy:

H = sum(-(p(p>0).*(log2(p(p>0)))));

This gives the entropy H in bits.

p must sum to 1.