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

Dirichlet tensor #219

Merged
merged 73 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
93047b2
testTensirDirichlet
Raphael-Tresor Nov 25, 2024
e5e08e3
tensorDirichlet not exponentialFamiliy compatible
Raphael-Tresor Dec 24, 2024
d3b5f1a
Update initialization of out
wouterwln Jan 7, 2025
f244d1c
Ensure all tests are in `testitem` blocks
wouterwln Jan 7, 2025
603d989
testTensirDirichlet
Raphael-Tresor Nov 25, 2024
bfc7466
tensorDirichlet not exponentialFamiliy compatible
Raphael-Tresor Dec 24, 2024
de2e32f
Update initialization of out
wouterwln Jan 7, 2025
6a9df05
Ensure all tests are in `testitem` blocks
wouterwln Jan 7, 2025
d8ccd98
Merge branch 'DirichletTensor' of https://github.com/ReactiveBayes/Ex…
wouterwln Jan 7, 2025
c399f37
Add TensorDirichlet benchmarks
wouterwln Jan 7, 2025
c033071
Add logpdf tests and benchmarks
wouterwln Jan 8, 2025
ff5cf02
Formatting
wouterwln Jan 8, 2025
0977bc3
Refine prod benchmarks
wouterwln Jan 8, 2025
d1bfa07
Update benchmarks
wouterwln Jan 8, 2025
baf0514
Update benchmarks
wouterwln Jan 8, 2025
3e83feb
Reimplement var
wouterwln Jan 8, 2025
b28e67e
Update logpdf tests
wouterwln Jan 8, 2025
1339467
Revise tests
wouterwln Jan 8, 2025
e38405f
Reimplement cov
wouterwln Jan 9, 2025
fd790dd
test_cov
Raphael-Tresor Jan 9, 2025
6a7b028
tests base functions
Raphael-Tresor Jan 9, 2025
6c9d756
Reimplement prod
wouterwln Jan 8, 2025
40f08e2
Update judge benchmarks
wouterwln Jan 8, 2025
78026b8
Speedup logpdf
wouterwln Jan 8, 2025
e43b376
Update benchmarks
wouterwln Jan 8, 2025
678af98
Save alpha0
wouterwln Jan 8, 2025
89dd0ba
reimplement var
wouterwln Jan 9, 2025
bd657cb
Speedup var
wouterwln Jan 9, 2025
2aba23d
Speedup logpdf
wouterwln Jan 9, 2025
2aa166d
Introduce error msg for negative alpha
wouterwln Jan 9, 2025
bcebba4
Make benchmarks robust
wouterwln Jan 9, 2025
159e035
test: unmark broken tests
Nimrais Jan 9, 2025
6160272
Merge pull request #222 from ReactiveBayes/dirichlet-tensor-performance
wouterwln Jan 9, 2025
e506a5d
Fix `std`
wouterwln Jan 9, 2025
2c8bd8c
Add entropy to benchmarks
wouterwln Jan 9, 2025
bbba975
Add out of support case for `logpdf`
wouterwln Jan 9, 2025
85d437a
Reimplement entropy
wouterwln Jan 9, 2025
f38bfe0
Merge pull request #224 from ReactiveBayes/dt_entropy
wouterwln Jan 9, 2025
f94b302
Merge branch 'main' into DirichletTensor
wouterwln Jan 9, 2025
4dcb512
Merge branch 'DirichletTensor' of https://github.com/ReactiveBayes/Ex…
wouterwln Jan 9, 2025
83da858
test rand
Raphael-Tresor Jan 9, 2025
b042beb
docs: they are always independent
Nimrais Jan 9, 2025
0e327fa
fix: mark broken methods
Nimrais Jan 10, 2025
54ef2d6
fix: proper conversion between Mean and Natural spaces
Nimrais Jan 10, 2025
19a9446
fix: implement rand! without extract_collection
Nimrais Jan 10, 2025
3e87207
fix: implement join_conditioner
Nimrais Jan 10, 2025
5791da8
fix: implement NaturalParametersSpace getlogpartition
Nimrais Jan 10, 2025
5253fbe
fix: implement getgradlogpartition for TensorDirichlet
Nimrais Jan 10, 2025
3ac5e68
fix: implement correct BayesBase.insupport
Nimrais Jan 13, 2025
1432769
fix: use generic check_logpdf in _pdf
Nimrais Jan 13, 2025
d50c6d5
fix: implement specific check_logpdf for EF TensorDirichlet
Nimrais Jan 13, 2025
b31c87d
fix: save same unpacked form for natural and mean spaces
Nimrais Jan 13, 2025
4da7225
fix: implement fisher for the natural space
Nimrais Jan 13, 2025
c82eaac
fix: generic unpack needs to use the conditioner
Nimrais Jan 13, 2025
ecd1cdf
fix: make type inference happy
Nimrais Jan 13, 2025
f3ef44a
fix: Pareto unpakcing with conditioner
Nimrais Jan 13, 2025
66601a4
fix: implement logpdf, pdf
Nimrais Jan 13, 2025
4af1f19
test: add nsamples for gradlogpartition test
Nimrais Jan 13, 2025
94bbd82
fix: implement fisher and gradlogpartition for TensorDirichlet
Nimrais Jan 13, 2025
d6e3700
fix: add unpacked methods for conditioned distributions
Nimrais Jan 13, 2025
0784837
test(fix): unpack needs take into account conditioner now
Nimrais Jan 13, 2025
a690ace
test(fix): test_generic_simple_exponentialfamily_product works
Nimrais Jan 13, 2025
410dad6
test: delete wrong test
Nimrais Jan 14, 2025
f8cdeec
Make unpack_parameters non-allocating
wouterwln Jan 14, 2025
6283aa5
Merge branch 'main' into DirichletTensor
Nimrais Jan 14, 2025
f430acf
docs(fix): add TensorDirichlet
Nimrais Jan 14, 2025
b5a43e2
Update docs
wouterwln Jan 14, 2025
336bb8c
Enable conversion benchmarks
wouterwln Jan 14, 2025
3170cef
Update tests for rand
wouterwln Jan 14, 2025
69898b8
Speedup `rand!`
wouterwln Jan 14, 2025
d6e6de6
Fix `logpdf` and fix `rand!`
wouterwln Jan 14, 2025
5bc0e86
Tests for `rand`, `logpdf` and `pdf`
wouterwln Jan 14, 2025
2841038
Update `rand!`
wouterwln Jan 14, 2025
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
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ version = "1.6.0"

