Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix entropy of Dirichlet #1271

Merged
merged 1 commit into from
Feb 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Distributions"
uuid = "31c24e10-a181-5473-b8eb-7969acd0382f"
authors = ["JuliaStats"]
version = "0.24.12"
version = "0.24.13"

[deps]
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
Expand Down
4 changes: 3 additions & 1 deletion src/multivariate/dirichlet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ end

function entropy(d::Dirichlet)
α0 = d.alpha0
en = d.lmnB + (α0 - k) * digamma(α0) - sum(αj -> (αj - 1) * digamma(αj), d.alpha)
α = d.alpha
k = length(d.alpha)
en = d.lmnB + (α0 - k) * digamma(α0) - sum(αj -> (αj - 1) * digamma(αj), α)
return en
end

Expand Down
9 changes: 9 additions & 0 deletions test/dirichlet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,12 @@ rng = MersenneTwister(123)
# @test r.alpha ≈ d.alpha atol=0.25
end
end

@testset "Dirichlet: entropy" begin
α = exp.(rand(2))
@test entropy(Dirichlet(α)) ≈ entropy(Beta(α...))

N = 10
@test entropy(Dirichlet(N, 1)) ≈ -loggamma(N)
@test entropy(Dirichlet(ones(N))) ≈ -loggamma(N)
end
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ using PDMats # test dependencies
using Test
using Distributed
using Random
using SpecialFunctions
using StatsBase
using LinearAlgebra
using HypothesisTests
Expand Down