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 68fbd99c authored by John Myles White's avatar John Myles White

Added a multivariate normal distribution

parent 2cba2ea4
......@@ -24,6 +24,7 @@ export # types
logNormal,
MixtureModel,
Multinomial,
MultivariateNormal,
NegativeBinomial,
NoncentralBeta,
NoncentralChisq,
......@@ -765,6 +766,33 @@ function rand(d::MixtureModel)
rand(d.components[i])
end
type MultivariateNormal <: Distribution
mean::Vector{Float64}
cov::Matrix{Float64}
sqrt_cov::Matrix{Float64}
function MultivariateNormal(m, c, s)
if length(m) == size(c, 1) == size(c, 2) == size(s, 1) == size(s, 2)
new(m, c, s)
else
error("Dimensions of mean and covariance do not match")
end
end
end
function MultivariateNormal(mean::Vector{Float64}, cov::Matrix{Float64})
MultivariateNormal(mean, cov, chol(cov)') #'
end
function MultivariateNormal(mean::Vector{Float64})
MultivariateNormal(mean, eye(length(mean)))
end
MultivariateNormal() = MultivariateNormal(zeros(2), eye(2))
mean(d::MultivariateNormal) = d.mean
function rand(d::MultivariateNormal)
z = randn(length(d.mean))
return d.mean + d.sqrt_cov * z
end
var(d::MultivariateNormal) = d.cov
## NegativeBinomial is the distribution of the number of failures
## before the size'th success in a sequence of Bernoulli trials.
## We do not enforce integer size, as the distribution is well defined
......
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