您的位置:首页 > 其它

给出x 和 y 的联合概率,求信息熵

2018-06-06 23:15 155 查看
f <- function(x)
{
x <- x[which(x != 0)]
return(-sum(x*log(x)))
}
information_entropy <- function(A)
{
apply(A, 1, f)
apply(A, 1, f)
temp1 <- as.vector(A)
temp1 <- temp1[which(temp1 != 0)]
result <- -sum(temp1*log(temp1))
list("x的信息熵" = apply(A, 1, f),
"x的信息熵" = apply(A, 2, f),
"x,y的联合信息熵" = result)
}

A <- matrix(1/2, ncol = 2, nrow = 2)

information_entropy(A)

阅读更多
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