@@ -27,7 +27,12 @@ Create a histogram with bin partition defined by `edges`.
2727- If `left`, the bins will be left-closed.
2828- If `closed`, the bin on the end will be closed.
2929 - E.g. for a two bin histogram ``[a, b), [b, c)`` vs. ``[a, b), [b, c]``
30- # Example
30+
31+ If `edges` is a tuple instead of an array, a multidimensional histogram will be
32+ generated that behaves like a `WeightedOnlineStat{VectorOb}`.
33+
34+ # Examples
35+
3136 o = fit!(WeightedHist(-5:.1:5), randn(10^6))
3237
3338 # approximate statistics
@@ -40,6 +45,11 @@ Create a histogram with bin partition defined by `edges`.
4045 extrema(o)
4146 area(o)
4247 pdf(o)
48+
49+ ## 2d Histogram
50+
51+ hist2d = fit!(WeightedHist((-5:1:5, -5:1:5) ), randn(10000,2), rand(10000))
52+ value(hist2d).y
4353"""
4454struct WeightedHist1D{R} <: WeightedHist{Float64}
4555 edges:: R
7686nobs (o:: WeightedHist ) = sum (o. counts) + sum (o. outcount)
7787weightsum (o:: WeightedHist ) = LinearAlgebra. dot (o. counts, o. meanw) + LinearAlgebra. dot (o. outcount,o. meanwout)
7888value (o:: WeightedHist ) = (x= edges (o), y= o. counts .* o. meanw)
89+ binindices (o:: WeightedHistND{<:Any,N} , x:: AbstractVector ) where N = binindices (o, ntuple (i-> x[i],N))
7990binindices (o:: WeightedHist1D ,x) = OnlineStats. binindex (o. edges, x, o. left, o. closed)
8091binindices (o:: WeightedHistND ,x) = CartesianIndex (map ((e,ix)-> OnlineStats. binindex (e, ix, o. left, o. closed), o. edges, x))
8192midpoints (o:: WeightedHistND ) = Iterators. product (map (midpoints,o. edges)... )
0 commit comments