Ai
1 Star 0 Fork 0

mosache/go-zero

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
entropy.go 423 Bytes
一键复制 编辑 原始数据 按行查看 历史
kevwan 提交于 2020-08-07 15:28 +08:00 . add tests
package mathx
import "math"
const epsilon = 1e-6
func CalcEntropy(m map[interface{}]int) float64 {
if len(m) == 0 || len(m) == 1 {
return 1
}
var entropy float64
var total int
for _, v := range m {
total += v
}
for _, v := range m {
proba := float64(v) / float64(total)
if proba < epsilon {
proba = epsilon
}
entropy -= proba * math.Log2(proba)
}
return entropy / math.Log2(float64(len(m)))
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mosache/go-zero.git
git@gitee.com:mosache/go-zero.git
mosache
go-zero
go-zero
dfb45c801a6c

搜索帮助