Skip to content

Commit 18ae5a9

Browse files
committed
Add docs
1 parent 149a279 commit 18ae5a9

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
[![Appveyor Build Status](https://ci.appveyor.com/api/projects/status/github/oschulz/EmpiricalDistributions.jl?branch=master&svg=true)](https://ci.appveyor.com/project/oschulz/EmpiricalDistributions-jl)
88
[![Codecov](https://codecov.io/gh/oschulz/EmpiricalDistributions.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/oschulz/EmpiricalDistributions.jl)
99

10+
A Julia package for empirical probability distributions. Currently
11+
implements uni- and multivariate binned distributions, backed by
12+
[StatsBase.jl](https://github.com/JuliaStats/StatsBase.jl) histograms.
13+
1014

1115
## Documentation
1216

docs/src/index.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,48 @@
11
# EmpiricalDistributions.jl
2+
3+
A Julia package for empirical probability distributions that implement the
4+
[Distributions.jl](https://github.com/JuliaStats/Distributions.jl) API.
5+
6+
This package currently provides uni- and multivariate binned distributions,
7+
backed by [StatsBase.jl](https://github.com/JuliaStats/StatsBase.jl)
8+
histograms.
9+
10+
[`UvBinnedDist`](@ref) wraps a 1-dimensional histogram and presents it as
11+
a (binned) univariate continuous distribution:
12+
13+
```julia
14+
using Distributions, StatsBase
15+
16+
X_uv = rand(Normal(2.0, 0.5), 10^5)
17+
uvhist = fit(Histogram, X_uv)
18+
19+
using EmpiricalDistributions
20+
21+
uvdist = UvBinnedDist(uvhist)
22+
uvdist isa Distribution{Univariate,Continuous}
23+
```
24+
25+
The resulting distribution can be queried, used to generate random numbers,
26+
etc.:
27+
28+
```julia
29+
mean(uvdist), var(uvdist)
30+
maximum(uvdist), minimum(uvdist)
31+
rand(uvdist, 5)
32+
```
33+
34+
[`MvBinnedDist`](@ref) does the same for a multi-dimensional histogram,
35+
and presents it as a (binned) multivariate continuous distribution:
36+
37+
```julia
38+
X_mv = rand(MvNormal([3.5, 0.5], [2.0 0.5; 0.5 1.0]), 10^5)
39+
mvhist = fit(Histogram, (X_mv[1, :], X_mv[2, :]))
40+
41+
using Distributions, EmpiricalDistributions
42+
43+
mvdist = MvBinnedDist(mvhist)
44+
mvdist isa Distribution{Multivariate,Continuous}
45+
46+
mean(mvdist), cov(mvdist)
47+
rand(mvdist, 5)
48+
```

src/mv_binned_dist.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# This file is a part of EmpiricalDistributions.jl, licensed under the MIT License (MIT).
22

3+
4+
"""
5+
UvBinnedDist <: Distribution{Univariate,Continuous}
6+
7+
Wraps a multi-dimensional histograms and presents it as a binned multivariate
8+
distribution.
9+
10+
Constructor:
11+
12+
MvBinnedDist(h::Histogram{<:Real,N})
13+
"""
314
struct MvBinnedDist{T, N} <: Distributions.Distribution{Multivariate,Continuous}
415
h::StatsBase.Histogram{<:Real, N}
516
edges::NTuple{N, <:AbstractVector{T}}

src/uv_binned_dist.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
# This file is a part of EmpiricalDistributions.jl, licensed under the MIT License (MIT).
22

33

4+
"""
5+
UvBinnedDist <: Distribution{Univariate,Continuous}
6+
7+
Wraps a 1-dimensional histograms and presents it as a binned univariate
8+
distribution.
9+
10+
Constructor:
11+
12+
UvBinnedDist(h::Histogram{<:Real,1})
13+
"""
414
struct UvBinnedDist{T <: AbstractFloat} <: Distribution{Univariate,Continuous}
515
h::Histogram{<:Real, 1}
616
inv_weights::Vector{T}

0 commit comments

Comments
 (0)