Skip to content

Commit

Permalink
Merge pull request #45 from TuringLang/csp/misc-fixes
Browse files Browse the repository at this point in the history
Fix logevidence printing, minor tidying
  • Loading branch information
cpfiffer authored Mar 2, 2019
2 parents f74758d + 1cdc153 commit b6b59a3
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 101 deletions.
2 changes: 1 addition & 1 deletion src/chains.jl
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ function header(c::AbstractChains; section=missing)

# Return header.
return string(
# "Log model evidence = $(c.logevidence)\n", #FIXME: Uncomment.
"Log evidence = $(c.logevidence)\n",
"Iterations = $(first(c)):$(last(c))\n",
"Thinning interval = $(step(c))\n",
"Chains = $(join(map(string, chains(c)), ", "))\n",
Expand Down
Binary file removed test/demo-plot.png
Binary file not shown.
2 changes: 2 additions & 0 deletions test/plot_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,6 @@ chn = Chains(val)

p_subset_colordim = plot(chn, 2, colordim = :parameter)
@test isa(p_subset_colordim, Plots.Plot)

rm("demo-plot.png")
end
70 changes: 0 additions & 70 deletions test/sections_test.txt

This file was deleted.

71 changes: 41 additions & 30 deletions test/sections_tests.jl
Original file line number Diff line number Diff line change
@@ -1,34 +1,45 @@
using MCMCChains, Test

@testset "describe sections" begin

a3d = reshape(1:3600, 100, 9, 4)

cnames = ["lp__" , "accept_stat__", "stepsize__" , "treedepth__" ,
"n_leapfrog__" , "divergent__" , "energy__", "sigma", "mu" ]

pi = filter(p -> length(p) > 2 && p[end-1:end] == "__", cnames)
p = filter(p -> !(p in pi), cnames)

c = Chains(a3d,
Symbol.(cnames),
Dict(
:parameters => Symbol.(p),
:internals => Symbol.(pi)
)
)

tmpdir = tempdir()
open(joinpath(tmpdir, "sections_test.txt"), "w") do io
describe(io, c, section=:parameters);
describe(io, c, section=:internals);
describe(io, c);
end


@test open(f->read(f, String), joinpath(tmpdir, "sections_test.txt")) ==
open(f->read(f, String), joinpath(@__DIR__, "sections_test.txt"))

#println(open(f->read(f, String), joinpath(tmpdir, "sections_test.txt")))


a3d = reshape(1:3600, 100, 9, 4)

cnames = ["lp__" , "accept_stat__", "stepsize__" , "treedepth__" ,
"n_leapfrog__" , "divergent__" , "energy__", "sigma", "mu" ]

pi = filter(p -> length(p) > 2 && p[end-1:end] == "__", cnames)
p = filter(p -> !(p in pi), cnames)

c = Chains(a3d,
Symbol.(cnames),
Dict(
:parameters => Symbol.(p),
:internals => Symbol.(pi)
)
)

c2 = Chains(a3d,
Symbol.(cnames),
Dict(
:parameters => Symbol.(p),
:internals => Symbol.(pi)
)
)

tmpdir = tempdir()
open(joinpath(tmpdir, "sections_test1.txt"), "w") do io
describe(io, c, section=:parameters);
describe(io, c, section=:internals);
describe(io, c);
end

open(joinpath(tmpdir, "sections_test2.txt"), "w") do io
describe(io, c2, section=:parameters);
describe(io, c2, section=:internals);
describe(io, c2);
end


@test open(f->read(f, String), joinpath(tmpdir, "sections_test1.txt")) ==
open(f->read(f, String), joinpath(tmpdir, "sections_test2.txt"))
end

0 comments on commit b6b59a3

Please sign in to comment.