SeComLib
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Macros Pages
hub.h
Go to the documentation of this file.
1 /*
2 SeComLib
3 Copyright 2012-2013 TU Delft, Information Security & Privacy Lab (http://isplab.tudelft.nl/)
4 
5 Contributors:
6 Inald Lagendijk (R.L.Lagendijk@TUDelft.nl)
7 Mihai Todor (todormihai@gmail.com)
8 Thijs Veugen (P.J.M.Veugen@tudelft.nl)
9 Zekeriya Erkin (z.erkin@tudelft.nl)
10 
11 Licensed under the Apache License, Version 2.0 (the "License");
12 you may not use this file except in compliance with the License.
13 You may obtain a copy of the License at
14 
15 http://www.apache.org/licenses/LICENSE-2.0
16 
17 Unless required by applicable law or agreed to in writing, software
18 distributed under the License is distributed on an "AS IS" BASIS,
19 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 See the License for the specific language governing permissions and
21 limitations under the License.
22 */
29 #ifndef HUB_HEADER_GUARD
30 #define HUB_HEADER_GUARD
31 
32 //include our headers
33 #include "utils/config.h"
34 #include "utils/filesystem.h"
35 #include "utils/math.h"
36 #include "utils/date_time.h"
37 #include "utils/cpu_timer.h"
38 #include "core/big_integer.h"
39 #include "core/random_provider.h"
40 #include "core/paillier.h"
41 
42 #include "server.h"
43 #include "test_data_row.h"
44 
45 //include C++ libraries
46 #include <iostream>
47 #include <fstream>
48 #include <string>
49 #include <sstream>
50 #include <numeric>
51 #include <vector>
52 #include <map>
53 #include <stdexcept>
54 
55 namespace SeComLib {
56 using namespace Core;
57 
58 namespace SecureRecommendations {
59  //forward-declare required classes
60  class Server;
61 
65  class Hub {
66  public:
68  Hub ();
69 
71  ~Hub () {}
72 
74  const PaillierPublicKey &GetPublicKey () const;
75 
77  void SetServer (const std::shared_ptr<const Server> &server);
78 
80  void EvaluateSign (SecureSvm::EncryptedVector &input) const;
81 
83  void EvaluateMaximum (SecureSvm::EncryptedVector &input) const;
84 
86  void EvaluateDivision (const BigInteger &numerator, SecureSvm::EncryptedVector &input) const;
87 
89  void DoAccuracyAnalysis ();
90 
92  void DoPerformanceAnalysis ();
93 
95  void DoTrafficAnalysis ();
96 
98  void DebugValue (const Paillier::Ciphertext &value) const;
99  private:
102 
104  std::shared_ptr<const Server> server;
105 
108  unsigned long testVectorCount;
109 
111  unsigned int attributeCount;
112 
115 
118 
120  BigInteger svWeightScaling;
121 
123  std::vector<TestDataRow> medicalRelevanceTestData;
124 
126  std::vector<std::map<std::string, TestDataRow>> safetyTestData;
127 
129  std::vector<unsigned short> predictedClusters;
130 
132  std::vector<std::vector<unsigned short>> predictedQualityOfLifeMatrix;
133 
135  std::map<std::string, unsigned int> safetyBlockFalsePositives;
136 
138  std::map<std::string, unsigned int> safetyBlockFalseNegatives;
139 
141  static bool measureTraffic;
142 
144  static BigInteger bitsSent;
145 
147  static BigInteger bitsReceived;
148 
150  void loadSafetyTestData (const std::string &testFilesDirectory, const std::string &safetyTestFilesPrefix);
151 
153  TestDataRow parseTestDataRow (const std::string &line) const;
154 
156  unsigned short getVotedCluster (const std::vector<Paillier::Ciphertext> &encryptedClusterVotes) const;
157 
159  std::vector<unsigned short> processSafetyPredictions (const std::vector<Paillier::Ciphertext> &encryptedSafetyPredictions) const;
160 
162  unsigned int getMedicalRelevanceBlockCorrectPredictionCount () const;
163 
165  void computeSafetyBlockFalsePredictions ();
166 
168  static void resetTrafficCounters ();
169 
171  std::string getKernelName () const;
172 
174  Hub (Hub const &);
175 
177  Hub operator= (Hub const &);
178  };
179 }//namespace SecureRecommendations
180 }//namespace SeComLib
181 
182 #endif//HUB_HEADER_GUARD
Definition of class Math.
std::vector< Paillier::Ciphertext > EncryptedVector
Define a vector template specialization for vectors of encrypted data.
Definition: secure_svm.h:62
std::vector< TestDataRow > medicalRelevanceTestData
The medical relevance block test data.
Definition: hub.h:123
Processed test data container.
Definition: test_data_row.h:40
std::vector< unsigned short > predictedClusters
The predicted clusters.
Definition: hub.h:129
std::vector< std::vector< unsigned short > > predictedQualityOfLifeMatrix
Vector of predicted quality of life values (contains 0 for negative values and 1 for positive values)...
Definition: hub.h:132
Defines BigInteger.
SecureSvm::KernelTypes kernel
The SVM kernel type. We want to pre-compute only the data that is necessary for a particular kernel...
Definition: hub.h:114
Definition of class Config.
static BigInteger bitsReceived
Counts the number of bits received from the server.
Definition: hub.h:147
Paillier cryptoProvider
The crypto provider.
Definition: hub.h:101
Definition of class Filesystem.
unsigned int attributeCount
The number of attributes in each test vector of the test data.
Definition: hub.h:111
Definition of class DateTime.
static BigInteger bitsSent
Counts the numbe of bits sent to the server.
Definition: hub.h:144
Implementation of the public-key Paillier Cryptosystem.
Definition: paillier.h:103
Definition of struct TestDataRow.
KernelTypes
Types of implemented kernels.
Definition: secure_svm.h:68
BigInteger svWeightScaling
The scaling applied to the SVM parameters, and .
Definition: hub.h:120
Definition of class CpuTimer.
std::map< std::string, unsigned int > safetyBlockFalsePositives
Vector containing number of false positives per safety SVM.
Definition: hub.h:135
Defines RandomProvider.
Definition of class Paillier.
static bool measureTraffic
Enables traffic profiling.
Definition: hub.h:141
std::vector< std::map< std::string, TestDataRow > > safetyTestData
The safety block test data array (vector of collection of rows; each file should have the same number...
Definition: hub.h:126
std::shared_ptr< const Server > server
A reference to the recommendations server.
Definition: hub.h:104
std::map< std::string, unsigned int > safetyBlockFalseNegatives
Vector containing number of false negatives per safety SVM.
Definition: hub.h:138
~Hub()
Destructor - void implementation.
Definition: hub.h:71
BigInteger featureScalingFactor
The scaling applied to the test and model vectors and .
Definition: hub.h:117
Definition of class Server.
The public key container structure for the Paillier cryptosystem.
Definition: paillier.h:49