1.理論及相關概念
1.1熵
用來描述随機變量平均資訊量,公式為:
1.2聯合熵
設x, y是兩個離散型随機變量,它們的聯合分布密度為p(x, y), 則z 和y 的聯合熵定義為:
1.3條件熵 設x, y是兩個離散型随機變量,它們的聯合分布密度為p(x, y), 則z 和y 的條件熵定義為:
1.4互資訊
互資訊定義為:
推導為
互資訊為0,則相關性為0;
互資訊趨于無窮,相關性為+/-1
2.R語言實作
mi.empirical(y2d, unit=c("log", "log2", "log10"))
參數:
y2d: 要計算互資訊的矩陣
unit: the unit in which entropy is measured. The default is "nats" (natural units). For computing entropy in "bits" set unit="log2".
舉例:
y2d = rbind( c(1,2,3), c(6,5,4) )
# empirical estimate of mutual information
mi.empirical(y2d)
mi.empirical傳回值即為互資訊的值,值越大,組成矩陣的向量間相關性越大
3.參考:
1. http://ziketang.com/2013/08/some-notions-about-entropy/
2. http://cran.r-project.org/web/packages/entropy/entropy.pdf
3. http://kris.kalish.net/2013/11/mutual-information-in-r/