[deps]
BayesBase = "b4ee3484-f114-42fe-b91c-797d54a0c67e"
BlockArrays = "8e7c35d0-a365-5155-bbbb-fb81a777f24e"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
DomainSets = "5b8099bc-c8ec-5219-889f-1d9e522a28bf"
FastCholesky = "2d5283b6-8564-42b6-bb00-83ed8e915756"
Expand All @@ -29,6 +30,7 @@ TinyHugeNumbers = "783c9a47-75a3-44ac-a16b-f1ab7b3acf04"
[compat]
Aqua = "0.8.7"
BayesBase = "1.5.0"
BlockArrays = "1.3.0"
Distributions = "0.25"
DomainSets = "0.5.2, 0.6, 0.7"
FastCholesky = "1.0"
Expand Down
3 changes: 2 additions & 1 deletion benchmark/benchmarks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ using ExponentialFamily.BayesBase

const SUITE = BenchmarkGroup()

include("benchmarks/bernoulli.jl")
include("benchmarks/bernoulli.jl")
include("benchmarks/tensordirichlet.jl")
42 changes: 42 additions & 0 deletions benchmark/benchmarks/tensordirichlet.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

SUITE["tensordirichlet"] = BenchmarkGroup(
["tensordirichlet", "distribution"],
"prod" => BenchmarkGroup(["prod", "multiplication"]),
"convert" => BenchmarkGroup(["convert"])
)

# `prod` BenchmarkGroup ========================
for rank in (3, 4, 5, 6)
for d in (5, 10, 20)
left = TensorDirichlet(rand([d for _ in 1:rank]...) .+ 1)
right = TensorDirichlet(rand([d for _ in 1:rank]...) .+ 1)
SUITE["tensordirichlet"]["prod"]["Closed(rank=$rank, d=$d)"] = @benchmarkable prod(ClosedProd(), $left, $right)
end
end

# ==============================================

# `convert` BenchmarkGroup =====================
SUITE["tensordirichlet"]["convert"]["Convert from D to EF"] = @benchmarkable convert(ExponentialFamilyDistribution, dist) setup = begin
dist = TensorDirichlet(rand(5, 5, 5))
end

SUITE["tensordirichlet"]["convert"]["Convert from EF to D"] = @benchmarkable convert(Distribution, efdist) setup = begin
efdist = convert(ExponentialFamilyDistribution, TensorDirichlet(rand(5, 5, 5)))
end
# ==============================================

