bat / BAT.jl

A Bayesian Analysis Toolkit in Julia
Other
198 stars 30 forks source link

Fix HierarchicalDistributions w/ dof smaller than length #417

Closed waldie11 closed 1 year ago

waldie11 commented 1 year ago

Only checked the transform in https://github.com/bat/BAT.jl/pull/415 , so now reenable functionality to draw random sample from HierarchicalDistributions / anything calling _hd_split with eff_totalndof ≠ length in primary_dist. No guarantees that there are some calls remaining which should rather work on newly introduced _hd_split_efftotalndof

using BAT
using ValueShapes
using Distributions
using InverseFunctions

d = HierarchicalDistribution(NamedTupleDist(
       a=truncated(Logistic(),0,Inf),
)) do v
       NamedTupleDist(
             b=Dirichlet(10,1/v.a),
       )
end

trafo = BAT.DistributionTransform(Normal,d)
inverse(trafo)(rand(Normal(), BAT.eff_totalndof(d)))

rand(d)
rand(unshaped(d))
trafo(rand(d))
codecov[bot] commented 1 year ago

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.05 :tada:

Comparison is base (4628507) 54.75% compared to head (ff118a3) 54.81%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #417 +/- ## ========================================== + Coverage 54.75% 54.81% +0.05% ========================================== Files 116 116 Lines 5610 5617 +7 ========================================== + Hits 3072 3079 +7 Misses 2538 2538 ``` | [Impacted Files](https://app.codecov.io/gh/bat/BAT.jl/pull/417?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bat) | Coverage Δ | | |---|---|---| | [src/distributions/hierarchical\_distribution.jl](https://app.codecov.io/gh/bat/BAT.jl/pull/417?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bat#diff-c3JjL2Rpc3RyaWJ1dGlvbnMvaGllcmFyY2hpY2FsX2Rpc3RyaWJ1dGlvbi5qbA==) | `82.65% <100.00%> (+1.33%)` | :arrow_up: | | [src/transforms/distribution\_transform.jl](https://app.codecov.io/gh/bat/BAT.jl/pull/417?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bat#diff-c3JjL3RyYW5zZm9ybXMvZGlzdHJpYnV0aW9uX3RyYW5zZm9ybS5qbA==) | `88.91% <100.00%> (ø)` | |

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

waldie11 commented 1 year ago

@oschulz sry for confusing with #416 - only aborted that one as I wanted to have the cleaner commit history possible at that time. the "no guarantees" is also more conservative than necessary, I think :wink:

Iam rather convinced that this should do the job.

oschulz commented 1 year ago

Thanks again! :-)