Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constraint Factorization Error #345

Closed
mhidalgoaraya opened this issue Aug 20, 2024 · 1 comment
Closed

Constraint Factorization Error #345

mhidalgoaraya opened this issue Aug 20, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@mhidalgoaraya
Copy link
Contributor

I have a model where an error occurs depending how I define the Naive Mean Field in the constrains:

it works if:
q(y, yprior, s, θ) = q(y)q(yprior)q(s)q(θ)

it doesn't work if:
q(y, yprior, s, θ) = MeanField()

`# Atomic Filter
@model function prob_lpf_switch(y, μx0, vx0, p∞, θ)
m = (0.0, 0.0)
yprior ~ Normal(mean = μx0, variance = vx0)
s ~ NormalMixture(switch = θ, m = m, p = p∞)
y := yprior + s
end

@model function prob_xnr_encap(y, π, μx0s, vx0s, μx0n, vx0n, vy, ps∞, pn∞)
	θ ~ Bernoulli(π)
    sp ~ prob_lpf_switch(μx0 = μx0s, vx0 = vx0s, p∞ = ps∞, θ = θ,)
    np ~ prob_lpf_switch(μx0 = μx0n, vx0 = vx0n, p∞ = pn∞, θ = θ,)	    

	g := sp - np
    g ~ Normal(m = 0.0, v = 1e10)
    
    y ~ Normal(m = sp, v = vy)
    y ~ Normal(m = np, v = vy)
end

function run_inference(data, π, vy, ps∞, pn∞)
    autoupdates = @autoupdates begin
        μx0s, vx0s = mean_var(q(sp))
        μx0n, vx0n = mean_var(q(np))
    end

    initialization = @initialization begin
        q(g) = vague(NormalMeanVariance)
		
		q(np) = vague(NormalMeanVariance)
		q(sp) = vague(NormalMeanVariance)
		
        for init in prob_lpf_switch
            q(y) = vague(NormalMeanVariance)
            q(s) = vague(NormalMeanVariance)
        end
    end

    constraints = @constraints begin
        for q in prob_lpf_switch
            q(y, yprior, s, θ) = MeanField()#q(y)q(yprior)q(s)q(θ)
        end
        q(sp, np, g) = MeanField()
    end

    rxengine = infer(
        model = prob_xnr_encap(vy = vy, ps∞ = ps∞, pn∞ = pn∞),
        autoupdates = autoupdates,
        data = (y = data, π = π),
        initialization = initialization,
        constraints = constraints,
        free_energy = false,
        showprogress = true,
        keephistory = 8000,
        historyvars = (
            sp = KeepLast(),
            np = KeepLast(),
			g = KeepLast(),
        ),
        returnvars = (:sp, :np, :g),
        autostart = true,
    )    
    return rxengine
end

`
Screenshot 2024-08-20 at 16 23 18

@mhidalgoaraya mhidalgoaraya added the bug Something isn't working label Aug 20, 2024
@wouterwln
Copy link
Member

This was a bug in GraphPPL and is fixed in version 4.3.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants