Skip to content

Handling loops in variational message passing algorithm. #98

Open
@albertpod

Description

@albertpod

I am trying to build the inference algorithm in the coupled random walk model:

Screenshot 2020-07-08 at 12 54 57

We assume the following factorization: q = PosteriorFactorization(x_0, x, γ_x, w_0, w, γ_w)
However, ForneyLab throws an error when calling variationalAlgorithm(q, free_energy=false) due to the loop (green edges):
ArgumentError: The input graph contains a loop around Interface 2 (m) of GaussianMeanPrecision gaussianmeanprecision_3

In my opinion, if the loop occurs, ForneyLab should still be able to build the algorithm, but the user would have to provide a schedule.

Here is the code snippet:

using ForneyLab

n_samples = 2

fg = FactorGraph()

# Hidden process model
@RV x_0 ~ GaussianMeanVariance(placeholder(:m_x_0),
                               placeholder(:v_x_0))

@RV γ_x ~ ForneyLab.Gamma(placeholder(:a_x), placeholder(:b_x))

# Noise model
@RV w_0 ~ GaussianMeanVariance(placeholder(:m_w_0),
                               placeholder(:v_w_0))

@RV γ_w ~ ForneyLab.Gamma(placeholder(:a_w), placeholder(:b_w))

# Transition and observation models
x = Vector{Variable}(undef, n_samples)
w = Vector{Variable}(undef, n_samples)
y = Vector{Variable}(undef, n_samples)

x_i_min = x_0
w_i_min = w_0
for i in 1:n_samples
    global x_i_min, w_i_min
    @RV x[i] ~ GaussianMeanPrecision(x_i_min, γ_x)
    @RV w[i] ~ GaussianMeanPrecision(w_i_min, γ_w)
    @RV y[i] = x[i] + w[i]

    # Data placeholder
    placeholder(y[i], :y, index=i)

    # Reset state for next step
    x_i_min = x[i]
    w_i_min = w[i]
end

q = PosteriorFactorization(x_0, x, γ_x, w_0, w, γ_w, ids=[:X0 :X :ΓX :W0 :W :ΓW])
algo = variationalAlgorithm(q, free_energy=false)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions