Skip to content

Commit

Permalink
Corrected logpdf for MultivariateNormal
Browse files Browse the repository at this point in the history
  • Loading branch information
lindahua committed Feb 25, 2013
1 parent ba90c2f commit 19d958e
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Distributions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1055,8 +1055,9 @@ function rand!(d::MultivariateNormal, X::Matrix)
end
function logpdf{T <: Real}(d::MultivariateNormal, x::Vector{T})
k = length(d.mean)
z = d.covchol.LR \ (x - d.mean)
return -0.5 * k * log(2.0pi) - sum(log(diag(d.covchol.LR))) - 0.5 * dot(z,z)
u = x - d.mean
z = d.covchol.LR \ u
return -0.5 * k * log(2.0pi) - sum(log(diag(d.covchol.LR))) - 0.5 * dot(u,z)
end
pdf{T <: Real}(d::MultivariateNormal, x::Vector{T}) = exp(logpdf(d, x))
function cdf{T <: Real}(d::MultivariateNormal, x::Vector{T})
Expand Down

1 comment on commit 19d958e

@lindahua
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a fix to issue #19

The original error is dot(z, z) with z = cov \ (x - mean). The correct way should be dot(x - mean, cov \ (x - mean)). Of course, x - mean should be pre-computed.

Please sign in to comment.