Skip to content

Commit

Permalink
Fix multivariate log likelihood refactor (#594)
Browse files Browse the repository at this point in the history
Also bump PDMats requirement
  • Loading branch information
ararslan authored Apr 19, 2017
1 parent 7c399b6 commit a6db77a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
julia 0.5
PDMats 0.5.4
PDMats 0.6.0
StatsFuns 0.3.1
Calculus
StatsBase 0.8.3
Expand Down
2 changes: 1 addition & 1 deletion src/multivariates.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ end

function loglikelihood(d::MultivariateDistribution, X::AbstractMatrix)
size(X, 1) == length(d) || throw(DimensionMismatch("Inconsistent array dimensions."))
return sum(x -> _logpdf(d, x), X, 2)
return sum(i -> _logpdf(d, view(X, :, i)), 1:size(X, 2))
end

##### Specific distributions #####
Expand Down
3 changes: 3 additions & 0 deletions test/mvnormal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ function test_mvnormal(g::AbstractMvNormal, n_tsamples::Int=10^6)
@test logpdf(g, X[:,i]) lp[i]
end
@test logpdf(g, X) lp

# log likelihood
@test loglikelihood(g, X) sum([Distributions._logpdf(g, X[:,i]) for i in 1:size(X, 2)])
end


Expand Down

0 comments on commit a6db77a

Please sign in to comment.