-
Notifications
You must be signed in to change notification settings - Fork 41
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
Weighted mean from StatsBase
does not work on DimArray
#754
Comments
We got a bit tricky with those unit ranges, guess we missed a method. It would be good to allow a dim there too, do we need a StatsBase extension for dispatch? |
Yes because the second argument has to be typed as |
Ok we should add an extension for StatsBase. We need it to make If you have time feel free to PR, otherwise it may take a while to get to it. |
So turns out this can be fixed by defining using DimensionalData, StatsBase
function Base.reduced_index(dur::DimensionalData.Dimensions.DimUnitRange)
r1 = Base.reduced_index(parent(dur))
d = dims(dur)
# Type changes are not allowed here so we just
# take the "first" value
d1 = if isreverse(d)
d[end:end]
else
d[begin:begin]
end
DimensionalData.Dimensions.DimUnitRange(r1, d1)
end And weighted mean just works. julia> mean(data, weights([0.3,0.3,0.4]), 2)
╭──────────────────────────╮
│ 10×1 DimArray{Float64,2} │
├──────────────────────────┴─────────────────────── dims ┐
↓ X Sampled{Int64} 1:10 ForwardOrdered Regular Points,
→ Y Sampled{Int64} 1:1 ForwardOrdered Regular Points
└────────────────────────────────────────────────────────┘
↓ → 1
1 1.0
2 1.0
3 1.0
4 1.0
5 1.0
6 1.0
7 1.0
8 1.0
9 1.0
10 1.0 The annoying part is we cant use |
I am not sure I see the problem here from the example. But I think the suboptimal behavior of the lookup reduction is probably acceptable in exchange for having the basic functionality of |
Yeah let's just add it as is |
Fixed |
The following does not work with
DimArray
:This produces an error:
On a related note, maybe
DimensionalData
could add dispatches for these functions that takes aDim
instead of an integer?The text was updated successfully, but these errors were encountered: