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 0be4cc2f authored by Dahua Lin's avatar Dahua Lin

Changed constructor interface + exposing sqmahal

parent 4d80544b
......@@ -109,6 +109,8 @@ export # types
logpdf!, # evaluate log pdf to provided storage
logpmf, # log probability mass
logpmf!, # evaluate log pmf to provided storage
sqmahal, # squared Mahalanobis distance to Gaussian center
sqmahal!, # inplace evaluation of sqmahal
mean, # mean of distribution
median, # median of distribution
mgf, # moment generating function
......
......@@ -19,8 +19,8 @@ function MultivariateNormal{Cov<:AbstractPDMat}(Σ::Cov)
MultivariateNormal{Cov}(d, zeros(d), Σ)
end
MultivariateNormal(μ::Vector{Float64}, σ2::Float64) = MultivariateNormal(μ, ScalMat(length(μ), σ2))
MultivariateNormal(μ::Vector{Float64}, σ2::Vector{Float64}) = MultivariateNormal(μ, PDiagMat(σ2))
MultivariateNormal(μ::Vector{Float64}, σ::Float64) = MultivariateNormal(μ, ScalMat(length(μ), abs2(σ)))
MultivariateNormal(μ::Vector{Float64}, σ::Vector{Float64}) = MultivariateNormal(μ, PDiagMat(abs2(σ)))
MultivariateNormal(μ::Vector{Float64}, Σ::Matrix{Float64}) = MultivariateNormal(μ, PDMat(Σ))
const MvNormal = MultivariateNormal
......
......@@ -19,21 +19,21 @@ x = rand(3, 100)
# SGauss
gs = MvNormal(mu, 2.0)
gs = MvNormal(mu, sqrt(2.0))
@test isa(gs, MvNormal{ScalMat})
@test dim(gs) == 3
@test mean(gs) == mode(gs) == mu
@test cov(gs) == diagm(fill(2.0, 3))
@test_approx_eq cov(gs) diagm(fill(2.0, 3))
@test var(gs) == diag(cov(gs))
@test_approx_eq entropy(gs) 0.5 * logdet(2π * e * cov(gs))
# DGauss
gd = MvNormal(mu, va)
gd = MvNormal(mu, sqrt(va))
@test isa(gd, MvNormal{PDiagMat})
@test dim(gd) == 3
@test mean(gd) == mode(gd) == mu
@test cov(gd) == diagm(va)
@test_approx_eq cov(gd) diagm(va)
@test var(gd) == diag(cov(gd))
@test_approx_eq entropy(gd) 0.5 * logdet(2π * e * cov(gd))
......
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