From fbc316b25b8085fa50ad392da62b081553819391 Mon Sep 17 00:00:00 2001 From: Suresh Parthasarathy Date: Tue, 21 Nov 2017 10:30:20 +0530 Subject: [PATCH] Adding i/o code for protonn outputs --- run_ProtoNNPredict_usps10.bat | 2 +- run_ProtoNNTrain_usps10.bat | 2 +- src/ProtoNN/ProtoNNPredictor.cpp | 42 ++++++++++++++++++++++++++------ src/ProtoNN/ProtoNNTrainer.cpp | 30 +++++++++++++++++++++-- 4 files changed, 64 insertions(+), 12 deletions(-) diff --git a/run_ProtoNNPredict_usps10.bat b/run_ProtoNNPredict_usps10.bat index 29b9cb38..1988ea1a 100644 --- a/run_ProtoNNPredict_usps10.bat +++ b/run_ProtoNNPredict_usps10.bat @@ -9,7 +9,7 @@ REM # Have a look at README.md and README_PROTONN_OSS.md for details on how to s SET test_file=-I usps10/test.txt SET model_file=-M usps10/ProtoNNResults/ProtoNNTrainer_pd_15_protPerClass_0_prot_200_spW_1.000000_spZ_1.000000_spB_1.000000_gammaNumer_1.000000_normal_3_seed_42_bs_1024_it_20_ep_20/model SET normalization_file=-n usps10/ProtoNNResults/ProtoNNTrainer_pd_15_protPerClass_0_prot_200_spW_1.000000_spZ_1.000000_spB_1.000000_gammaNumer_1.000000_normal_3_seed_42_bs_1024_it_20_ep_20/minMaxParams -SET output_dir=-O usps10/ProtoNNResults +SET output_dir=-O usps10\ProtoNNResults SET input_format=-F 0 SET ntest=-e 2007 REM SET batch_size=-b 1024 diff --git a/run_ProtoNNTrain_usps10.bat b/run_ProtoNNTrain_usps10.bat index 602721a2..2c84dfb5 100644 --- a/run_ProtoNNTrain_usps10.bat +++ b/run_ProtoNNTrain_usps10.bat @@ -13,7 +13,7 @@ SET predefined_model=-P 0 SET problem_format=-C 1 SET train_file=-I usps10/train.txt SET validation_file=-V usps10/test.txt -SET output_dir=-O usps10/ProtoNNResults +SET output_dir=-O usps10\ProtoNNResults SET input_format=-F 0 REM ######################################################## diff --git a/src/ProtoNN/ProtoNNPredictor.cpp b/src/ProtoNN/ProtoNNPredictor.cpp index 1794ad47..a0d55366 100644 --- a/src/ProtoNN/ProtoNNPredictor.cpp +++ b/src/ProtoNN/ProtoNNPredictor.cpp @@ -57,7 +57,7 @@ ProtoNNPredictor::ProtoNNPredictor( testData.loadDataFromFile(dataformatType, trainFile, validationFile, - testFile); + testFile); testData.finalizeData(); normalize(); @@ -120,7 +120,14 @@ ProtoNNPredictor::ProtoNNPredictor( void ProtoNNPredictor::createOutputDirs() { std::string subdirName = model.hyperParams.subdirName(); + +#ifdef LINUX outDir = outDir + "/ProtoNNPredictor_" + subdirName; +#endif + +#ifdef WINDOWS + outDir = outDir + "\\ProtoNNPredictor_" + subdirName; +#endif try { std::string testcommand = "test -d " + outDir; @@ -134,29 +141,48 @@ void ProtoNNPredictor::createOutputDirs() LOG_WARNING("Error in creating directory at this location: " + outDir); #endif +#ifdef WINDOWS + if (system(command.c_str()) != 0) + LOG_WARNING("Error in creating directory at this location: " + outDir + " (Directory might already exist)"); +#endif + + #ifdef DUMP +#ifdef LINUX testcommand = "test -d " + outDir + "/dump"; command = "mkdir " + outDir + "/dump"; -#ifdef LINUX if (system(testcommand.c_str()) == 0) LOG_INFO("Directory " + outDir + "/dump already exists."); else if (system(command.c_str()) != 0) LOG_WARNING("Error in creating directory at this location: " + outDir + "/dump"); #endif + +#ifdef WINDOWS + command = "mkdir " + outDir + "\\dump"; + if (system(command.c_str()) != 0) + LOG_WARNING("Error in creating directory at this location: " + outDir + "\dump" + " (Directory might already exist)"); #endif +#endif + #ifdef VERIFY +#ifdef LINUX testcommand = "test -d " + outDir + "/verify"; command = "mkdir " + outDir + "/verify"; -#ifdef LINUX if (system(testcommand.c_str()) == 0) LOG_INFO("Directory " + outDir + "/verify already exists."); else if (system(command.c_str()) != 0) LOG_WARNING("Error in creating directory at this location: " + outDir + "/verify"); #endif + +#ifdef WINDOWS + command = "mkdir " + outDir + "\\verify"; + if (system(command.c_str()) != 0) + LOG_WARNING("Error in creating directory at this location: " + outDir + "\verify" + " (Directory might already exist)"); #endif - } +#endif +} catch (...) { LOG_WARNING("Error in creating one of the subdirectories. Some of the output may not be recorded."); } @@ -444,10 +470,10 @@ EdgeML::ResultStruct ProtoNNPredictor::testPointWise() EdgeML::ResultStruct res, tempRes; for (dataCount_t i = 0; i < n; ++i) { - scoreSparseDataPoint(scores, - (const FP_TYPE*) testData.Xtest.valuePtr() + testData.Xtest.outerIndexPtr()[i], - (const featureCount_t*) testData.Xtest.innerIndexPtr() + testData.Xtest.outerIndexPtr()[i], - (featureCount_t) testData.Xtest.outerIndexPtr()[i + 1] - testData.Xtest.outerIndexPtr()[i]); + scoreSparseDataPoint(scores, + (const FP_TYPE*) testData.Xtest.valuePtr() + testData.Xtest.outerIndexPtr()[i], + (const featureCount_t*) testData.Xtest.innerIndexPtr() + testData.Xtest.outerIndexPtr()[i], + (featureCount_t) testData.Xtest.outerIndexPtr()[i + 1] - testData.Xtest.outerIndexPtr()[i]); tempRes = evaluate(Yscores, testData.Ytest.middleCols(i, 1), model.hyperParams.problemType); res.scaleAndAdd(tempRes, 1); diff --git a/src/ProtoNN/ProtoNNTrainer.cpp b/src/ProtoNN/ProtoNNTrainer.cpp index c0f95741..528284a0 100644 --- a/src/ProtoNN/ProtoNNTrainer.cpp +++ b/src/ProtoNN/ProtoNNTrainer.cpp @@ -53,7 +53,14 @@ ProtoNNTrainer::ProtoNNTrainer( void ProtoNNTrainer::createOutputDirs() { std::string subdirName = model.hyperParams.subdirName(); + +#ifdef LINUX outDir = outDir + "/ProtoNNTrainer_" + subdirName; +#endif + +#ifdef WINDOWS + outDir = outDir + "\\ProtoNNTrainer_" + subdirName; +#endif try { std::string testcommand = "test -d " + outDir; @@ -67,27 +74,46 @@ void ProtoNNTrainer::createOutputDirs() LOG_WARNING("Error in creating directory at this location: " + outDir); #endif +#ifdef WINDOWS + if (system(command.c_str()) != 0) + LOG_WARNING("Error in creating directory at this location: " + outDir + " (Directory might already exist)"); +#endif + + #ifdef DUMP +#ifdef LINUX testcommand = "test -d " + outDir + "/dump"; command = "mkdir " + outDir + "/dump"; -#ifdef LINUX if (system(testcommand.c_str()) == 0) LOG_INFO("Directory " + outDir + "/dump already exists."); else if (system(command.c_str()) != 0) LOG_WARNING("Error in creating directory at this location: " + outDir + "/dump"); #endif + +#ifdef WINDOWS + command = "mkdir " + outDir + "\\dump"; + if (system(command.c_str()) != 0) + LOG_WARNING("Error in creating directory at this location: " + outDir + "\dump" + " (Directory might already exist)"); #endif +#endif + #ifdef VERIFY +#ifdef LINUX testcommand = "test -d " + outDir + "/verify"; command = "mkdir " + outDir + "/verify"; -#ifdef LINUX if (system(testcommand.c_str()) == 0) LOG_INFO("Directory " + outDir + "/verify already exists."); else if (system(command.c_str()) != 0) LOG_WARNING("Error in creating directory at this location: " + outDir + "/verify"); #endif + +#ifdef WINDOWS + command = "mkdir " + outDir + "\\verify"; + if (system(command.c_str()) != 0) + LOG_WARNING("Error in creating directory at this location: " + outDir + "\verify" + " (Directory might already exist)"); +#endif #endif } catch (...) {