-
Notifications
You must be signed in to change notification settings - Fork 14
IndirectEntropy
should not subtype Entropy
.
#167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Well, can it though? Or are we generalizing something that we shouldn't care to generalize?
Personally I am happy with current API, but it also seems to me that simply swapping the order of arguments into
You'd have only two wrapper functions, |
Ok, just for the sake of the argument here, let's
I really want to follow the same style in CausalityTools too (i.e. entropy/mutualinfo/transfer entropy type first, then estimator then input data).
We'd just keep the names as they are. Each docstring should clearly state what type of entropy the estimator computes (all of them do already). With the change I propose, there is just a single supertype """
Kraskov <: EntropyEstimator
A Shannon entropy estimator that computes entropy directly without first computing probabilities, by doing ....
"""
"""
Zhu <: EntropyEstimator
A Shannon entropy estimator that computes entropy directly without first computing probabilities, by doing ....
"""
"""
ClassicEstimator <: EntropyEstimator
A Tsallos entropy estimator that computes entropy directly without first computing probabilities, by doing ....
"""
function entropy(e::Renyi, est::Kraskov, args...)
e.q == 1 || error("$est can't be used to estimate Renyi entropy with q = $(e.q)")
... # implementation
end
function entropy(e::Renyi, est::Zhu, args...)
e.q == 1 || error("$est can't be used to estimate Renyi entropy with q = $(e.q)")
... # implementation
end
function entropy(e::Tsallis, est::ClassicalEstimator, args...)
... # implementation
end
# Generic error message in all other cases.
entropy(e::Entropy, est::EntropyEstimator, args...) = error("$e entropy can't be estimated using a $est estimator" Here, To me, this seems a rather obvious way to streamline the api, without any obvious downsides. Any confusion would be immediately resolved when the user reads the docs, and we will supplement with tables of available methods and their syntax.
Simply swapping the order of the arguments doesn't solve my issue, because Overall, this is a low-effort change that will 1) make at least my life easier and lead to better and non-duplicated code in the CausalityTools stuff, 2) be more intiutive for the user, because the only thing that changes between using direct probabilities and indirect estimator is the second argument (not having to use two different signatures and think about why there are two signatures for doing the same thing) |
But |
in any case I am ok with the proposed change |
In CausalityTools, I will always feed a first
Excellent. |
Closed by #168. |
While getting CausalityTools ready for Entropies v2, I encountered the following issue:
There are now two ways of computing entropies: either
entropy(e::Entropy, x, est::ProbabilitiesEstimator)
entropy(e::IndirectEntropy, x)
.I have two problems with this:
1. The indirect entropies are not entropies.
They are types indicating that a certain type of entropy is being estimated using a certain numerical procedure. A much more natural choice would be to have just one signature
entropy(e::Entropy, x, est::Union{ProbabilitiesEstimator, EntropyEstimator}
, whereEntropyEstimator
is what we now callIndirectEntropy
.The API should be predictable, and the types should be named in a way that reflects what is actually going on. I argue that
IndirectEntropy
is a bit misleading, because it can be confused withEntropy
, which is something else entirely. Actually, now we equate (through the type hierarchy) an entropic quantity with its estimator. But the former is used to estimate the latter. They should be different things.We already make this distinction for probabilities.
Probabilities
is the quantity being computed, whileProbabilitiesEstimator
is the procedure used to estimate it.Entropy
s should have the corresponding quantityEntropyEstimator
that computes it.Thus:
entropy(::Kraskov, x)
should beentropy(::Shannon, x, ::Kraskov)
.Kraskov
estimator can be used to estimate some other entropy, then dispatch must be implemented for that particular entropy, i.e.entropy(::SomeOtherEntropy, x, ::Kraskov)
.2. Two distinct signatures lead to code duplication
The way we've designed it now, I have to duplicate source code using
entropy
where I want to be able to input both probability estimators and entropy estimators. I have to make:ProbabilitiesEstimator
(which has one order of arguments) and,IndirectEntropy
. I can, of course, write wrapper functions and circumvent this issue. But that shouldn't be necessary.The text was updated successfully, but these errors were encountered: