Skip to content

Commit

Permalink
Merge pull request #198 from mach3-software/feature_randomFixes
Browse files Browse the repository at this point in the history
Random Fixes
  • Loading branch information
KSkwarczynski authored Nov 1, 2024
2 parents 5f39fd7 + 85886f6 commit 2072e51
Show file tree
Hide file tree
Showing 15 changed files with 76 additions and 136 deletions.
13 changes: 7 additions & 6 deletions .github/workflows/Doxygen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,20 @@ jobs:
- run: sudo apt-get install -y perl

# Runs a single command using the runners shell
- name: Doxygen Action
uses: mattnotmitt/[email protected]
- uses: DenverCoder1/[email protected]
with:
doxyfile-path: './Doxyfile'
working-directory: ./Doc
github_token: ${{ secrets.GITHUB_TOKEN }}
folder: Doc/html
branch: gh-pages
config_file: Doc/Doxyfile

- name: Upload Doxygen Artifact
uses: actions/upload-artifact@v4
with:
retention-days: 1
name: DoxygenHTML
path: Doc/html

Sphinx:
# The type of runner that the job will run on
runs-on: ubuntu-latest
Expand Down Expand Up @@ -120,7 +121,7 @@ jobs:
name: DocumentationHTML
path: to-upload


Deploy:
runs-on: ubuntu-latest
needs: [Doxygen, Sphinx]
Expand Down
10 changes: 2 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,10 @@
*.o
*.sif

#ignore some stuff in libconfig
*.lo
*.la
*.Plo
lib/*

build*/
install/
Doc/latex/
Doc/html/
Doc/html
Doc/latex

# Ignore emacs/vim stuff
*#*
Expand Down
1 change: 1 addition & 0 deletions .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Edward Atkin <[email protected]> EdAtkin <[email protected]

# Daniel Barrow
Daniel Barrow <[email protected]> dbarrow257 <[email protected]>
Daniel Barrow <[email protected]> dbarrow257 <[email protected]>

# Kamil Skwarczynski
Kamil Skwarczynski <[email protected]> Kamil <[email protected]>
Expand Down
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ install(EXPORT MaCh3-targets
NAMESPACE MaCh3::
DESTINATION ${CMAKE_INSTALL_PREFIX}/
)
install(DIRECTORY cmake DESTINATION ${CMAKE_BINARY_DIR})

#KS: Options to print dependency graph
DefineEnabledRequiredSwitch(MaCh3_DependancyGraph FALSE)
Expand Down Expand Up @@ -331,4 +332,4 @@ if(NOT TARGET uninstall)
endif()

