Ce serveur Gitlab sera éteint le 30 juin 2020, pensez à migrer vos projets vers les serveurs gitlab-research.centralesupelec.fr et gitlab-student.centralesupelec.fr !

Commit e81a3020 authored by Dahua Lin's avatar Dahua Lin

introduce a dim function for getting sample dimension of a multivariate distribution

parent 13a56269
......@@ -82,6 +82,7 @@ export # types
cumulant, # cumulants of distribution
deviance, # deviance of fitted and observed responses
devresid, # vector of squared deviance residuals
dim, # sample dimension of multivariate distribution
entropy, # entropy of distribution in nats
fit, # fit a distribution to data
freecumulant, # free cumulants of distribution
......
......@@ -19,6 +19,8 @@ Dirichlet(d::Integer, alpha::Real) = Dirichlet(fill(alpha, d))
Dirichlet(dim::Integer) = Dirichlet(ones(dim))
dim(d::Dirichlet) = length(d.alpha)
function entropy(d::Dirichlet)
k = length(d.alpha)
en = lmnB(d)
......
......@@ -32,6 +32,8 @@ end
Multinomial(d::Integer) = Multinomial(1, d)
dim(d::Multinomial) = length(d.prob)
entropy(d::Multinomial) = NumericExtensions.entropy(d.prob)
function insupport{T <: Real}(d::Multinomial, x::Vector{T})
......
......@@ -21,6 +21,9 @@ function MultivariateNormal(cov::Matrix{Float64})
end
MultivariateNormal() = MultivariateNormal(zeros(2), eye(2))
dim(d::MultivariateNormal) = length(d.mean)
function cdf{T <: Real}(d::MultivariateNormal, x::Vector{T})
k = length(d.mean)
if k > 3
......
......@@ -8,12 +8,14 @@ for d in [Dirichlet([100.0, 17.0, 31.0, 45.0]),
MultivariateNormal([0.0, 0.0], [1.0 0.9; 0.9 1.0])]
# Check that we can generate a single random draw
draw = rand(d)
@assert length(draw) == dim(d)
# Check that draw satifies insupport()
@assert insupport(d, draw)
# Check that we can generate many random draws at once
X = rand(d, n_samples)
@assert size(X, 1) == dim(d)
# Check that sequence of draws satifies insupport()
@assert insupport(d, X)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment