Skip to content
Snippets Groups Projects
Commit 39389f04 authored by rtalbi's avatar rtalbi
Browse files

Added dot product test

parent 9cc2e5a7
No related branches found
No related tags found
No related merge requests found
# Experiments parameters # Experiments parameters
perf{ perf{
testBuildingBlocks="false"; testBuildingBlocks="true";
PrivacyPreservation="false"; PrivacyPreservation="false";
MLAlgorithm="lr"; MLAlgorithm="lr";
runs_number ="30"; runs_number ="30";
......
#ifndef DAPPLE_EVALDOTPROD_H #ifndef DAPPLE_EVALDOTPROD_H
#define DAPPLE_EVALDOTPROD__H #define DAPPLE_EVALDOTPROD_H
#include "DTPKC.h" // Header of the DTPKC cryptosystem's class #include "DTPKC.h" // Header of the DTPKC cryptosystem's class
......
...@@ -580,12 +580,14 @@ void TESTBuildingBlocks::run (bool deserialize, int keysize, int prec, int error ...@@ -580,12 +580,14 @@ void TESTBuildingBlocks::run (bool deserialize, int keysize, int prec, int error
vector<Cipher> C_av, C_bv, C_cv; vector<Cipher> C_av, C_bv, C_cv;
mpz_class output =0; mpz_class output =0;
mpz_class output2 =0;
for(int i=0; i < 8; i++) for(int i=0; i < 8; i++)
{ {
C_av.push_back(dtpkc.enc(av[i],dtpkc.pkw)); C_av.push_back(dtpkc.enc(av[i],dtpkc.pkw));
C_bv.push_back(dtpkc.enc(bv[i],dtpkc.pkw)); C_bv.push_back(dtpkc.enc(bv[i],dtpkc.pkw));
C_cv.push_back(dtpkc.enc(cv[i],dtpkc.pkw)); C_cv.push_back(dtpkc.enc(cv[i],dtpkc.pkw));
output = output + alpha2 * (av[i]-bv[i])*cv[i]; output = output + alpha2 * (av[i]-bv[i])*cv[i];
output2 = output2 + cv[i]*bv[i];
} }
EvalLrUpdate evalLrUpdate(C_av, C_bv, C_cv ,alpha, dtpkc); EvalLrUpdate evalLrUpdate(C_av, C_bv, C_cv ,alpha, dtpkc);
...@@ -598,6 +600,18 @@ void TESTBuildingBlocks::run (bool deserialize, int keysize, int prec, int error ...@@ -598,6 +600,18 @@ void TESTBuildingBlocks::run (bool deserialize, int keysize, int prec, int error
if (abs(int(output.get_ui()- C.get_ui())) > 3 ) cptF++; if (abs(int(output.get_ui()- C.get_ui())) > 3 ) cptF++;
cout<<"Test(" << cpt << ") <<LRupdate> gave : " << C.get_str() << " expected result " << output << " state :" << state << endl; cout<<"Test(" << cpt << ") <<LRupdate> gave : " << C.get_str() << " expected result " << output << " state :" << state << endl;
EvalDotProd evalDotProd(C_cv, C_bv , C_bv.size(), dtpkc);
C_C = evalDotProd.EvalDotProd_U1_step3(evalDotProd.EvalDotProd_U2_step2(evalDotProd.EvalDotProd_U1_step1()));
C = dtpkc.Sdec(C_C);
if ( dtpkc.n - C < 10000000000000 ) C= 0 - (dtpkc.n - dtpkc.Sdec(C_C));
else
state = (abs(int(output2.get_ui()- C.get_ui())) < 3 ) ? " passed":" failed";
if (abs(int(output2.get_ui()- C.get_ui())) > 3 ) cptF++;
cout<<"Test(" << cpt << ") <<Dot Product> gave : " << C.get_str() << " expected result " << output2 << " state :" << state << endl;
//cout << dtpkc.n << endl; //cout << dtpkc.n << endl;
/** /**
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
#include "../CRYPTO/EvalAddPow2.h" #include "../CRYPTO/EvalAddPow2.h"
#include "../CRYPTO/EvalStandardDiv.h" #include "../CRYPTO/EvalStandardDiv.h"
#include "../CRYPTO/EvalSigmoid.h" #include "../CRYPTO/EvalSigmoid.h"
#include "../CRYPTO/EvalDotProd.h"
#include "../UTIL/mpz_class.hh" #include "../UTIL/mpz_class.hh"
#include "../UTIL/num_th_alg.hh" #include "../UTIL/num_th_alg.hh"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment