ReactiveMP.jl
ReactiveMP.jl copied to clipboard
Extend logpdf messages with importance distributions
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