MaCh3  2.6.1
Reference Guide
Functions
RHat_HighMem.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_HighMem.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].

Author
Kamil Skwarczynski
Michael Reh

Definition in file RHat_HighMem.cpp.

Function Documentation

◆ main()

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

Definition at line 21 of file RHat_HighMem.cpp.

21  {
22 // *******************
25 
26  std::vector<std::string> MCMCFile;
27  if (argc == 1 || argc == 2)
28  {
29  MACH3LOG_ERROR("Wrong arguments");
30  MACH3LOG_ERROR("./RHat Ntoys MCMCchain_1.root MCMCchain_2.root MCMCchain_3.root ... [how many you like]");
31  throw MaCh3Exception(__FILE__ , __LINE__ );
32  }
33 
34  int Ntoys = atoi(argv[1]);
35  int Nchains = 0;
36  //KS Gelman suggests to diagnose on more than one chain
37  for (int i = 2; i < argc; i++)
38  {
39  MCMCFile.push_back(std::string(argv[i]));
40  MACH3LOG_INFO("Adding file: {}", MCMCFile.back());
41  Nchains++;
42  }
43 
44  if(Ntoys < 1)
45  {
46  MACH3LOG_ERROR("You specified {} specify larger greater than 0", Ntoys);
47  throw MaCh3Exception(__FILE__ , __LINE__ );
48  }
49 
50  if(Nchains == 1)
51  {
52  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.");
53  MACH3LOG_WARN("Multiple chains are more likely to reveal multimodality and poor adaptation or mixing:");
54  }
55  MACH3LOG_INFO("Diagnosing {} chains, with {} toys", Nchains, Ntoys);
56 
57  auto RHatCalc = std::make_unique<RHatCalculator>(true, MCMCFile, Ntoys);
58  RHatCalc->RunDiagnostic();
59  return 0;
60 }
#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