From bfd661458d983170292034a273acc429b02aa8f5 Mon Sep 17 00:00:00 2001 From: IftachSadeh Date: Fri, 16 Nov 2018 19:48:40 +0100 Subject: [PATCH] Added `isReadOnlySys` option for evaluation - Added `isReadOnlySys` option, usable for evaluation only. One may set `isReadOnlySys = Ture` while using the python wrapper, in order to avoid writing anything to disk during evaluation. --- CHANGELOG.md | 4 +++- examples/scripts/annz_evalWrapper.py | 5 ++++- src/ANNZ_err.cpp | 6 ++++-- src/ANNZ_utils.cpp | 4 ++-- src/Utils.cpp | 8 ++++++++ src/Wrapper.cpp | 2 +- src/myANNZ.cpp | 10 ++++++++++ 7 files changed, 32 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7185966..85dcff8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,13 @@ # Changelog -## Master version (22/05/2018) +## Master version (16/11/2018) - Updated `py/ANNZ.py` and `scripts/annz_evalWrapper.py` for `python-3.6` compatibility. - Fixed bug in the `Makefile`; now ROOT shared libraries are linked *after* the local objects. +- Added `isReadOnlySys` option, usable for evaluation only. One may set `isReadOnlySys = Ture` while using the python wrapper, in order to avoid writing anything to disk during evaluation. + ## ANNZ v2.3.0 (03/04/2018) ### For users: diff --git a/examples/scripts/annz_evalWrapper.py b/examples/scripts/annz_evalWrapper.py index 0827a39..05e7dc4 100644 --- a/examples/scripts/annz_evalWrapper.py +++ b/examples/scripts/annz_evalWrapper.py @@ -108,6 +108,9 @@ def init(testType, opts): opts['doRegression'] = False opts['doClassification'] = False + # can run evaluation within a read-only system, by setting isReadOnlySys + # opts['isReadOnlySys'] = True + # -------------------------------------------------------------------------------------------------- # can work with single-regression, eg: # -------------------------------------------------------------------------------------------------- @@ -149,7 +152,7 @@ def init(testType, opts): if testType == 'doRandomCls': opts['doClassification'] = True opts['doRandomCls'] = True - opts["outDirName"] = "test_randCls_advanced" + opts["outDirName"] = "test_randCls_quick" # -------------------------------------------------------------------------------------------------- # list of parameter types and parameter names - THIS MUST INCLUDE any parameter diff --git a/src/ANNZ_err.cpp b/src/ANNZ_err.cpp index 68c2959..289eecf 100644 --- a/src/ANNZ_err.cpp +++ b/src/ANNZ_err.cpp @@ -204,8 +204,10 @@ void ANNZ::setupKdTreeKNN( // setup the factory // ----------------------------------------------------------------------------------------------------------- TString outFileNameTrain = getKeyWord(MLMname,"knnErrXML","outFileNameKnnErr"); - knnErrOutFile = new TFile(outFileNameTrain,"RECREATE"); - knnErrFactory = new TMVA::Factory(typeANNZ, knnErrOutFile, (TString)verbLvlF+drawProgBarStr+transStr+analysType); + if(glob->GetOptB("isReadOnlySys")) knnErrOutFile = NULL; + else knnErrOutFile = new TFile(outFileNameTrain,"RECREATE"); + + knnErrFactory = new TMVA::Factory(typeANNZ, knnErrOutFile, (TString)verbLvlF+drawProgBarStr+transStr+analysType); #if ROOT_TMVA_V0 typedef TMVA::Factory def_dataLoader; diff --git a/src/ANNZ_utils.cpp b/src/ANNZ_utils.cpp index ce18b35..e5e2a00 100644 --- a/src/ANNZ_utils.cpp +++ b/src/ANNZ_utils.cpp @@ -586,7 +586,7 @@ void ANNZ::Init() { if(glob->GetOptB("doOnlyKnnErr")) trainingNeeded = false; // initialize the outputs with the training directory and reset it - if(trainingNeeded) { + if(trainingNeeded && !glob->GetOptB("isReadOnlySys")) { outputs->InitializeDir(glob->GetOptC("outDirNameFull"),glob->GetOptC("baseName")); } glob->NewOptB("trainingNeeded",trainingNeeded); @@ -602,7 +602,7 @@ void ANNZ::Init() { // save the final configuration options to file // ----------------------------------------------------------------------------------------------------------- - bool saveConfig = ( (glob->GetOptB("doTrain") && trainingNeeded) || !glob->GetOptB("doTrain") ); + bool saveConfig = ( ( (glob->GetOptB("doTrain") && trainingNeeded) || !glob->GetOptB("doTrain") ) && !glob->GetOptB("isReadOnlySys") ); if(saveConfig) { TString saveFileName = getKeyWord("","baseConfig","current"); aLOG(Log::INFO)< Utils::splitStringByChar(TString s, char delim) { void Utils::safeRM(TString cmnd, bool verbose, bool checkExitStatus) { // =================================================================== + if(glob->GetOptB("isReadOnlySys")) { + if(verbose) aLOG(Log::INFO) <GetOptB("isReadOnlySys")); + if(glob->OptOrNullB("debugSysCmnd")) verbose = true; if(glob->OptOrNullB("copyCodeToOutDir")) copyCode = true; diff --git a/src/Wrapper.cpp b/src/Wrapper.cpp index e3c249d..fcf2a25 100644 --- a/src/Wrapper.cpp +++ b/src/Wrapper.cpp @@ -148,7 +148,7 @@ void Wrapper::Init(int argc, char ** argv) { utils = aManager->utils; glob = aManager->glob; outputs = aManager->outputs; - + aANNZ = new ANNZ("aANNZ"+name,utils,glob,outputs); aANNZ->aRegEval = new RegEval("aRegEval"+name,utils,glob,outputs); diff --git a/src/myANNZ.cpp b/src/myANNZ.cpp index 4af86fc..68c5e84 100644 --- a/src/myANNZ.cpp +++ b/src/myANNZ.cpp @@ -549,6 +549,7 @@ Manager::Manager() { glob->NewOptI("initSeedRnd" ,1979); // some random number so that the same set of randoms are chosen each time the code is run glob->NewOptB("doStoreToAscii" ,true); // store evaluation into ascii files glob->NewOptI("minObjTrainTest" ,50); // minimal number of objects to use for training (very dangerous to set this too low !!!!) + glob->NewOptB("isReadOnlySys" ,false); // allow evalWrapper to be run on a read-only system // number of times to divide the collection of MLMs needed for evaluation - in principle, no division is neccessary, however, // some MLMs (notabley BDTs) require a lot of memory. Therefore, it might be better to only evaluate a sub-sample of the MLMs @@ -914,6 +915,15 @@ void Manager::Init(int argc, char ** argv) { } } + // verify that isReadOnlySys can be enabled only together with doEval + if(glob->GetOptB("isReadOnlySys") && !glob->GetOptB("doEval")) { + glob->SetOptB("isReadOnlySys" ,false); + + aLOG(Log::WARNING) <printOpts(2,30); cout<