ReactiveBayes / ReactiveBayes/ExponentialFamilyProjection.jl
[MEDIUM] `ClosedFormStrategy` throws `MethodError` for variational families with a non-constant base measure
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 11
- Forks
- 1
- PR merge metrics
- No merged PRs in 30d
Description
[MEDIUM] ClosedFormStrategy throws MethodError for variational families with a non-constant base measure
Summary
ClosedFormStrategy (extension ClosedFormExpectationsExt) implements the exact-gradient (Williams-product) path, but its base-measure correction only has a method for ConstantBaseMeasure. Any variational family whose base measure is not constant (current ExponentialFamily.jl families: Poisson, Chisq, Binomial, Rayleigh, Weibull, NegativeBinomial) hits a MethodError during gradient computation.
Evidence
ext/ClosedFormExpectationsExt/ClosedFormExpectationsExt.jl:
- lines 18-25 define
logbasemeasure_correction(::ClosedFormStrategy, ::ConstantBaseMeasure, ...)— the only method. compute_gradient!(lines 55-60) calls:
logbasemeasure_correction(strategy, ExponentialFamily.isbasemeasureconstant(q_dist), q_dist, grad_target).
Verified (Julia 1.12.6, ClosedFormExpectations 0.4.1):
methods(ClosedFormExpectationsExt.logbasemeasure_correction)returns exactly one method (ConstantBaseMeasure).- Calling with
ExponentialFamily.NonConstantBaseMeasure()throwsMethodError. isbasemeasureconstant(convert(ExponentialFamilyDistribution, Poisson(3))) == NonConstantBaseMeasure()(alsoChisq,Rayleigh,Binomial).
The docstring (src/strategies/closed_form.jl) states the strategy computes exact gradients for the target–variational pair with no caveat; this is only true for constant-base-measure families.
Root cause
The mathematical cancellation the comment relies on (E_q[(log p̃ - log h_q)(T-μ)], where the log h_q term vanishes because E_q[T] = μ) is only valid for a constant base measure. There is no implementation (and no explicit error) for the non-constant case.
Suggested direction
Either implement the -E_q[log h_q (T-μ)] correction for NonConstantBaseMeasure, or — until then — throw a clear, informative error from compute_gradient! when the variational q_dist has a non-constant base measure, rather than an opaque MethodError.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in ext/ClosedFormExpectationsExt/ClosedFormExpectationsExt.jl by reading logbasemeasure_correction and compute_gradient!, then compare their handling of ConstantBaseMeasure and NonConstantBaseMeasure. Decide which suggested behavior is appropriate, verify gradient computation no longer produces an opaque MethodError, and update the src/strategies/closed_form.jl docstring if the strategy remains limited.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100