## [9f8b15]: doc / info-theory.m  Maximize  Restore  History

### 95 lines (62 with data), 1.4 kB

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94``` ```#! /usr/bin/octave -q % % General test cases for Octave % % % Tests for Information Theory Library. % p=[ 0 0.75; 0.125 0.125 ]; jointentropy(p) x=marginalc(p); entropy(x) y=marginalr(p); entropy(y) % Test on Mutual Information XY=[ 1/8 1/16 1/32 1/32; 1/16 1/8 1/32 1/32; 1/16 1/16 1/16 1/16; 1/4 0 0 0 ]; mutualinformation(XY) entropy(marginalc(XY)) - conditionalentropy_XY(XY) entropy(marginalr(XY)) - conditionalentropy_YX(XY) jointentropy(XY) % Test on Relative Entropy X=[0.5 0.2 0.2 0.1]; Y=[0.2 0.2 0.2 0.4]; relativeentropy(X,Y) relativeentropy(Y,X) % Test on Conditional Entropy XY=[ 1/8 1/16 1/32 1/32; 1/16 1/8 1/32 1/32; 1/16 1/16 1/16 1/16; 1/4 0 0 0 ]; % x=marginalr(XY) % y=marginalc(XY) c1=conditionalentropy_XY(XY); c2=conditionalentropy_YX(XY); j=jointentropy(XY); marx=entropy(marginalc(XY)); mary=entropy(marginalr(XY)); j # H(x,y) marx + c2 # H(x,y) mary + c1 # H(x,y) % Test on Joint Entropy XY=[ 1/8 1/16 1/32 1/32; 1/16 1/8 1/32 1/32; 1/16 1/16 1/16 1/16; 1/4 0 0 0 ]; jointentropy(XY) % Test on Conditional Entropy % Test on Entropy function for N=2:20 prob=ones(1,N)*(1/N); x=entropy(prob); printf("Entropy of %g is %g\n",prob(1),x); end prob=[1/2,1/4,1/8,1/8] val=0 for i=1:length(prob) val=val+prob(i)*log2(prob(i)) end entropy(prob) ```