Skip to content

Commit ad63b74

Browse files
committed
Merge pull request #17 from yebai/emma_chain_show3
Adding Base.show(io::IO, ch1::Chain) function
2 parents 6876bd3 + e7a6e09 commit ad63b74

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/core/io.jl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ type Chain
1313
end
1414
Chain() = Chain(0, Vector{Sample}())
1515

16+
function Base.show(io::IO, ch1::Chain)
17+
# Print chain weight and weighted means of samples in chain
18+
if length(ch1.value) == 0
19+
print(io, "Empty Chain, weight $(ch1.weight)")
20+
else
21+
chain_mean = [i => mean(ch1, i, x -> x) for i in keys(ch1.value[1].value)]
22+
print(io, "Chain, model evidence (log) $(ch1.weight) and means $(chain_mean)")
23+
end
24+
end
25+
1626
function Base.getindex(c::Chain, v::Symbol)
1727
# This strange implementation is mostly to keep backward compatability.
1828
# Needs some refactoring a better format for storing results is available.
@@ -54,4 +64,3 @@ end
5464
# tests
5565
# tr = Turing.sampler.particles[1]
5666
# tr = Chain(Turing.sampler.particles)
57-

0 commit comments

Comments
 (0)