我是R的新手,試圖找到一個函數來計算JS在JS中的散度。 我可以看到R有KLdiv來計算KL散度,但是有什麼可用於JS散度?Jensen Shannon divergence in R
5
A
回答
0
根據維基百科Jensen-Shannon發散是KL散度的一種轉變。自定義應用公式應該給你的JS偏差然後...
參見:http://en.wikipedia.org/wiki/Jensen%E2%80%93Shannon_divergence
4
在任何情況下一個答案(我)仍在尋找,還有在計算此功能[R包phyloseq:http://www.plosone.org/article/info%3Adoi%2F10.1371%2Fjournal.pone.0061217
我也發現了這個教程有用:http://enterotype.embl.de/enterotypes.html
7
我一直在尋找一個簡單實現JS divergence的,而不是的R庫。由於我沒有看到任何答覆,所以我想出了下面的答案。
假設我們有以下的輸入分佈:
# p & q are distributions so their elements should sum up to 1
p <- c(0.00029421, 0.42837957, 0.1371827, 0.00029419, 0.00029419,
0.40526004, 0.02741252, 0.00029422, 0.00029417, 0.00029418)
q <- c(0.00476199, 0.004762, 0.004762, 0.00476202, 0.95714168,
0.00476213, 0.00476212, 0.00476202, 0.00476202, 0.00476202)
的詹森 - 香農散度將是:
m <- 0.5 * (p + q)
JS <- 0.5 * (sum(p * log(p/m)) + sum(q * log(q/m)))
> JS
[1] 0.6457538
在超過2個分佈(其已經討論here),我們需要一個函數來計算Entropy:
H <- function(v) {
v <- v[v > 0]
return(sum(-v * log(v)))
}
然後JS散度將是:
JSD <- function(w, m) {
return(H(m %*% w) - apply(m, 2, H) %*% w)
}
> JSD(w = c(1/3, 1/3, 1/3), m = cbind(p, q, m))
[,1]
[1,] 0.4305025
凡w
是應該總結1和m
權重的矢量與輸入分佈爲列的矩陣。
相關問題
- 1. Jensen-Shannon Divergence
- 2. Pythonwise中的pairwise Kullback Leibler(或Jensen-Shannon)散度距離矩陣
- 3. Shannon Entropy
- 4. Shannon-Fano編碼與圖像
- 5. confusionMatrix in R
- 6. na.omit in data.table,R
- 7. Paste/Collapse in R
- 8. Date Vector in R
- 9. ImageMagick in R
- 10. Xgboost Num_class in R
- 11. R plot in order
- 12. WriteWebGL in R
- 13. hts package in R
- 14. gblinear xgboost in R
- 15. lapply and data.frame in R
- 16. 「*」vs「:」in R for model
- 17. Project Euler#29 in R
- 18. `actionButton` action in Shiny R
- 19. 關於PCA in R?
- 20. IF/THEN/ELSE in R
- 21. rgb()with ggplot2 in R
- 22. Recenter heatmap.2 in R
- 23. pch in plot with R
- 24. readPDF(tm package)in R
- 25. Latex,RenderTable in Shiny,R
- 26. setdiff of row in R
- 27. apply()vs. sweep()in R
- 28. RExcel in R 3.0.x
- 29. Cartogram + choropleth map in R
- 30. file.copy in R not working
非常好的工作! –