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

Adding Base.show(io::IO, ch1::Chain) function #17

Merged
merged 3 commits into from
Jun 3, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/core/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ type Chain
end
Chain() = Chain(0, Vector{Sample}())

function Base.show(io::IO, ch1::Chain)
# Print chain weight and weighted means of samples in chain
if length(ch1.value) == 0
print(io, "Empty Chain, weight $(ch1.weight)")
else
chain_mean = [i => mean(ch1, i, x -> x) for i in keys(ch1.value[1].value)]
print(io, "Chain, model evidence (log) $(ch1.weight) and means $(chain_mean)")
end
end

function Base.getindex(c::Chain, v::Symbol)
# This strange implementation is mostly to keep backward compatability.
# Needs some refactoring a better format for storing results is available.
Expand Down Expand Up @@ -54,4 +64,3 @@ end
# tests
# tr = Turing.sampler.particles[1]
# tr = Chain(Turing.sampler.particles)