33 namespace SecureRecommendations {
79 std::cout <<
"Preprocessing model files data." << std::endl;
84 std::cout <<
"Finished preprocessing data from " << this->
medicalRelevanceSvms.size() <<
" medical relevance block model files." << std::endl;
89 std::cout <<
"Finished preprocessing data from " << this->
safetySvms.size() <<
" safety block model files." << std::endl;
93 this->
dummyContentItems.emplace_back((RandomProvider::GetInstance().GetRandomInteger(BigInteger(9)) + 1) * 10);
96 std::cout <<
"Finished generating dummy content items." << std::endl;
104 std::cout <<
"Finished generating dummy preferences block scores." << std::endl;
120 std::vector<BigInteger> blindingFactors;
123 for (
size_t i = 0; i < denominators.size(); ++i) {
125 blindingFactors.emplace_back(RandomProvider::GetInstance().GetRandomInteger(this->
blindingFactorSize) + 1);
128 denominators[i] = denominators[i] * blindingFactors.back();
135 permutation.
Permute(denominators);
138 this->
client.lock()->EvaluateDivision(numerator, denominators);
141 permutation.InvertPermutation(denominators);
144 for (
size_t i = 0; i < denominators.size(); ++i) {
148 denominators[i] = denominators[i] * blindingFactors[i];
175 svmPredictions.emplace_back(this->
medicalRelevanceSvms[i]->Predict(medicalRelevanceTestData.
x, medicalRelevanceTestData.
xx, medicalRelevanceTestData.
xSquared));
181 for (
size_t i = 0; i < this->
safetySvms.size(); ++i) {
182 std::map<std::string, TestDataRow>::const_iterator safetyTestDataIterator = safetyTestData.find(
safetySvms[i]->GetUnsafeClasses());
183 if (safetyTestData.end() != safetyTestDataIterator) {
186 svmPredictions.emplace_back(this->
safetySvms[i]->Predict((*safetyTestDataIterator).second.x, (*safetyTestDataIterator).second.xx, (*safetyTestDataIterator).second.xSquared));
192 throw std::runtime_error(
"Missing safety test data for unsafe classes: " +
safetySvms[i]->GetUnsafeClasses());
209 std::move(svmPredictions.begin() + this->
medicalRelevanceSvms.size(), svmPredictions.end(), std::back_inserter(safetyPredictions));
210 svmPredictions.erase(svmPredictions.begin() + this->
medicalRelevanceSvms.size(), svmPredictions.end());
258 std::vector<std::string> output;
260 for (
size_t i = 0; i < this->
safetySvms.size(); ++i) {
261 output.emplace_back(this->
safetySvms[i]->GetUnsafeClasses());
278 this->
client.lock()->DebugValue(value);
291 std::stringstream fileNameBuilder;
294 fileNameBuilder <<
"cluster" << (i + 1) <<
"v" << (j + 1) <<
"." + this->
modelFileExtension;
310 throw std::runtime_error(
"No model files found in directory: " + modelsDirectory);
344 index = i * (medicalRelevanceClusterCount - 1) - (i - 1) * i / 2 + j - (i + 1);
346 clusterVotes[i] = clusterVotes[i] + votes[index];
349 index = j * (medicalRelevanceClusterCount - 1) - (j - 1) * j / 2 + i - (j + 1);
352 clusterVotes[i] = clusterVotes[i] + this->
encryptedOne - votes[index];
382 for (Server::EncryptedSvmValues::iterator encryptedSvmValue = data.begin(); encryptedSvmValue != data.end(); ++encryptedSvmValue) {
384 *encryptedSvmValue = *encryptedSvmValue * RandomProvider::GetInstance().GetRandomInteger(this->
blindingFactorSize);
388 this->
client.lock()->EvaluateSign(data);
391 permutation.InvertPermutation(data);
415 BigInteger r1 = RandomProvider::GetInstance().GetRandomInteger(this->
blindingFactorSize) + 1;
419 for (Server::EncryptedClusterVotes::iterator encryptedClusterVote = data.begin(); encryptedClusterVote != data.end(); ++encryptedClusterVote) {
421 *encryptedClusterVote = *encryptedClusterVote * r1 + r2;
425 this->
client.lock()->EvaluateMaximum(data);
428 permutation.InvertPermutation(data);
PaillierCiphertext Ciphertext
Provide public access to the T_Ciphertext type.
std::vector< Paillier::Ciphertext > EncryptedVector
Define a vector template specialization for vectors of encrypted data.
Ciphertext GetEncryptedOne(const bool randomized=true) const
Returns [1].
Processed test data container.
Paillier::Ciphertext encryptedOne
Precompute [1] for optimization purposes.
Ciphertext GetEncryptedZero(const bool randomized=true) const
Returns [0].
std::vector< std::unique_ptr< SecureSvm > > safetySvms
Safety Block SVM models.
void DebugValue(const Paillier::Ciphertext &value) const
Sends a request to the client to debug an encrypted value.
std::deque< std::string > safetySvmModelFiles
The safety block model files.
void interactiveMaximumEvaluation(Server::EncryptedClusterVotes &data) const
Performs the interactive maximum evaluation protocol inplace.
Server::EncryptedClusterVotes getTotalClusterVotes(Server::EncryptedSvmValues &votes) const
Returns the total number of votes per cluster.
void InteractiveSecureDivision(const BigInteger &numerator, SecureSvm::EncryptedVector &denominators) const
Performs the interactive secure division protocol.
void Initialize()
Initializes the internal SVM instances.
std::vector< BigInteger > dummyContentItems
Dummy vector of content items.
static Config & GetInstance()
Returns a reference to the singleton.
std::string medicalRelevanceModelsDirectory
Medical relevance models folder.
std::deque< std::string > GetSafetyBlockModelFiles() const
Returns the names of the model files for the safety block.
SecureSvm::EncryptedVector x
Encrypted test data vector.
std::vector< Paillier::Ciphertext > EncryptedClusterVotes
Container for the encrypted cluster votes.
virtual T_Ciphertext EncryptInteger(const BigInteger &plaintext) const
Encrypt an integer and apply randomization.
SecureSvm::KernelTypes kernel
The SVM kernel type.
PaillierPublicKey clientPublicKey
The client public key.
void loadMedicalRelevanceSvmModels(const std::string &modelsDirectory)
Loads the Medical Relevance block SVM models.
unsigned int contentItemCount
The number of content items.
std::vector< std::unique_ptr< SecureSvm > > medicalRelevanceSvms
Medical Relevance Block SVM models.
unsigned int medicalRelevanceClusterCount
Number of clusters for the Medical Relevance Block.
SecureSvm::EncryptedVector xSquared
Encrypted squared test data vector.
Permutation class which implements the Fisher-Yates (Knuth) shuffle algorithm.
static KernelTypes GetKernel(const std::string &input)
Converts the input string to the proper kernel.
Paillier cryptoProvider
The crypto provider.
Server(const PaillierPublicKey &key)
Constructor.
void GetPerformancePredictions(SecureSvm::EncryptedVector &firstTwoBlocksPredictions, SecureSvm::EncryptedVector &SafetyBlockPredictions, const TestDataRow &medicalRelevanceTestData, const std::map< std::string, TestDataRow > &safetyTestData) const
Procedure which computes (and returns) the predictions generated by the first two blocks and the safe...
Secure Support Vector Machine algorithm.
std::vector< Paillier::Ciphertext > EncryptedSvmValues
Vector of encrypted SVM evaluations.
void GetAccuracyPredictions(Server::EncryptedClusterVotes &clusterVotes, SecureSvm::EncryptedVector &safetyPredictions, const TestDataRow &medicalRelevanceTestData, const std::map< std::string, TestDataRow > &safetyTestData) const
Procedure which computes (and returns) the cluster votes for the first block and the medical safety p...
unsigned int blindingFactorSize
The maximum size of the blinding factors.
std::string modelFileExtension
The model files extension.
std::weak_ptr< const Hub > client
T GetParameter(const std::string ¶meter) const
Template method which returns the value of the specified configuration parameter. ...
std::vector< Paillier::Ciphertext > dummyEncryptedPreferenceScores
Dummy vector of encrypted preference scores.
std::string safetyModelsDirectory
The full path to the safety block models directory.
SecureSvm::EncryptedVector xx
Encrypted vector product combinations, , stored as an unraveled upper triangular matrix.
void SetClient(const std::shared_ptr< const Hub > &client)
Sets a reference to the client.
void Permute(T_DataType &vector) const
Applies the permutations to the input vector.
void interactiveSignEvaluation(Server::EncryptedSvmValues &data) const
Performs the interactive sign evaluation protocol inplace.
Paillier::Ciphertext encryptedZero
Precompute [0] for optimization purposes.
static std::deque< std::string > GetFilesInDirectory(const std::string &directory)
Traverses the provided directory (non-recursively) and extracts the absolute paths to all the files i...
void loadSafetySvmModels(const std::string &modelsDirectory)
Loads the Safety block SVM models.
Definition of class Server.
The public key container structure for the Paillier cryptosystem.
std::vector< std::string > GetSafetyBlockSvmsUnsafeClasses() const
Returns the unsafe classes for each safety SVM.