Skip to content

Use of mvnormcdf in Turing model #2080

Answered by torfjelde
rand5 asked this question in Q&A
Sep 13, 2023 · 1 comments · 3 replies
Discussion options

You must be logged in to vote

Also, you might want to check the numerical error on the mvnormcdf calls, i.e.

@model function flip(y,N,c1,c2)    
    C ~ LKJCholesky(2, 1.0)
    d = MvNormal(Distributions.PDMat(C))

    M=5000
    
    a1, er1 = mvnormcdf(d, [c2,c1], [Inf,Inf];m=M)
    a2, er2 = mvnormcdf(d, [c2,-Inf], [Inf,c1];m=M)
    
    if er1 > 1e-6 || er2 > 1e-6
        # Add `-Inf` to the log-prob to ensure that this sample will be reject by the sampler.
        Turing.@addlogprob! -Inf
        return nothing # return early since it will be rejected anyways
    end

    for n in 1:N
        y[n] ~ Binomial(10,a1/(a1+a2))
    end
end

Aaand I'd say use this stuff on your own risk 😬 You're currently performing aut…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@torfjelde
Comment options

Answer selected by rand5
@rand5
Comment options

@torfjelde
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants