MaCh3  2.6.1
Reference Guide
Functions
RHat.cpp File Reference

This executable calculates the \( \hat{R} \) estimator for Markov Chain Monte Carlo (MCMC) convergence. More...

#include "Fitters/RHatCalculator.h"
Include dependency graph for RHat.cpp:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Detailed Description

This executable calculates the \( \hat{R} \) estimator for Markov Chain Monte Carlo (MCMC) convergence.

KS: This exe is meant to calculate the \( \hat{R} \) estimator. For a well-converged chain, this distribution should be centered at one. The \( \hat{R} \) statistic is used to assess the convergence of MCMC simulations and helps determine whether the chains have reached a stable distribution.

[36].

MJR: Update – Improved memory usage so that whole chains can be quickly loaded without requiring copious amounts of RAM. This comes at the cost of not being able to calculate the Folded RHat since finding the median requires the loading of full chains at a time. The method has been validated to give identical results to the "High Memory" (original) version at a fraction of the runtime and resources.

The input format is also slightly altered; since we can now load entire chains, there's less need to specify how many toys are desired for a sub-sample, so the Ntoys input has been removed.

Author
Kamil Skwarczynski
Michael Reh

Definition in file RHat.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 29 of file RHat.cpp.

29  {
30 // *******************
33 
34  std::vector<std::string> MCMCFile;
35  int Nchains = 0;
36  if (argc < 2)
37  {
38  MACH3LOG_ERROR("Wrong arguments");
39  MACH3LOG_ERROR("./RHat NThin MCMCchain_1.root MCMCchain_2.root MCMCchain_3.root ... [how many you like]");
40  throw MaCh3Exception(__FILE__ , __LINE__ );
41  }
42 
43  int NThin = atoi(argv[1]);
44 
45  //KS Gelman suggests to diagnose on more than one chain
46  for (int i = 2; i < argc; i++)
47  {
48  MCMCFile.push_back(std::string(argv[i]));
49  MACH3LOG_INFO("Adding file: {}", MCMCFile.back());
50  Nchains++;
51  }
52 
53  if(Nchains == 1)
54  {
55  MACH3LOG_WARN("Gelman is going to be sad :(. He suggested you should use more than one chain (at least 4). Code works fine for one chain, however, estimator might be biased.");
56  MACH3LOG_WARN("Multiple chains are more likely to reveal multimodality and poor adaptation or mixing:");
57  }
58  MACH3LOG_INFO("Diagnosing {} chains", Nchains);
59  auto RHatCalc = std::make_unique<RHatCalculator>(false, MCMCFile, NThin);
60  RHatCalc->RunDiagnostic();
61 
62  return 0;
63 }
#define MACH3LOG_ERROR
Definition: MaCh3Logger.h:37
#define MACH3LOG_INFO
Definition: MaCh3Logger.h:35
void SetMaCh3LoggerFormat()
Set messaging format of the logger.
Definition: MaCh3Logger.h:60
#define MACH3LOG_WARN
Definition: MaCh3Logger.h:36
Custom exception class used throughout MaCh3.
void MaCh3Welcome()
KS: Prints welcome message with MaCh3 logo.
Definition: Monitor.cpp:13