From 42a68a7a26eb37c626fb7467fec7ce5e0354e6f3 Mon Sep 17 00:00:00 2001 From: Mykola Lukashchuk Date: Mon, 12 Aug 2024 16:09:21 +0200 Subject: [PATCH 1/4] feat: add InverseGamma natural manifold --- src/ExponentialFamilyManifolds.jl | 1 + src/natural_manifolds/inverse_gamma.jl | 19 +++++++++++++++++++ test/natural_manifolds/gamma_inverse_tests.jl | 7 +++++++ 3 files changed, 27 insertions(+) create mode 100644 src/natural_manifolds/inverse_gamma.jl create mode 100644 test/natural_manifolds/gamma_inverse_tests.jl diff --git a/src/ExponentialFamilyManifolds.jl b/src/ExponentialFamilyManifolds.jl index 2a82cad..5a38fa0 100644 --- a/src/ExponentialFamilyManifolds.jl +++ b/src/ExponentialFamilyManifolds.jl @@ -16,6 +16,7 @@ include("natural_manifolds/categorical.jl") include("natural_manifolds/dirichlet.jl") include("natural_manifolds/exponential.jl") include("natural_manifolds/gamma.jl") +include("natural_manifolds/inverse_gamma.jl") include("natural_manifolds/geometric.jl") include("natural_manifolds/laplace.jl") include("natural_manifolds/lognormal.jl") diff --git a/src/natural_manifolds/inverse_gamma.jl b/src/natural_manifolds/inverse_gamma.jl new file mode 100644 index 0000000..816f771 --- /dev/null +++ b/src/natural_manifolds/inverse_gamma.jl @@ -0,0 +1,19 @@ +""" + get_natural_manifold_base(::Type{Gamma}, ::Tuple{}, conditioner=nothing) + +Get the natural manifold base for the `Gamma` distribution. +""" +function get_natural_manifold_base(::Type{ExponentialFamily.GammaInverse}, ::Tuple{}, conditioner=nothing) + return ProductManifold( + ShiftedNegativeNumbers(static(-1)), ShiftedNegativeNumbers(static(0)) + ) +end + +""" + partition_point(::Type{Gamma}, ::Tuple{}, p, conditioner=nothing) + +Converts the `point` to a compatible representation for the natural manifold of type `Gamma`. +""" +function partition_point(::Type{ExponentialFamily.GammaInverse}, ::Tuple{}, p, conditioner=nothing) + return ArrayPartition(view(p, 1:1), view(p, 2:2)) +end \ No newline at end of file diff --git a/test/natural_manifolds/gamma_inverse_tests.jl b/test/natural_manifolds/gamma_inverse_tests.jl new file mode 100644 index 0000000..6bbd8bf --- /dev/null +++ b/test/natural_manifolds/gamma_inverse_tests.jl @@ -0,0 +1,7 @@ +@testitem "Check `GammaInverse` natural manifold" begin + include("natural_manifolds_setuptests.jl") + + test_natural_manifold() do rng + return InverseGamma(10rand(rng), 10rand(rng)) + end +end \ No newline at end of file From a7ef874530cbda6a14b2db00620e296bd62d70f6 Mon Sep 17 00:00:00 2001 From: Mykola Lukashchuk Date: Mon, 12 Aug 2024 16:16:10 +0200 Subject: [PATCH 2/4] fix: use InverseGamma from ExponentialFamily --- test/natural_manifolds/gamma_inverse_tests.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/natural_manifolds/gamma_inverse_tests.jl b/test/natural_manifolds/gamma_inverse_tests.jl index 6bbd8bf..37c86b1 100644 --- a/test/natural_manifolds/gamma_inverse_tests.jl +++ b/test/natural_manifolds/gamma_inverse_tests.jl @@ -2,6 +2,6 @@ include("natural_manifolds_setuptests.jl") test_natural_manifold() do rng - return InverseGamma(10rand(rng), 10rand(rng)) + return ExponentialFamily.InverseGamma(10rand(rng), 10rand(rng)) end end \ No newline at end of file From 9e6fdc78a7684159492169529d8cb578a88458f0 Mon Sep 17 00:00:00 2001 From: Mykola Lukashchuk Date: Mon, 12 Aug 2024 16:22:15 +0200 Subject: [PATCH 3/4] docs: fix doc for GammaInverse --- src/natural_manifolds/inverse_gamma.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/natural_manifolds/inverse_gamma.jl b/src/natural_manifolds/inverse_gamma.jl index 816f771..6af87b0 100644 --- a/src/natural_manifolds/inverse_gamma.jl +++ b/src/natural_manifolds/inverse_gamma.jl @@ -1,7 +1,7 @@ """ - get_natural_manifold_base(::Type{Gamma}, ::Tuple{}, conditioner=nothing) + get_natural_manifold_base(::Type{GammaInverse}, ::Tuple{}, conditioner=nothing) -Get the natural manifold base for the `Gamma` distribution. +Get the natural manifold base for the `GammaInverse` distribution. """ function get_natural_manifold_base(::Type{ExponentialFamily.GammaInverse}, ::Tuple{}, conditioner=nothing) return ProductManifold( @@ -10,9 +10,9 @@ function get_natural_manifold_base(::Type{ExponentialFamily.GammaInverse}, ::Tup end """ - partition_point(::Type{Gamma}, ::Tuple{}, p, conditioner=nothing) + partition_point(::Type{GammaInverse}, ::Tuple{}, p, conditioner=nothing) -Converts the `point` to a compatible representation for the natural manifold of type `Gamma`. +Converts the `point` to a compatible representation for the natural manifold of type `GammaInverse`. """ function partition_point(::Type{ExponentialFamily.GammaInverse}, ::Tuple{}, p, conditioner=nothing) return ArrayPartition(view(p, 1:1), view(p, 2:2)) From a2c6dedc87ec7f890848e2c580a7cae184f2d031 Mon Sep 17 00:00:00 2001 From: Mykola Lukashchuk Date: Mon, 12 Aug 2024 16:25:51 +0200 Subject: [PATCH 4/4] docs: specify type --- src/natural_manifolds/inverse_gamma.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/natural_manifolds/inverse_gamma.jl b/src/natural_manifolds/inverse_gamma.jl index 6af87b0..67969c0 100644 --- a/src/natural_manifolds/inverse_gamma.jl +++ b/src/natural_manifolds/inverse_gamma.jl @@ -1,7 +1,7 @@ """ - get_natural_manifold_base(::Type{GammaInverse}, ::Tuple{}, conditioner=nothing) + get_natural_manifold_base(::Type{ExponentialFamily.GammaInverse}, ::Tuple{}, conditioner=nothing) -Get the natural manifold base for the `GammaInverse` distribution. +Get the natural manifold base for the `ExponentialFamily.GammaInverse` distribution. """ function get_natural_manifold_base(::Type{ExponentialFamily.GammaInverse}, ::Tuple{}, conditioner=nothing) return ProductManifold( @@ -10,9 +10,9 @@ function get_natural_manifold_base(::Type{ExponentialFamily.GammaInverse}, ::Tup end """ - partition_point(::Type{GammaInverse}, ::Tuple{}, p, conditioner=nothing) + partition_point(::Type{ExponentialFamily.GammaInverse}, ::Tuple{}, p, conditioner=nothing) -Converts the `point` to a compatible representation for the natural manifold of type `GammaInverse`. +Converts the `point` to a compatible representation for the natural manifold of type `ExponentialFamily.GammaInverse`. """ function partition_point(::Type{ExponentialFamily.GammaInverse}, ::Tuple{}, p, conditioner=nothing) return ArrayPartition(view(p, 1:1), view(p, 2:2))