-
Notifications
You must be signed in to change notification settings - Fork 14
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
Fix gamma mixture #222
Fix gamma mixture #222
Conversation
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
@@ -13,7 +13,7 @@ convenient functions to generate samples and weights to approximate expectations | |||
- `rng`: random number generator objects | |||
- `nsamples`: number of samples generated by default | |||
""" | |||
struct ImportanceSamplingApproximation{T, R} | |||
struct ImportanceSamplingApproximation{T, R} <: AbstractFormConstraint |
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.
The ImportanceSamplingApproximation
should not be declared as an AbstractFormConstraint
. This is wrong from the semantic point of view. There should be an extra MomentsApproximationFormConstraint
(or something similar).
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.
|
||
a = m^2 / v | ||
b = m / v | ||
return GammaShapeRate(a, b) |
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.
This should be changed somehow
|
||
constrain_form(::ImportanceSamplingApproximation, distribution::Any) = distribution | ||
|
||
make_form_constraint(::Type{ImportanceSamplingApproximation}, args...; kwargs...) = |
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.
This should be removed in favor of separate MomentsApproximationFormConstraint
@@ -65,3 +65,7 @@ end | |||
|
|||
Distributions.pdf(dist::GammaShapeRate, x::Real) = (rate(dist)^shape(dist)) / gamma(shape(dist)) * x^(shape(dist) - 1) * exp(-rate(dist) * x) | |||
Distributions.logpdf(dist::GammaShapeRate, x::Real) = shape(dist) * log(rate(dist)) - loggamma(shape(dist)) + (shape(dist) - 1) * log(x) - rate(dist) * x | |||
|
|||
function Random.rand(rng::AbstractRNG, dist::GammaShapeRate) |
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.
Lets also add more rand
methods (which accepts size and inplace versions).
@average_energy GammaShapeRate (q_out::Any, q_α::GammaDistributionsFamily, q_β::Any) = begin | ||
mean(loggamma, q_α) - mean(q_α) * mean(log, q_β) - (mean(q_α) - 1.0) * mean(log, q_out) + mean(q_β) * mean(q_out) | ||
end | ||
@average_energy GammaShapeRate (q_out::Any, q_α::Union{PointMass, SampleList, GammaDistributionsFamily}, q_β::Any) = |
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 wonder if can simply put Any
there
Initially, this PR aimed to solve #84.
It enables importance sampling for the
shape
parameters of the Gamma Mixture node (see supporting notebook onGamma Mixture
).We have filled in the missing functions for
ImportanceSamplingApproximation
.We have added the missing
rand
function for theGammaShapeRate
type.Average energy functions for
GammaShapeRate
were fused into a single function.