Soss.jl icon indicating copy to clipboard operation
Soss.jl copied to clipboard

Out of bounds error from

Open baggepinnen opened this issue 4 years ago • 1 comments

I get a cryptic out-of-bounds error trying to run inference on the following model. It samples from the prior just fine, the error originates from DynamicHMC. The stack trace is absolutely enormous, but I can post it in a gist if it would be helpful.

using Soss, Distributions
# generate fake data
nr = 5 # Number of reviewers
na = 20 # Number of articles
max_score = 10
reviewer_bias = rand(Normal(0,1), nr)
article_score = rand(Normal(0,2), na)
Rtrue = clamp.([r+a for r in reviewer_bias, a in article_score], -5, 5)
R = Rtrue .+ 0.5 .* randn.()
R = round.(Int,R)
Rmask = rand(Binomial(1,0.7), size(R))
R = replace(Rmask, 0=>missing) .* R
Rv = [R[i,j] for i in axes(R,1), j in axes(R,2) if !ismissing(R[i,j])]
indv = [(i,j) for i in axes(R,1), j in axes(R,2) if !ismissing(R[i,j])]
min_score = -5
max_score = 5
nscores = max_score-min_score+1


cum_model = Soss.@model indv begin
    rσ ~ Gamma(0.2)
    article_pop_variance ~ truncated(Normal(1., 0.5), 0, 100)
    reviewer_noise ~ truncated(Normal(rσ, 0.1), 0, 3) |> iid(nr) # Different reviewer have different noise variances
    reviewer_gain ~ Normal(1, 0.1) |> iid(nr)
    true_article_score ~ Normal(0,article_pop_variance) |> iid(na)
    diffcp ~ For(nscores-1) do i
        # i == 1 ? truncated(Normal(1,0.3), 0, 3) : Normal(1,0.15)
        Normal(1,0.15)
    end
    #cumsum(diffcp) .- (abs(min_score) + 1)
    pred ~ For(length(indv)) do ind
        i,j = indv[ind]
        Normal(true_article_score[j] + reviewer_gain[i]*true_article_score[j], reviewer_noise[i])
    end
    Rv ~ For(length(indv)) do ind
        i,j = indv[ind]
        Normal(pred[ind], 1)#OrderedLogistic(pred[ind],cutpoints)
    end
end;

truth = rand(cum_model(indv=indv))

@time post = dynamicHMC(cum_model(indv=indv), (Rv=truth.Rv,), 1000);

This is on soss 0.9 and julia 1.3.1

baggepinnen avatar Jan 30 '20 19:01 baggepinnen

Thanks @baggepinnen . I'm not sure yet what's going on here. Seems like it could be a problem with ForwardDiff, because that's mentioned in the error and logpdf(cum_model(indv=indv), truth) works just fine

cscherrer avatar Feb 04 '20 16:02 cscherrer