Skip to content

Commit

Permalink
Fix entropy of Dirichlet (#1271)
Browse files Browse the repository at this point in the history
  • Loading branch information
devmotion authored Feb 13, 2021
1 parent 863844c commit f409cfe
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
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

2 comments on commit f409cfe

@andreasnoack
Copy link
Member

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/30008

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.24.13 -m "<description of version>" f409cfe274c2cb554275f20c08b4d543d795af39
git push origin v0.24.13

Please sign in to comment.