Inference results postprocessing

infer allow users to postprocess the inference result with the postprocess = ... keyword argument. The inference engine operates on wrapper types to distinguish between marginals and messages. By default these wrapper types are removed from the inference results if no addons option is present. Together with the enabled addons, however, the wrapper types are preserved in the inference result output value. Use the options below to change this behaviour:

inference_postprocess(strategy, result)

This function modifies the result of the inference procedure according to the strategy. The result can be a Marginal or a collection of Marginals. The default strategy is DefaultPostprocess.


Custom postprocessing step

In order to implement a custom postprocessing strategy simply implement the inference_postprocess method:

using RxInfer

struct CustomPostprocess end

# For demonstration purposes out postprocessing step simply stringifyes the result
RxInfer.inference_postprocess(::CustomPostprocess, result::Marginal) = string(ReactiveMP.getdata(result))

Now, we can use the postprocessing step in the infer function:

@model function beta_bernoulli(y)
    θ ~ Beta(1, 1)
    y ~ Bernoulli(θ)

result = infer(
    model = beta_bernoulli(),
    data  = (y = 1.,),
    postprocess = CustomPostprocess()

result.posteriors[:θ] # should be a `String`
"Beta{Float64}(α=2.0, β=1.0)"
result.posteriors[:θ] isa String