Skip to content
Open
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
22 changes: 18 additions & 4 deletions src/samplers/mcmc/mcmc_convergence.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# This file is a part of BAT.jl, licensed under the MIT License (MIT).

using Printf

function check_convergence!(
chains::AbstractVector{<:MCMCIterator},
Expand Down Expand Up @@ -71,7 +72,7 @@ function bat_convergence_impl(samples::AbstractVector{<:DensitySampleVector}, al
max_Rsqr = maximum(gr_Rsqr(samples))
vt = ValueAndThreshold{max_Rsqr}(max_Rsqr, <=, algorithm.threshold)
converged = convert(Bool, vt)
@debug begin
@info begin
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to keep this at debug-level for now, and have users do ENV["JULIA_DEBUG"] = "BAT".

success_str = converged ? "have" : "have *not*"
"Chains $success_str converged, max(R^2) = $(vt.value), threshold = $(vt.threshold)"
end
Expand Down Expand Up @@ -149,12 +150,25 @@ end
export BrooksGelmanConvergence

function bat_convergence_impl(samples::AbstractVector{<:DensitySampleVector}, algorithm::BrooksGelmanConvergence, ::BATContext)
max_Rsqr = maximum(bg_R_2sqr(samples, corrected = algorithm.corrected))
r2 = bg_R_2sqr(samples, corrected = algorithm.corrected)

max_Rsqr = maximum(r2)
mean_Rsqr = mean(r2)

n = length(r2)
n_conv = length(r2[r2 .<= algorithm.threshold])

vt = ValueAndThreshold{max_Rsqr}(max_Rsqr, <=, algorithm.threshold)
converged = convert(Bool, vt)
@debug begin

@info begin
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we leave this at debug-level too?

success_str = converged ? "have" : "have *not*"
"Chains $success_str converged, max(R^2) = $(vt.value), threshold = $(vt.threshold)"

max_r2 = @sprintf("%.2f", vt.value)
thresh = @sprintf("%.2f", vt.threshold)
mean_r2 = @sprintf("%.2f", mean_Rsqr)

"Chains $success_str converged, max(R²) = $max_r2, threshold = $thresh mean(R²) = $mean_r2, nconverged $n_conv / $n"
end
(result = vt,)
end
Expand Down
Loading