From b7a5ce5c753b8d1d73247f0910b9abcd9219a2bb Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Mon, 16 Dec 2024 11:00:50 -0700 Subject: [PATCH] Fix a bug. --- .../producers/differential_evaluation_mh.impl.h | 8 +++++--- tests/differential_evaluation_mh_producer_01.output | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/include/sampleflow/producers/differential_evaluation_mh.impl.h b/include/sampleflow/producers/differential_evaluation_mh.impl.h index 7b3c5c8b..5cebd8a2 100644 --- a/include/sampleflow/producers/differential_evaluation_mh.impl.h +++ b/include/sampleflow/producers/differential_evaluation_mh.impl.h @@ -233,12 +233,14 @@ namespace SampleFlow b_dist(0, n_chains - 3); typename std::vector::size_type b = b_dist(rng); + if (b >= std::min::size_type>(a, chain)) + ++b; if (b >= std::max(a, chain)) - b += 2; - else if (b >= std::min::size_type>(a, chain)) - b += 1; + ++b; const OutputType trial_b = current_samples[b]; + assert (a!=b); + // Combine trial a and trial b const OutputType crossover_result = crossover(current_samples[chain], trial_a, trial_b); trial_sample_and_ratio = propose_sample(crossover_result); diff --git a/tests/differential_evaluation_mh_producer_01.output b/tests/differential_evaluation_mh_producer_01.output index 3519c933..7af6d8fe 100644 --- a/tests/differential_evaluation_mh_producer_01.output +++ b/tests/differential_evaluation_mh_producer_01.output @@ -1 +1 @@ -Mean value = 1.9881 +Mean value = 1.98196