Skip to content

Commit bc5dbac

Browse files
committed
Fix mode of LKJCholesky and define mean(::LKJCholesky)
1 parent 957f0c0 commit bc5dbac

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "Distributions"
22
uuid = "31c24e10-a181-5473-b8eb-7969acd0382f"
33
authors = ["JuliaStats"]
4-
version = "0.25.116"
4+
version = "0.25.117"
55

66
[deps]
77
AliasTables = "66dad0bd-aa9a-41b7-9441-69ab47430ed8"

src/cholesky/lkjcholesky.jl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,20 @@ function insupport(d::LKJCholesky, R::LinearAlgebra.Cholesky)
109109
return true
110110
end
111111

112-
function StatsBase.mode(d::LKJCholesky)
112+
function StatsBase.mean(d::LKJCholesky)
113113
factors = Matrix{eltype(d)}(LinearAlgebra.I, size(d))
114114
return LinearAlgebra.Cholesky(factors, d.uplo, 0)
115115
end
116116

117+
function mode(d::LKJCholesky; check_args::Bool=true)
118+
@check_args(
119+
LKJCholesky,
120+
@setup= d.η),
121+
(η, η > 1, "mode is defined only when η > 1."),
122+
)
123+
return mean(d)
124+
end
125+
117126
StatsBase.params(d::LKJCholesky) = (d.d, d.η, d.uplo)
118127

119128
@inline partype(::LKJCholesky{T}) where {T <: Real} = T

test/cholesky/lkjcholesky.jl

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,25 @@ using FiniteDifferences
124124
end
125125

126126
@testset "properties" begin
127-
@testset for p in (4, 5), η in (2, 3.5), uplo in ('L', 'U')
127+
@testset for p in (4, 5), η in (0.5, 2, 3.5), uplo in ('L', 'U')
128128
d = LKJCholesky(p, η, uplo)
129129
@test d.d == p
130130
@test size(d) == (p, p)
131131
@test Distributions.params(d) == (d.d, d.η, d.uplo)
132132
@test partype(d) <: Float64
133133

134-
m = mode(d)
134+
if η > 1
135+
m = mode(d)
136+
@test m isa Cholesky{eltype(d)}
137+
@test Matrix(m) I
138+
else
139+
@test_throws "DomainError with :\nLKJCholesky: mode is defined only when η > 1." mode(d)
140+
end
141+
m = mode(d; check_args = false)
142+
@test m isa Cholesky{eltype(d)}
143+
@test Matrix(m) I
144+
145+
m = mean(d)
135146
@test m isa Cholesky{eltype(d)}
136147
@test Matrix(m) I
137148
end

0 commit comments

Comments
 (0)