Skip to content

Entropy calculation with non-probability vectors #769

Open
@milankl

Description

@milankl

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions