Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 43
#---------------------------------------------------------------- # Sample code for UEET2533 Information Theory and Coding # by Chong Zan Kai # Email [email protected] # Universiti Tunku Abdul Rahman, Malaysia. # # Plot the entropy graph. # # Last modified on 2-Feb-2016. #---------------------------------------------------------------- # # Calculate the information of an event that has binary output. # def calc_entropy(p): bit = p * log(1/p, 2) + (1-p) * log(1/(1-p), 2) return bit #---------------------------------------------------------------- # Main #---------------------------------------------------------------- import scipy import pylab x_list = scipy.arange(0.01, 1.0, 0.01) y_list = [calc_entropy(p) for p in x_list] pylab.plot(x_list, y_list) pylab.ylabel(r'Entropy, $H(X)$') pylab.xlabel(r'Probability, $\Pr(X=1)$') pylab.ylim(0, 1.1) pylab.grid(True) pylab.show()
[<matplotlib.lines.Line2D object at 0x7fbc8cab4b50>] <matplotlib.text.Text object at 0x7fbc8c7b2a10> <matplotlib.text.Text object at 0x7fbc8cc2f510> (0, 1.10000000000000)