Pick the value from a result

Here is a solution of a Bayesian inference using RxInfer:

``````julia> result
Inference results:
Posteriors       | available for (i_β)

julia> result.posteriors
Dict{Symbol, Vector{Dirichlet{Float64, Vector{Float64}, Float64}}} with 1 entry:
:i_β => [Dirichlet{Float64, Vector{Float64}, Float64}(alpha=[…

julia> result.posteriors[:i_β][1]
Dirichlet{Float64, Vector{Float64}, Float64}(alpha=[0.01559091258256351, 0.20785569702925843, 1.0099435968993862])

julia> result.posteriors[:i_β][1].alpha
3-element Vector{Float64}:
0.01559091258256351
0.20785569702925843
1.0099435968993862

julia> result.posteriors[:i_β][1].alpha[1]
0.01559091258256351
``````

Too tedious to get the value wanted, any convenient method?

Not as far as I know.

If the posterior of `i_β` is always a `Dirichlet` (or any other distribution with an `alpha` vector parameter) then you can define a helper function

``````function get_alpha(result, index, element)
return result.posteriors[:i_β][index].alpha[element]
end
``````

and call it with `alpha_value = get_alpha(result, 1, 1)`.

RxInfer.jl uses Distributions.jl, so if you want easy access to parameters of distributions like a Dirichlet, you have to open an issue there.

1 Like