-
Notifications
You must be signed in to change notification settings - Fork 14
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
Add generic histogram method for Vector{<:Any}
, so we can use counts(::UniqueElements, x)
on any data
#349
Comments
Hm. Not entirely sure about this. Should we instead require the input to be sortable (i.e. the user has to map their data to some sortable format)? That would make maintenance a bit easier. |
I think in the future there should be a version implemented for non-sortable collections. But this is extremely low priority because a user can always map their vector to the integers corresponding to unique elements and then use count on the integer. For now we can focus on v3 and hope that some other contributor will add this method in the future. |
Agreed. Then I keep this issue open. |
There is a difficulty I see in implementing this: there is no julia function, or type trait, that checks for sortability. So it is not clear to me how we would check whether we can call fasthist or not in the first place... |
We could check something like
with |
Yes, this should work. The fallback would typically just occur when the user has different types of elements in their input vector. Then julia> T = Any
Any
julia> hasmethod(isless, (T, T))
false |
In the current API, the docstring of """
outcome_space(o::OutcomeSpace, x) → Ω
Return a sorted container containing all _possible_ outcomes of `o` for input `x`.
For some estimators the concrete outcome space is known without knowledge of input `x`,
in which case the function dispatches to `outcome_space(o)`.
In general it is recommended to use the 2-argument version irrespectively of estimator.
"""
function outcome_space(o::OutcomeSpace) For a non-sortable vector, we can't sort the elements. Therefore, we either need to relax this requirement, or disallow using non-sortable data (which I think is too restrictive atm). We could just say that "if your input data isn't sortable, then the outcome space is given in the order of first appearance of the outcomes" or something like that |
Yes order of first appearance is fine, but at the moment non sortable data simply domm't work with the pacakge ayways |
I haven't done any sort of testing for speed etc, but an obvious (and perhaps the easiest) solution to this issue is precisely what @Datseris says above - convert to the integers (and then convert back again). We already have the infrastructure to do this conversion, in the form of
|
In any case, anyone working on this should wait until #347 is merged. |
Currently, we can do
But this only works if
x
is sortable, becausefasthist!
uses sorting internally. We should have a generic (probably much slower) fallback that enables things like this to work too:The text was updated successfully, but these errors were encountered: