Skip to content

Commit

Permalink
Add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
oschulz committed Dec 2, 2019
1 parent 149a279 commit 18ae5a9
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
[![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)
[![Codecov](https://codecov.io/gh/oschulz/EmpiricalDistributions.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/oschulz/EmpiricalDistributions.jl)

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


## Documentation

Expand Down
47 changes: 47 additions & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
@@ -1 +1,48 @@
# EmpiricalDistributions.jl

A Julia package for empirical probability distributions that implement the
[Distributions.jl](https://github.com/JuliaStats/Distributions.jl) API.

This package currently provides uni- and multivariate binned distributions,
backed by [StatsBase.jl](https://github.com/JuliaStats/StatsBase.jl)
histograms.

[`UvBinnedDist`](@ref) wraps a 1-dimensional histogram and presents it as
a (binned) univariate continuous distribution:

```julia
using Distributions, StatsBase

X_uv = rand(Normal(2.0, 0.5), 10^5)
uvhist = fit(Histogram, X_uv)

using EmpiricalDistributions

uvdist = UvBinnedDist(uvhist)
uvdist isa Distribution{Univariate,Continuous}
```

The resulting distribution can be queried, used to generate random numbers,
etc.:

```julia
mean(uvdist), var(uvdist)
maximum(uvdist), minimum(uvdist)
rand(uvdist, 5)
```

[`MvBinnedDist`](@ref) does the same for a multi-dimensional histogram,
and presents it as a (binned) multivariate continuous distribution:

```julia
X_mv = rand(MvNormal([3.5, 0.5], [2.0 0.5; 0.5 1.0]), 10^5)
mvhist = fit(Histogram, (X_mv[1, :], X_mv[2, :]))

using Distributions, EmpiricalDistributions

mvdist = MvBinnedDist(mvhist)
mvdist isa Distribution{Multivariate,Continuous}

mean(mvdist), cov(mvdist)
rand(mvdist, 5)
```
11 changes: 11 additions & 0 deletions src/mv_binned_dist.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# This file is a part of EmpiricalDistributions.jl, licensed under the MIT License (MIT).


"""
UvBinnedDist <: Distribution{Univariate,Continuous}
Wraps a multi-dimensional histograms and presents it as a binned multivariate
distribution.
Constructor:
MvBinnedDist(h::Histogram{<:Real,N})
"""
struct MvBinnedDist{T, N} <: Distributions.Distribution{Multivariate,Continuous}
h::StatsBase.Histogram{<:Real, N}
edges::NTuple{N, <:AbstractVector{T}}
Expand Down
10 changes: 10 additions & 0 deletions src/uv_binned_dist.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
# This file is a part of EmpiricalDistributions.jl, licensed under the MIT License (MIT).


"""
UvBinnedDist <: Distribution{Univariate,Continuous}
Wraps a 1-dimensional histograms and presents it as a binned univariate
distribution.
Constructor:
UvBinnedDist(h::Histogram{<:Real,1})
"""
struct UvBinnedDist{T <: AbstractFloat} <: Distribution{Univariate,Continuous}
h::Histogram{<:Real, 1}
inv_weights::Vector{T}
Expand Down

2 comments on commit 18ae5a9

@oschulz
Copy link
Owner Author

@oschulz oschulz commented on 18ae5a9 Dec 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/6129

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if Julia TagBot is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.0 -m "<description of version>" 18ae5a913a3f5f48a928d4b2387614758ba05357
git push origin v0.1.0

Please sign in to comment.