The current (v0.33.16) implementation of entropy(p)
|
function entropy(p) |
|
if isempty(p) |
|
throw(ArgumentError("empty collections are not supported since they do not " * |
|
"represent proper probability distributions")) |
|
end |
|
return -sum(xlogx, p) |
|
end |
|
|
|
entropy(p, b::Real) = entropy(p) / log(b) |
returns weird results if the argument isn't a probability-like vector (i.e. sum(p) != 1)
julia> entropy([0.5,0.5],2) # correct
1.0
julia> entropy([0.5,0.25],2) # this should throw an error?
1.0
julia> entropy([0.25,0.25],2) # this too, or at least some notion of normalization of p?
1.0
julia> entropy([0.125,0.125],2) # incorrect, no idea what's happening here
0.75
The current (v0.33.16) implementation of
entropy(p)StatsBase.jl/src/scalarstats.jl
Lines 760 to 768 in 071d10a
returns weird results if the argument isn't a probability-like vector (i.e.
sum(p) != 1)