JuliaLang/julia — pull request #956 by johnmyleswhite (2012-06-20 04:00:13+00:00)
Title: Implemented multinomial and Dirichlet distributions.

Here's an implementation of the multinomial and Dirichlet distributions. Below are some examples you can use to test these functions:

load("base/distributions.jl")

d = Multinomial(1, [0.5, 0.4, 0.1])
d = Multinomial(1, 3)
d = Multinomial(3)
d = Multinomial(1, [0.6; 0.4])
d = Multinomial(1, [0.6; 0.4]')
mean(d)
var(d)
insupport(d, [1, 0])
insupport(d, [1, 1])
insupport(d, [0, 1])
pmf(d, [1, 0])
pmf(d, [1, 1])
pmf(d, [0, 1])
logpmf(d, [1, 0])
logpmf(d, [1, 1])
logpmf(d, [0, 1])
rand(d)
A = zeros(Int, 10, 2)
rand!(d, A)
A

d = Dirichlet([1.0, 2.0, 1.0])
d = Dirichlet(3)
d = Dirichlet([1.0; 2.0; 1.0])
d = Dirichlet([1.0; 2.0; 1.0]')
mean(d)
var(d)
insupport(d, [0.1, 0.8, 0.1])
insupport(d, [0.1, 0.8, 0.2])
insupport(d, [0.1, 0.8])
pdf(d, [0.1, 0.8, 0.1])
rand(d)
A = zeros(Float64, 10, 3)
rand!(d, A)
A