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 961e8a8d by Dahua Lin

### add multiple constructors of MvNormal

parent 999fb23b
 ... ... @@ -54,6 +54,7 @@ export # types MixtureModel, Multinomial, MultivariateNormal, MvNormal, NegativeBinomial, NoncentralBeta, NoncentralChisq, ... ... @@ -110,6 +111,7 @@ export # types mean, # mean of distribution median, # median of distribution mgf, # moment generating function mode, # the mode of a unimodal distribution modes, # mode(s) of distribution as vector moment, # moments of distribution # mueta, # derivative of inverse link function ... ... @@ -131,7 +133,7 @@ export # types import Base.mean, Base.median, Base.quantile, Base.max, Base.min import Base.rand, Base.std, Base.var, Base.cor, Base.cov import Base.show, Base.sprand import NumericExtensions.entropy import NumericExtensions.dim, NumericExtensions.entropy import Stats.kurtosis, Stats.skewness, Stats.modes abstract Distribution ... ...
 ... ... @@ -8,7 +8,7 @@ end function MultivariateNormal{Cov<:AbstractPDMat}(μ::Vector{Float64}, Σ::Cov) d = length(μ) if dim(Σ) != (d, d) if dim(Σ) != d throw(ArgumentError("The dimensions of μ and Σ are inconsistent.")) end MultivariateNormal{Cov}(d, μ, Σ) ... ... @@ -19,8 +19,13 @@ 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}, Σ::Matrix{Float64}) = MultivariateNormal(μ, PDMat(Σ)) const MvNormal = MultivariateNormal # Basic statistics dim(d::MvNormal) = d.dim ... ... @@ -40,4 +45,5 @@ modes(d::MvNormal) = [mode(d)] entropy(d::MvNormal) = 0.5 * (log2π + 1.0 + logdet_cov(d)) # PDF evaluation
test/mvnormal.jl 0 → 100644
 # Tests on Multivariate Normal distributions using NumericExtensions using Distributions using Base.Test ##### construction, basic properties, and evaluation mu = rand(3) va = [1.2, 3.4, 2.6] C = [4. -2. -1.; -2. 5. -1.; -1. -1. 6.] x1 = rand(3) x = rand(3, 100) # SGauss g = MvNormal(mu, 2.0) @test isa(g, MvNormal{ScalMat}) @test dim(g) == 3 @test mean(g) == mode(g) == mu @test cov(g) == diagm(fill(2.0, 3)) # DGauss g = MvNormal(mu, va) @test isa(g, MvNormal{PDiagMat}) @test dim(g) == 3 @test mean(g) == mode(g) == mu @test cov(g) == diagm(va) # Gauss g = MvNormal(mu, C) @test isa(g, MvNormal{PDMat}) @test dim(g) == 3 @test mean(g) == mode(g) == mu @test cov(g) == C
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!