ReactiveMP.jl icon indicating copy to clipboard operation
ReactiveMP.jl copied to clipboard

Extend logpdf messages with importance distributions

Open ismailsenoz opened this issue 3 years ago • 0 comments

Sometimes we send pdf messages and need to evaluate the expectation statistics of these un-normalized pdf messages. Under the assumption that these messages are integrable, we resort to importance sampling to compute the expectations. Consequently, a user might need to define a function function ReactiveMP.mean_var(p::ReactiveMP.ContinuousMultivariateLogPdf) of this sort. Augmenting the ReactiveMP.ContinuousUnivariateLogPdf with an additional importance distribution would allow us to write a generic function to compute the expectation statistics. Very roughly, the function would look like this.

function ReactiveMP.computeExpectation(T::Function, p::ReactiveMP.ContinuousMultivariateLogPdf)
    nsamples               = p.no_samples
    importancedistribution = p.importance_distribution
    modifiedpdf            = (x) -> exp(p.logdpdf(x) - importancedistribution.logpdf(x))
    samples                = rand(importancedistribution, nsamples)
    weights                = computeWeights(modifiedpdf, samples)
    statistics             = sum(weights .* T.(samples))
    
    return statistics
end

ismailsenoz avatar Jan 30 '23 10:01 ismailsenoz