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

Add manifold for Categorical distribution #15

Merged
merged 17 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions src/ExponentialFamilyManifolds.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ include("natural_manifolds/bernoulli.jl")
include("natural_manifolds/beta.jl")
include("natural_manifolds/binomial.jl")
include("natural_manifolds/chisq.jl")
include("natural_manifolds/categorical.jl")
include("natural_manifolds/dirichlet.jl")
include("natural_manifolds/exponential.jl")
include("natural_manifolds/gamma.jl")
Expand Down
19 changes: 19 additions & 0 deletions src/natural_manifolds/categorical.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

"""
get_natural_manifold_base(::Type{Categorical}, dims::Tuple{Int}, conditioner=nothing)

Get the natural manifold base for the `Categorical` distribution.
"""
function get_natural_manifold_base(::Type{Categorical}, ::Tuple{}, conditioner=nothing)
return Euclidean(conditioner)
Nimrais marked this conversation as resolved.
Show resolved Hide resolved
end

"""
partition_point(::Type{Categorical}, dims::Tuple{Int}, p, conditioner=nothing)

Converts the `point` to a compatible representation for the natural manifold of type `Categorical`.
"""
function partition_point(::Type{Categorical}, ::Tuple{}, p, conditioner=nothing)
# See comment in `get_natural_manifold_base` for `Categorical`
return ArrayPartition(p)
end
9 changes: 9 additions & 0 deletions test/natural_manifolds/categorical_tests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@testitem "Check `Categorical` natural manifold" begin
include("natural_manifolds_setuptests.jl")

test_natural_manifold() do rng
p = rand(rng, 10)
normalize!(p, 1)
return Categorical(p)
end
end
Loading