why use list of values inside Gen.jl @gen model for observe variable better?

33 views Asked by At

for this model in gen,

@gen function height_model()
    mu = @trace(normal(178, 20), :mu)
    sigma = @trace(uniform(0, 50), :sigma)
    @trace(normal(mu, sigma), :h)

end

converge of mh is,

enter image description here

which samples from the posterior are everywhere in no way near to real observations (y1 line), but for this model,

@gen function height_model(n)
    mu = @trace(normal(178, 20), :mu)
    sigma = @trace(uniform(0, 50), :sigma)

    for i=1:n
        @trace(normal(mu, sigma), "h-$i")

    end

end

has a better posterior (original observation is the blue line),

enter image description here

why is this happening?

same inference program used in both cases,

function do_mcmc_inference(model, args, xs, iters)
    observations = choicemap()

    for (i, x) in enumerate(xs)
        observations["h-$i"] = x

    end

    # Run the model, constrained by `constraints`,
    # to get an initial execution trace
    (trace, _) = generate(model, args, observations)

    # using Gen's metropolis_hastings operator.
    for i=1:iters
        (trace, _) = metropolis_hastings(trace, Gen.select(:mu)) 
        (trace, _) = metropolis_hastings(trace, Gen.select(:sigma))
        
    end

    # From the final trace, read out the mu, sigma.
    choices = get_choices(trace)

    return (choices[:mu], choices[:sigma])

end
0

There are 0 answers