-
Notifications
You must be signed in to change notification settings - Fork 2
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
Implement gradlogpartition for Exponential Family Distributions #149
Conversation
add getgradlogpartition Exponential
add getgradlogpartition function for Poisson
add getgradlogpartition function for Bernoulli
Add gradient of binomial
Add gradient of beta
biaslab to reactivebayes
Add gradient of Erlang
@bvdmitri, I believe this PR is now ready for review. Please note that the Contingency, Multinomial, and Continuous Bernoulli distributions will not be implemented in this PR. This is because we currently lack comprehensive functionality for them, and they haven’t been added to the package yet. I’ve suppressed the test for MvNormalWishart. This is because, first, we need to implement its variate type, I believe. Subsequently, we should refactor this PR with its The only issue I foresee is with the MatrixDirichlet. Sampling for it seems to be numerically problematic. Perhaps we could choose a non-random point for evaluation as a workaround? |
@bvdmitri @ismailsenoz The problem is completely numerical as I see for |
@Nimrais can you provide a MWE? My very simple thus naive test does not produce julia> any(iszero, rand(Beta(2, 7), 1000000))
false
julia> any(sample -> sample ≈ 0, rand(Beta(2, 7), 1000000))
false |
julia> rand(Beta(0.001, 10), 1000)
1000-element Vector{Float64}:
2.501697090499602e-61
1.5363386828054128e-117
0.0
2.2934573763809164e-19
0.0
5.025249983628666e-188
3.5214471095207316e-46
⋮
1.2648082681768658e-96
0.0
8.892674549717065e-308
4.820971913271643e-100
0.0
5.115976241095818e-165
0.0 |
You can check our Direchlet test distributions, some marginal of them are pretty close to ill-behaved Betas, one parameter is super small and another is big. |
Got it! Lets address this in a separate issue |
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #149 +/- ##
==========================================
+ Coverage 79.77% 80.21% +0.44%
==========================================
Files 39 39
Lines 2887 3094 +207
==========================================
+ Hits 2303 2482 +179
- Misses 584 612 +28 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I trust the tests, didn't check the actual math. Well done guys!!!
This PR aims to close issue #130: it implements
getgradlogpartition
for exponential family distribution types fromDistributions.jl
Derivations to do this feature we already prepared.
To test new functionality a new type of test for the exponential family interface was added:
test_gradlogpartion_against_expectation
. Based on the fact that expectation of the sufficient statistics is equal to the gradient of the logpartition:However the straightforward check would be to long to run:
can be generically approximated with a monte-carlo estimator
but this estimator is too slow to converge for the testing purposes.
So another with a faster convergence rate (the linear convergence rate)
is used and a sanity check that dimensionality of the gradient and the natural parameters are the same.
Tasks to do:
So please open a PR with
getgradlogpartition
for your type implemented into this branch.