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

NaN violates Normal condition σ >= zero(σ) #868

Closed
itsdfish opened this issue Jul 25, 2019 · 4 comments
Closed

NaN violates Normal condition σ >= zero(σ) #868

itsdfish opened this issue Jul 25, 2019 · 4 comments

Comments

@itsdfish
Copy link
Contributor

Hi-

For some reason the sigma parameter (s) takes the value of NaN and triggers an inequality violation. I found this in several models, but this is the simplest model I found that produces the error.

using Turing,Random 

Random.seed!(1101)

@model model(y) = begin
    N = length(y)
    μ = Vector{Real}(undef,N)
    μ ~ [Normal(0,1)]
    s ~ Truncated(Cauchy(0,1),0,Inf)
    if !isa(s,Float64)
        println(s.value)
    end
    for i in 1:N
        for j in 1:length(y[i])
            y[i][j] ~ Normal(μ[i],s)
        end 
    end
end
μ = rand(Normal(0,1),10)
y = [rand(Normal(i,1),10) for i in μ]

chain = sample(model(y),NUTS(2000,1000,.8))
println(chain)

System Info:

Julia 1.1.0

(v1.1) pkg> st Turing
    Status `~/.julia/environments/v1.1/Project.toml`
  [0bf59076] AdvancedHMC v0.2.1
  [31c24e10] Distributions v0.21.0
  [c7f686f2] MCMCChains v0.3.10
  [4c63d2b9] StatsFuns v0.8.0
  [fce5fe82] Turing v0.6.22
  [e88e6eb3] Zygote v0.3.2

(v1.1) pkg> st AdvancedHMC
    Status `~/.julia/environments/v1.1/Project.toml`
  [0bf59076] AdvancedHMC v0.2.1
  [d96e819e] Parameters v0.10.3
  [2913bbd2] StatsBase v0.31.0
@jonasmac16
Copy link
Contributor

I have also encountered the same error using a truncated normal on sigma recently but have a hard time to reproduce it. Just wanted to report it hear.

@itsdfish
Copy link
Contributor Author

itsdfish commented Jul 26, 2019

Thanks, @jonasmac16. I was able to reproduce the error by replacing s with s ~ TruncatedNormal(0,1,0,Inf) in the code above. On my system, the error systems seems to be fairly robust to the prior on s and seed. If you are finding cases where the model runs correctly, it might be helpful to report the code and your system info.

@xukai92
Copy link
Member

xukai92 commented Jul 26, 2019

This bug should be fixed by the recent merged PR in AdvancedHMC.jl. There was an interface bug after AdvancedHMC.jl was upgraded.

@xukai92
Copy link
Member

xukai92 commented Jul 31, 2019

Fixed by TuringLang/AdvancedHMC.jl#85

@xukai92 xukai92 closed this as completed Jul 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants