brian-j-smith / Mamba.jl

Markov chain Monte Carlo (MCMC) for Bayesian analysis in julia
Other
253 stars 52 forks source link

Intermittent error when plotting chains. #127

Open itsdfish opened 6 years ago

itsdfish commented 6 years ago

Hi-

I've been using the mamba plotting functions with Stan.jl. Sometimes I receive the following error when I plot my chains using the plot() function:

MethodError: no method matching isless(::Float64, ::Void)
Closest candidates are:
  isless(::Float64, !Matched::Float64) at float.jl:439
  isless(!Matched::DataArrays.NAtype, ::Any) at /Users/christopher.fisher/.julia/v0.6/DataArrays/src/operators.jl:383
  isless(::AbstractFloat, !Matched::AbstractFloat) at operators.jl:96
  ...
max(::Void, ::Float64) at operators.jl:348
apply_coordinate(::Gadfly.Coord.Cartesian, ::Array{Gadfly.Aesthetics,1}, ::Dict{Symbol,Gadfly.ScaleElement}) at coord.jl:215
#render_prepared#115(::Bool, ::Bool, ::Function, ::Gadfly.Plot, ::Gadfly.Coord.Cartesian, ::Gadfly.Aesthetics, ::Array{Gadfly.Aesthetics,1}, ::Array{Array{Gadfly.StatisticElement,1},1}, ::Array{Array{Gadfly.Aesthetics,1},1}, ::Array{Array{Gadfly.Data,1},1}, ::Dict{Symbol,Gadfly.ScaleElement}, ::Array{Gadfly.GuideElement,1}) at Gadfly.jl:806
render_prepared(::Gadfly.Plot, ::Gadfly.Coord.Cartesian, ::Gadfly.Aesthetics, ::Array{Gadfly.Aesthetics,1}, ::Array{Array{Gadfly.StatisticElement,1},1}, ::Array{Array{Gadfly.Aesthetics,1},1}, ::Array{Array{Gadfly.Data,1},1}, ::Dict{Symbol,Gadfly.ScaleElement}, ::Array{Gadfly.GuideElement,1}) at Gadfly.jl:806
render(::Gadfly.Plot) at Gadfly.jl:752
#draw#171(::Symbol, ::String, ::Measures.Length{:mm,Float64}, ::Measures.Length{:mm,Float64}, ::Int64, ::Int64, ::Bool, ::Bool, ::Compose.#draw, ::Array{Gadfly.Plot,2}) at plot.jl:45
(::Compose.#kw##draw)(::Array{Any,1}, ::Compose.#draw, ::Array{Gadfly.Plot,2}) at <missing>:0
include_string(::String, ::String) at sys.dylib:?
include_string(::String, ::String, ::Int64) at eval.jl:30
include_string(::Module, ::String, ::String, ::Int64, ::Vararg{Int64,N} where N) at eval.jl:34
(::Atom.##49#53{String,Int64,String})() at eval.jl:50
withpath(::Atom.##49#53{String,Int64,String}, ::String) at utils.jl:30
withpath(::Function, ::String) at eval.jl:38
macro expansion at eval.jl:49 [inlined]
(::Atom.##48#52{Dict{String,Any}})() at task.jl:80

I cannot share the code at this moment, but I would be willing to share the .jls file of the chain object if that is helpful.

Thanks,

-Chris

bdeonovic commented 6 years ago

@fisherc2 If you could provide the chain that would be helpful.

itsdfish commented 6 years ago

@bdeonovic I could not upload the file here. I sent it to the email listed on your profile. Please let me know if that email is no longer active.

goedman commented 6 years ago

@fisherc2 Hi Chris, could you also send it to me?

bdeonovic commented 6 years ago

@fisherc2 I was able to plot and draw your code. No errors (just some Gadfly warnings) must be an issue with your setup. What version of julia are you on and what version of Gadfly do you have? Also how did you try to plot. I did:

dat = deserialize(open("Downloads\\Samples_1124543.jls"))
p = plot(dat)
draw(p, fmt=:png, filename="test")
bdeonovic commented 6 years ago

To confirm here are the first 2 files from draw:

test-1 test-2

itsdfish commented 6 years ago

@bdeonovic I am using Julia .6 and Gadfly .6.4. After seeing your code, I think I may have identified the source of the error. Here is the code that produces the error based on @goedman Stan walk through:

sim = read("Samples_1124543.jls",Chains)
p = plot(sim, [:trace, :mean, :density, :autocor], legend=true);
draw(p, ncol=2, filename= "test", fmt=:png,width=20inch,height=15inch)

However, if I remove argument [:trace, :mean, :density, :autocor] from plot(), I no longer get the error. Note that the code above only produces an error on some chains.

bdeonovic commented 6 years ago

error seems to be with autocor. I will investigate further

bdeonovic commented 6 years ago

Issue is one of your variables (divergent__) is all 0s for all iterations and chains. This caused the autocor function to produce all NaNs which caused ChainSummary to error out.

We should probably have an error catch somewhere in the plotting to catch this and handle it more elegantly. @brian-j-smith