Skip to content

Commit

Permalink
Merge pull request #215 from ReactiveBayes/DirichletTensor
Browse files Browse the repository at this point in the history
Fix bug on `isproper `of MatrixDirichlet
  • Loading branch information
wouterwln authored Oct 23, 2024
2 parents 0012b50 + a40f396 commit 4ac105d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/distributions/matrix_dirichlet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ end
# Natural parametrization

isproper(::NaturalParametersSpace, ::Type{MatrixDirichlet}, η, conditioner) =
isnothing(conditioner) && length(η) > 1 && typeof(isqrt(length(η))) <: Integer && all(isless.(-1, η)) && all(!isinf, η) && all(!isnan, η)
isnothing(conditioner) && length(η) > 1 && all(isless.(-1, η)) && all(!isinf, η) && all(!isnan, η)
isproper(::MeanParametersSpace, ::Type{MatrixDirichlet}, θ, conditioner) =
isnothing(conditioner) && length(θ) > 1 && typeof(isqrt(length(θ))) <: Integer && all(>(0), θ) && all(!isinf, θ) && all(!isnan, θ)
isnothing(conditioner) && length(θ) > 1 &&all(>(0), θ) && all(!isinf, θ) && all(!isnan, θ)

function (::MeanToNatural{MatrixDirichlet})(tuple_of_θ::Tuple{Any})
(α,) = tuple_of_θ
Expand Down
7 changes: 3 additions & 4 deletions test/distributions/matrix_dirichlet_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,14 @@ end
end

for space in (MeanParametersSpace(), NaturalParametersSpace())
@test !isproper(space, MatrixDirichlet, [Inf Inf; Inf 1.0], 1.0)
@test !isproper(space, MatrixDirichlet, [Inf Inf; Inf 1.0])
@test !isproper(space, MatrixDirichlet, [1.0], Inf)
@test !isproper(space, MatrixDirichlet, [NaN], 1.0)
@test !isproper(space, MatrixDirichlet, [NaN],)
@test !isproper(space, MatrixDirichlet, [1.0], NaN)
@test !isproper(space, MatrixDirichlet, [0.5, 0.5], 1.0)
@test isproper(space, MatrixDirichlet, [2.0, 3.0])
@test !isproper(space, MatrixDirichlet, [-1.0, -1.2])
end

end
@test_throws Exception convert(ExponentialFamilyDistribution, MatrixDirichlet([Inf Inf; 2 3]))
end

Expand Down

0 comments on commit 4ac105d

Please sign in to comment.