Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@p1scescom
Created January 25, 2020 07:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save p1scescom/67475e6333c6dfe73966a4455182e7d2 to your computer and use it in GitHub Desktop.
Save p1scescom/67475e6333c6dfe73966a4455182e7d2 to your computer and use it in GitHub Desktop.
entropy
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