Skip to content

Commit 69db6aa

Browse files
committed
Update version and extend docstring
1 parent 14f394f commit 69db6aa

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

Project.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
name = "WeightedOnlineStats"
22
uuid = "bbac0a1f-7c9d-5672-960b-c6ca726e5d5d"
33
authors = ["Guido Kraemer <[email protected]>", "Martin Gutwin <[email protected]>"]
4-
version = "0.3.3"
4+
version = "0.4.0"
55

66
[compat]
77
julia = "1"
8+
MultivariateStats = "0.7"
9+
OnlineStats = "1"
10+
OnlineStatsBase = "1"
11+
StatsBase = "0.30,0.31,0.32"
812

913
[deps]
1014
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

src/histogram.jl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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
"""
4454
struct WeightedHist1D{R} <: WeightedHist{Float64}
4555
edges::R
@@ -76,6 +86,7 @@ end
7686
nobs(o::WeightedHist) = sum(o.counts) + sum(o.outcount)
7787
weightsum(o::WeightedHist) = LinearAlgebra.dot(o.counts, o.meanw) + LinearAlgebra.dot(o.outcount,o.meanwout)
7888
value(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))
7990
binindices(o::WeightedHist1D,x) = OnlineStats.binindex(o.edges, x, o.left, o.closed)
8091
binindices(o::WeightedHistND,x) = CartesianIndex(map((e,ix)->OnlineStats.binindex(e, ix, o.left, o.closed), o.edges, x))
8192
midpoints(o::WeightedHistND) = Iterators.product(map(midpoints,o.edges)...)

0 commit comments

Comments
 (0)