for rank in (3, 4, 5, 6)
for d in (5, 10, 20)
distribution = TensorDirichlet(rand([d for _ in 1:rank]...))
sample = rand(distribution)
SUITE["tensordirichlet"]["mean"]["rank=$rank, d=$d"] = @benchmarkable mean($distribution)
SUITE["tensordirichlet"]["rand"]["rank=$rank, d=$d"] = @benchmarkable rand($distribution)
SUITE["tensordirichlet"]["logpdf"]["rank=$rank, d=$d"] = @benchmarkable logpdf($distribution, $sample)
SUITE["tensordirichlet"]["var"]["rank=$rank, d=$d"] = @benchmarkable var($distribution)
SUITE["tensordirichlet"]["cov"]["rank=$rank, d=$d"] = @benchmarkable cov($distribution)
SUITE["tensordirichlet"]["entropy"]["rank=$rank, d=$d"] = @benchmarkable entropy($distribution)
end
end

# ==============================================
1 change: 1 addition & 0 deletions docs/src/library.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ ExponentialFamily.WishartFast
ExponentialFamily.InverseWishartFast
ExponentialFamily.NormalGamma
ExponentialFamily.MvNormalWishart
ExponentialFamily.TensorDirichlet
```
4 changes: 2 additions & 2 deletions scripts/benchmark.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ if isempty(ARGS)
export_markdown("./benchmark_logs/last.md", result)
else
name = first(ARGS)
BenchmarkTools.judge(ExponentialFamily, name; judgekwargs = Dict(:time_tolerance => 0.1, :memory_tolerance => 0.05))
export_markdown("benchmark_vs_$(name)_result.md", result)
result = BenchmarkTools.judge(ExponentialFamily, name; judgekwargs = Dict(:time_tolerance => 0.1, :memory_tolerance => 0.05))
export_markdown("./benchmark_logs/benchmark_vs_$(name)_result.md", result)
end
1 change: 1 addition & 0 deletions src/ExponentialFamily.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,6 @@ include("distributions/poisson.jl")
include("distributions/chi_squared.jl")
include("distributions/mv_normal_wishart.jl")
include("distributions/normal_gamma.jl")
include("distributions/tensor_dirichlet.jl")

end
4 changes: 4 additions & 0 deletions src/distributions/binomial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ function (::NaturalToMean{Binomial})(tuple_of_η::Tuple{Any}, _)
return (logistic(η₁),)
end

function unpack_parameters(::Type{Binomial}, packed, _)
return unpack_parameters(Binomial, packed)
end

function unpack_parameters(::Type{Binomial}, packed)
return (first(packed),)
end
Expand Down
4 changes: 4 additions & 0 deletions src/distributions/categorical.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ function (::NaturalToMean{Categorical})(tuple_of_η::Tuple{V}, _) where {V <: Ab
return (softmax(convert(Vector, η)),)
end

function unpack_parameters(::Type{Categorical}, packed, _)
return unpack_parameters(Categorical, packed)
end

function unpack_parameters(::Type{Categorical}, packed)
return (packed,)
end
Expand Down
4 changes: 4 additions & 0 deletions src/distributions/laplace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ function (::NaturalToMean{Laplace})(tuple_of_η::Tuple{Any}, _)
return (-inv(η₁),)
end

function unpack_parameters(::Type{Laplace}, packed, _)
return (first(packed),)
end

function unpack_parameters(::Type{Laplace}, packed)
return (first(packed),)
end
Expand Down
4 changes: 4 additions & 0 deletions src/distributions/negative_binomial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ function (::NaturalToMean{NegativeBinomial})(tuple_of_η::Tuple{Any}, _)
return (one(η₁) - exp(η₁),)
end

function unpack_parameters(::Type{NegativeBinomial}, packed, _)
return (first(packed),)
end

function unpack_parameters(::Type{NegativeBinomial}, packed)
return (first(packed),)
end
Expand Down
4 changes: 4 additions & 0 deletions src/distributions/pareto.jl
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ function (::NaturalToMean{Pareto})(tuple_of_η::Tuple{Any}, _)
return (-η₁ - one(η₁),)
end

function unpack_parameters(::Type{Pareto}, packed, _)
return (first(packed),)
end

function unpack_parameters(::Type{Pareto}, packed)
return (first(packed),)
end
Expand Down
Loading
Loading