# KS: Configure the Doxygen input file, this is to ensure whenever we update MaCh3 version Doxyfile will have same version.
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Templates/Doxyfile.in ${CMAKE_CURRENT_SOURCE_DIR}/Doc/Doxyfile @ONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Templates/Doxyfile.in ${CMAKE_CURRENT_SOURCE_DIR}/Doc/Doxyfile @ONLY)
20 changes: 7 additions & 13 deletions Diagnostics/GetPenaltyTerm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void ReadXSecFile(const std::string& inputFile)
}
}
#ifdef MULTITHREAD
#pragma omp parallel for
#pragma omp parallel for collapse(2)
#endif
for (int i = 0; i < size; i++)
{
Expand All @@ -126,7 +126,7 @@ void ReadXSecFile(const std::string& inputFile)

void GetPenaltyTerm(const std::string& inputFile, const std::string& configFile)
{
TCanvas* canvas = new TCanvas("canvas", "canvas", 0, 0, 1024, 1024);
auto canvas = std::make_unique<TCanvas>("canvas", "canvas", 0, 0, 1024, 1024);
canvas->SetGrid();
canvas->SetTickx();
canvas->SetTicky();
Expand Down Expand Up @@ -173,7 +173,7 @@ void GetPenaltyTerm(const std::string& inputFile, const std::string& configFile)
// Set all the branches to off
Chain->SetBranchStatus("*", false);

double* fParProp = new double[RelevantBranches];
std::vector<double> fParProp(RelevantBranches);
// Turn on the branches which we want for parameters
for (int i = 0; i < RelevantBranches; ++i)
{
Expand Down Expand Up @@ -250,14 +250,13 @@ void GetPenaltyTerm(const std::string& inputFile, const std::string& configFile)
}

int AllEvents = int(Chain->GetEntries());
TH1D **hLogL = new TH1D *[NSets];
for(int i = 0; i < NSets; i++)
{
std::vector<std::unique_ptr<TH1D>> hLogL(NSets);
for (int i = 0; i < NSets; i++) {
std::string NameTemp = "LogL_" + SetsNames[i];
hLogL[i] = new TH1D(NameTemp.c_str(), NameTemp.c_str(), AllEvents, 0 , AllEvents);
hLogL[i] = std::make_unique<TH1D>(NameTemp.c_str(), NameTemp.c_str(), AllEvents, 0, AllEvents);
hLogL[i]->SetLineColor(kBlue);
}
double* logL = new double[NSets]();
std::vector<double> logL(NSets, 0.0);
for(int n = 0; n < AllEvents; ++n)
{
if(n%10000 == 0) MaCh3Utils::PrintProgressBar(n, AllEvents);
Expand Down Expand Up @@ -337,7 +336,6 @@ void GetPenaltyTerm(const std::string& inputFile, const std::string& configFile)
}
}//End loop over steps

delete[] logL;
// Directory for posteriors
std::string OutputName = inputFile + "_PenaltyTerm" +".root";
TFile* OutputFile = new TFile(OutputName.c_str(), "recreate");
Expand All @@ -359,13 +357,9 @@ void GetPenaltyTerm(const std::string& inputFile, const std::string& configFile)
hLogL[i]->Write();

canvas->Print(Form("%s_PenaltyTerm.pdf",inputFile.c_str()), "pdf");
delete hLogL[i];
}
canvas->Print(Form("%s_PenaltyTerm.pdf]",inputFile.c_str()), "pdf");
delete[] hLogL;
delete[] fParProp;
delete Chain;
delete canvas;

for (int i = 0; i < size; i++)
{
Expand Down
53 changes: 24 additions & 29 deletions Diagnostics/RHat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@ int Nchains;

int nDraw;

std::vector<TString> BranchNames;
std::vector<std::string> MCMCFile;
std::vector<TString> BranchNames;
std::vector<std::string> MCMCFile;
std::vector<bool> ValidPar;

double ***Draws;

double** Mean;
double** StandardDeviation;

double* MeanGlobal;
double* StandardDeviationGlobal;

double* BetweenChainVariance;
double* MarginalPosteriorVariance;
double* RHat;
Expand All @@ -58,10 +58,10 @@ double* MedianArr;

double** MeanFolded;
double** StandardDeviationFolded;

double* MeanGlobalFolded;
double* StandardDeviationGlobalFolded;

double* BetweenChainVarianceFolded;
double* MarginalPosteriorVarianceFolded;
double* RHatFolded;
Expand All @@ -81,7 +81,7 @@ void CapVariable(double var, double cap);

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

SetMaCh3LoggerFormat();
MaCh3Utils::MaCh3Welcome();
Expand Down Expand Up @@ -420,7 +420,7 @@ void InitialiseArrays() {

// *******************
void RunDiagnostic() {
// *******************
// *******************
CalcRhat();
//In case in future we expand this
}
Expand All @@ -430,17 +430,17 @@ void RunDiagnostic() {
// Probably most of it could be moved cleverly to MCMC Processor, keep it separate for now
void CalcRhat() {
// *******************

TStopwatch clock;
clock.Start();

//KS: Start parallel region
// If we would like to do this for thousands of chains we might consider using GPU for this
//KS: Start parallel region
// If we would like to do this for thousands of chains we might consider using GPU for this
#ifdef MULTITHREAD
#pragma omp parallel
{
#endif

#ifdef MULTITHREAD
#pragma omp for collapse(2)
#endif
Expand Down Expand Up @@ -479,7 +479,7 @@ void CalcRhat() {
#ifdef MULTITHREAD
#pragma omp for collapse(2)
#endif
//Calculate the standard deviation for each parameter within each considered chain
//Calculate the standard deviation for each parameter within each considered chain
for (int m = 0; m < Nchains; ++m)
{
for (int j = 0; j < nDraw; ++j)
Expand Down Expand Up @@ -579,8 +579,8 @@ void CalcRhat() {

// *******************
void SaveResults() {
// *******************
#pragma GCC diagnostic ignored "-Wfloat-conversion"
// *******************
#pragma GCC diagnostic ignored "-Wfloat-conversion"

std::string NameTemp = "";
//KS: If we run over many many chains there is danger that name will be so absurdly long we run over system limit and job will be killed :(
Expand All @@ -591,7 +591,7 @@ void SaveResults() {
std::string temp = MCMCFile[i];

while (temp.find(".root") != std::string::npos) {
temp = temp.substr(0, temp.find(".root"));
temp = temp.substr(0, temp.find(".root"));
}

NameTemp = NameTemp + temp + "_";
Expand Down Expand Up @@ -674,13 +674,13 @@ void SaveResults() {
RhatFoldedLogPlot->Write();

//KS: Now we make fancy canvases, consider some function to have less copy pasting
TCanvas *TempCanvas = new TCanvas("Canvas", "Canvas", 1024, 1024);
auto TempCanvas = std::make_unique<TCanvas>("Canvas", "Canvas", 1024, 1024);
gStyle->SetOptStat(0);
TempCanvas->SetGridx();
TempCanvas->SetGridy();

// Random line to write useful information to TLegend
TLine *TempLine = new TLine(0 , 0, 0, 0);
auto TempLine = std::make_unique<TLine>(0, 0, 0, 0);
TempLine->SetLineColor(kBlack);

RhatPlot->GetXaxis()->SetTitle("R hat");
Expand All @@ -696,7 +696,7 @@ void SaveResults() {
Legend->SetLineWidth(0);
Legend->SetLineColor(0);

Legend->AddEntry(TempLine, Form("Number of throws=%.0i, Number of chains=%.1i", Ntoys, Nchains), "");
Legend->AddEntry(TempLine.get(), Form("Number of throws=%.0i, Number of chains=%.1i", Ntoys, Nchains), "");
Legend->AddEntry(RhatPlot, "Rhat Gelman 2013", "l");
Legend->AddEntry(RhatFoldedPlot, "Rhat-Folded Gelman 2021", "l");

Expand All @@ -721,7 +721,7 @@ void SaveResults() {
Legend->SetLineWidth(0);
Legend->SetLineColor(0);

Legend->AddEntry(TempLine, Form("Number of throws=%.0i, Number of chains=%.1i", Ntoys, Nchains), "");
Legend->AddEntry(TempLine.get(), Form("Number of throws=%.0i, Number of chains=%.1i", Ntoys, Nchains), "");
Legend->AddEntry(RhatLogPlot, "Rhat Gelman 2013", "l");
Legend->AddEntry(RhatFoldedLogPlot, "Rhat-Folded Gelman 2021", "l");

Expand Down Expand Up @@ -749,7 +749,7 @@ void SaveResults() {
const double Mean2 = EffectiveSampleSizeFoldedPlot->GetMean();
const double RMS2 = EffectiveSampleSizeFoldedPlot->GetRMS();

Legend->AddEntry(TempLine, Form("Number of throws=%.0i, Number of chains=%.1i", Ntoys, Nchains), "");
Legend->AddEntry(TempLine.get(), Form("Number of throws=%.0i, Number of chains=%.1i", Ntoys, Nchains), "");
Legend->AddEntry(EffectiveSampleSizePlot, Form("S_{eff, BDA2} #mu = %.2f, #sigma = %.2f",Mean1 ,RMS1), "l");
Legend->AddEntry(EffectiveSampleSizeFoldedPlot, Form("S_{eff, BDA2} Folded, #mu = %.2f, #sigma = %.2f",Mean2 ,RMS2), "l");

Expand All @@ -772,8 +772,6 @@ void SaveResults() {
delete EffectiveSampleSizeFoldedPlot;

delete Legend;
delete TempCanvas;
delete TempLine;

delete RhatLogPlot;
delete RhatFoldedLogPlot;
Expand All @@ -788,7 +786,7 @@ void SaveResults() {
//KS: Pseudo destructor
void DestroyArrays() {
// *******************

MACH3LOG_INFO("Killing all arrays");
delete[] MeanGlobal;
delete[] StandardDeviationGlobal;
Expand Down Expand Up @@ -829,22 +827,19 @@ void DestroyArrays() {
delete[] StandardDeviationFolded;
}


// *******************
//calculate median
double CalcMedian(double arr[], const int size) {
// *******************
// *******************
std::sort(arr, arr+size);
if (size % 2 != 0)
return arr[size/2];
return (arr[(size-1)/2] + arr[size/2])/2.0;
}


// *******************
//calculate median
void CapVariable(double var, const double cap) {
// *******************

// *******************
if(std::isnan(var) || !std::isfinite(var)) var = cap;
}
12 changes: 6 additions & 6 deletions Doc/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ PROJECT_BRIEF = "Reference Guide"
# and the maximum width should not exceed 200 pixels. Doxygen will copy the logo
# to the output directory.

PROJECT_LOGO = "../Doc/mach3logo_small.png"
PROJECT_LOGO = "Doc/mach3logo_small.png"

# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path
# into which the generated documentation will be written. If a relative path is
# entered, it will be relative to the location where doxygen was started. If
# left blank the current directory will be used.

OUTPUT_DIRECTORY =
OUTPUT_DIRECTORY = Doc/

# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create 4096 sub-
# directories (in 2 levels) under the output directory of each output format and
Expand Down Expand Up @@ -670,7 +670,7 @@ LAYOUT_FILE =
# search path. Do not use file names with spaces, bibtex cannot handle them. See
# also \cite for info how to create references.

CITE_BIB_FILES = ../Doc/bibliography.bib
CITE_BIB_FILES = Doc/bibliography.bib

#---------------------------------------------------------------------------
# Configuration options related to warning and progress messages
Expand Down Expand Up @@ -741,7 +741,7 @@ WARN_LOGFILE =
# spaces.
# Note: If this tag is empty the current directory is searched.

INPUT = mainpage.md ../ ../manager ../splines ../samplePDF ../OscClass ../mcmc ../Diagnostics ../plotting ../plotting/plottingUtils ../Diagnostics/Diagnostics_utils ../covariance Plots/
INPUT = . Doc/mainpage.md manager splines samplePDF mcmc Diagnostics plotting plotting/plottingUtils Diagnostics/Diagnostics_utils covariance

# This tag can be used to specify the character encoding of the source files
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
Expand Down Expand Up @@ -891,7 +891,7 @@ FILTER_SOURCE_PATTERNS =
# (index.html). This can be useful if you have a project on for instance GitHub
# and want to reuse the introduction page also for the doxygen output.

USE_MDFILE_AS_MAINPAGE = mainpage.md
USE_MDFILE_AS_MAINPAGE = Doc/mainpage.md

#---------------------------------------------------------------------------
# Configuration options related to source browsing
Expand Down Expand Up @@ -1080,7 +1080,7 @@ HTML_STYLESHEET =
# see the documentation.
# This tag requires that the tag GENERATE_HTML is set to YES.

HTML_EXTRA_STYLESHEET = ../Doc/MaCh3.css
HTML_EXTRA_STYLESHEET = Doc/MaCh3.css

# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or
# other source files which should be copied to the HTML output directory. Note
Expand Down
1 change: 1 addition & 0 deletions Doc/html/nojekyll.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Loading

0 comments on commit 2072e51

Please sign in to comment.