diff --git a/PPML/PPNB/PPNB_Classifier.cpp b/PPML/PPNB/PPNB_Classifier.cpp index bf6bc1ede2aa3b7febe25127164bfe7ba5cd2b94..6d71141f016724d757aa03940ea8ac39e49cee47 100755 --- a/PPML/PPNB/PPNB_Classifier.cpp +++ b/PPML/PPNB/PPNB_Classifier.cpp @@ -9,6 +9,14 @@ using namespace std; * Naive Bayes classifier over encrypted data * * */ +double PPNB_Classifier:: trainTimeMU; +double PPNB_Classifier:: trainTimeSU; +double PPNB_Classifier:: testTimeMU; +double PPNB_Classifier:: testTimeSU; +double PPNB_Classifier:: trainBdw; +double PPNB_Classifier:: testBdw; + + PPRecord * PPNB_Classifier::recvPPRecord(int sockfd, sockaddr_in cliaddr, int dim, DTPKC dtpkc, int id) { @@ -139,6 +147,12 @@ PPNB_Classifier::PPNB_Classifier(PPDatasetReader *datasetReader, PPStats *stats, this->clientTestTime=0; this->extTestBd=0; + this->trainTimeMU=0.0; + this->trainTimeSU=0.0; + this->testTimeMU=0.0; + this->testTimeSU=0.0; + this->trainBdw=0.0; + this->testBdw=0.0; } @@ -190,6 +204,20 @@ void PPNB_Classifier::Test() { auto end = chrono::high_resolution_clock::now(); std::chrono::duration<double, std::milli> duration = end - begin ; this->testTime = duration.count(); + + this->testTimeSU = dtpkc.timeSU; + this->testBdw = dtpkc.bdwSU + dtpkc.bdwMU; + + this->testTimeMU = this->testTime - this->testTimeSU; + + dtpkc.timeSU = 0.0; + dtpkc.timeMU = 0.0; + dtpkc.bdwMU = 0.0; + dtpkc.bdwSU = 0.0; + + + + inter.close(); //currentModel->print(); @@ -279,6 +307,18 @@ void PPNB_Classifier::train() { std::chrono::duration<double, std::milli> duration = end - begin ; this->trainTime = duration.count(); + + this->trainTimeSU += dtpkc.timeSU; + this->trainBdw += dtpkc.bdwSU + dtpkc.bdwMU; + + this->trainTimeMU = this->trainTime - this->trainTimeSU; + + dtpkc.timeSU = 0.0; + dtpkc.timeMU = 0.0; + dtpkc.bdwMU = 0.0; + dtpkc.bdwSU = 0.0; + + } @@ -340,6 +380,16 @@ void PPNB_Classifier::RemoteTest(){ std::chrono::duration<double, std::milli> duration = en - begin ; this->testTime = duration.count(); + this->testTimeSU = dtpkc.timeSU; + this->testBdw = dtpkc.bdwSU + dtpkc.bdwMU; + + this->testTimeMU = this->testTime - this->testTimeSU; + + dtpkc.timeSU = 0.0; + dtpkc.timeMU = 0.0; + dtpkc.bdwMU = 0.0; + dtpkc.bdwSU = 0.0; + char buf[200]; socklen_t addrlen = sizeof(cliaddr); int n = recvfrom(sockfd, buf, 200, 0, (struct sockaddr *)&cliaddr, &addrlen); diff --git a/PPML/PPNB/PPNB_Classifier.h b/PPML/PPNB/PPNB_Classifier.h index 3886bce4c7b59791f3c3d0abb1333129dc318e36..7f56b3e25404034060132479e61cb974f1b5b7dd 100755 --- a/PPML/PPNB/PPNB_Classifier.h +++ b/PPML/PPNB/PPNB_Classifier.h @@ -26,6 +26,16 @@ public : int sockfd; sockaddr_in cliaddr; + static double trainTimeSU; + static double trainTimeMU; + static double trainBdw; + + static double testTimeSU; + static double testTimeMU; + static double testBdw; + + + public: PPNB_Classifier(PPDatasetReader *datasetReader, PPStats *stats, int laplaceConstant, string log, int sockfd, sockaddr_in cliaddr, bool debug); diff --git a/PPML/PPNB/PPStats.cpp b/PPML/PPNB/PPStats.cpp index c3884ab3ef62b3f0779a2dcb417b112742f95ed2..16e2ae341b13042f0e91e9abb34f723237812d06 100755 --- a/PPML/PPNB/PPStats.cpp +++ b/PPML/PPNB/PPStats.cpp @@ -1,6 +1,7 @@ #include "PPStats.h" #include <map> #include "math.h" +#include "PPNB_Classifier.h" void PPStats::h() { @@ -120,12 +121,17 @@ PPStats::InitStats() { Cipher proba = evalDiv100.EvalDiv_U1_step3(evalDiv100.EvalDiv_U2_step2(res1[0], res1[1], res1[2], res1[3])); #pragma omp critical { + proProba.insert(std::make_pair(i->first, proba)); EvalLog evalLog(proba,10000,dtpkc); std::vector<Cipher> in = evalLog.EvalLog_U1_step1(); Cipher C_C=evalLog.EvalLog_U1_step3(evalLog.EvalLog_U2_step2(in[0],in[1])); //COUT << "prior proba " << C_C << " res " << mpz_class_log (dtpkc.Sdec(proba) + 1 , 100)<< " " <<proba << endl; LogproProba.insert(std::make_pair(i->first, C_C)); + PPNB_Classifier::trainTimeSU += evalDiv100.timeSU; + PPNB_Classifier::trainTimeSU += evalLog.timeSU; + PPNB_Classifier::trainBdw += evalDiv100.bdwMU + evalDiv100.bdwSU + evalLog.bdwMU + evalLog.bdwSU; + }; } @@ -140,12 +146,17 @@ PPStats::InitStats() { size_t cnt = 0; int ithread = omp_get_thread_num(); int nthreads = omp_get_num_threads(); + double costTimeDiv = 0.0; + double costBdwDiv =0.0; + double costTimeLog= 0.0; + double costBdwLog =0.0; for (auto j = dataAVC.begin(); j!=dataAVC.end(); ++j, cnt++) { if(cnt%nthreads != ithread) continue; PPStats::st VC = j->second; //PPStats::stf cdProbaValues; PPStats::stf LogcdProbaValues; + for (auto &k : VC) { @@ -161,6 +172,8 @@ PPStats::InitStats() { vector<Cipher> res1 = evalDiv100.EvalDiv_U1_step1(); probaxjkl = evalDiv100.EvalDiv_U1_step3( evalDiv100.EvalDiv_U2_step2(res1[0], res1[1], res1[2], res1[3])); + costTimeDiv = evalDiv100.timeSU; + costBdwDiv = evalDiv100.bdwMU + evalDiv100.bdwSU; } //cdProbaClasses.insert(std::make_pair(l.first, probaxjkl)); @@ -169,6 +182,9 @@ PPStats::InitStats() { Cipher C_C=evalLog.EvalLog_U1_step3(evalLog.EvalLog_U2_step2(in[0],in[1])); LogcdProbaClasses.insert(std::make_pair(l.first, C_C)); //COUT << "cond proba " << C_C << " res " <<mpz_class_log (dtpkc.Sdec(probaxjkl) + 1 , 100) << endl; + + costTimeLog = evalLog.timeSU; + costBdwLog = evalLog.bdwMU + evalLog.bdwSU; } //cdProbaValues.insert(std::make_pair(k.first, cdProbaClasses)); LogcdProbaValues.insert(std::make_pair(k.first, LogcdProbaClasses)); @@ -176,8 +192,16 @@ PPStats::InitStats() { #pragma omp critical { + int size = 0; + for (auto &ptr1 : VC) { + + size += ptr1.second.size(); + + } //condProba.insert(std::make_pair(j->first, cdProbaValues)); LogcondProba.insert(std::make_pair(j->first, LogcdProbaValues)); + PPNB_Classifier::trainTimeSU += costTimeLog + costTimeDiv; + PPNB_Classifier::trainBdw += costBdwLog + costBdwDiv; }; } @@ -259,6 +283,7 @@ Cipher PPStats::Classify(PPRecord *r) { } + //COUT << " maxProba " << maxProba << " maxClass " << maxClass << endl; return maxClass; diff --git a/TEST/main.cpp b/TEST/main.cpp index 20a4e0d780ad7ac681d75a76fa5ba5f2ef0d0e1b..b0e18af6d386cbb8a684c4b950ccaac240dc3491 100755 --- a/TEST/main.cpp +++ b/TEST/main.cpp @@ -494,7 +494,7 @@ int main (int argc, char **argv) { OutputPath + classOutput, sockfd, cliaddr, debug); if (Incremental) { - stats << "TrainTime,TrainBd,TestServerTime,TestClientTime,TestBd,P,R,F1" << endl; + stats << "TrainTime,TrainBd,TestServerTime,TestClientTime,TestBd,P,R,F1,TrainMU,TrainSU,TrainBdw,TestMU,TestSU,TestBdw" << endl; for (int ch = 0; ch < chunk_number; ch++) { if (debug) cout << "Started training on chunk n°: " << ch + 1 << " from: " << chunk_number << endl; @@ -529,7 +529,8 @@ int main (int argc, char **argv) { "," + std::to_string(classifier->testTime) + "," + std::to_string(classifier->clientTestTime) + "," + classifier->extTestBd.get_str() + "," + std::to_string(P) + "," + - std::to_string(R) + "," + std::to_string(F1) << endl; + std::to_string(R) + "," + std::to_string(F1) + "," + std::to_string(PPNB_Classifier::trainTimeMU) + "," + std::to_string(PPNB_Classifier::trainTimeSU) +","+ std::to_string(PPNB_Classifier::trainBdw) + "," + + std::to_string(PPNB_Classifier::testTimeMU) +"," + std::to_string(PPNB_Classifier::testTimeSU) +"," + std::to_string(PPNB_Classifier::testBdw)<< endl; classifier->trainTime = 0; classifier->testTime = 0 ; datasetReader->reloadTest(); @@ -560,7 +561,8 @@ int main (int argc, char **argv) { "," + std::to_string(classifier->testTime) + "," + std::to_string(classifier->clientTestTime) + "," + classifier->extTestBd.get_str() + "," + std::to_string(P) + "," + - std::to_string(R) + "," + std::to_string(F1) << endl; + std::to_string(R) + "," + std::to_string(F1) + "," + std::to_string(PPNB_Classifier::trainTimeMU) + "," + std::to_string(PPNB_Classifier::trainTimeSU) +","+ std::to_string(PPNB_Classifier::trainBdw) + "," + + std::to_string(PPNB_Classifier::testTimeMU) +"," + std::to_string(PPNB_Classifier::testTimeSU) +"," + std::to_string(PPNB_Classifier::testBdw)<< endl; }