Skip to content
Paco Zamora Martinez edited this page Jan 2, 2014 · 3 revisions

Introduction

Package stats.MI could be loaded via the standalone binary, or in Lua with require("aprilann.stats.MI).

The table stats.MI contains functions useful to compute the Mutual Information between matrices of data. It has the following functions:

  • number = stats.MI.entropy(matrix, histogram, levels=256) this function receives three optional arguments. The first two are related to the set of data from computing the entropy. One of them must be given, the other must be nil. The third argument is by default 256, and is only useful if the matrix is given, and indicates the number of levels for the histogram computation.
    • If the matrix argument is given, a histogram is computed to estimate the probability distribution of the data, using the given number of levels, 256 by default.
    • If the histogram argument is given, the function takes this histogram as the source for the probability distribution estimation.
  • MI,NMI = stats.MI.mutual_information(matrix1, matrix2, levels=256) this function computes the amount of information mutually shared by the given two matrices of data, using levels for the histogram computation. The two matrices will be reinterpreted as a linear sequence of data, so the must have exactly the same size, and is recommended both matrices to being a vector of data, so multi-dimensional feature vectors are not allowed. The function returns the Mutual Information, and the Normalized Mutual Information.
> m1 = matrix(1,10):linear(1)
> m2 = matrix(1,10)
> m2:slice({1,1},{1,5}):linear(2)
> m2:slice({1,6},{1,5}):linear(2)
> print(m1)
 1          2          3          4          5          6          7          8          9          10        
# Matrix of size [1,10] in row_major [0x260dae0 data= 0x260dbc0]
> print(m2)
 2          3          4          5          6          2          3          4          5          6         
# Matrix of size [1,10] in row_major [0x260e280 data= 0x260de70]
> print(stats.MI.mutual_information(m1,m2))
2.321927794305	1.6989699041453
Clone this wiki locally