Created
January 25, 2020 07:27
-
-
Save p1scescom/67475e6333c6dfe73966a4455182e7d2 to your computer and use it in GitHub Desktop.
entropy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function _entropy(coef) | |
bs = size(coef) | |
d = Dict{Int,Int}() | |
for i in 1:bs[1], j in 1:bs[2] | |
d[coef[i,j]] = get(d, coef[i,j], 0) + 1 | |
end | |
h = 0.0 | |
for i in d | |
println(i,i.second,length(coef)) | |
p = i.second/length(coef) | |
println(p) | |
h -= p*log2(p) | |
end | |
h | |
end | |
function entropy(coef) | |
if ndims(coef) == 2 | |
return _entropy(coef) | |
elseif ndims(coef) == 3 | |
cs = size(coef)[1] | |
es = 0.0 | |
for i in 1:cs | |
es += entropy(coef[i,:,:]) | |
end | |
return es/cs | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment