SeComLib
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Macros Pages
Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
SeComLib::SecureRecommendations::Server Class Reference

Medical Recommendations Server. More...

#include <server.h>

Inheritance diagram for SeComLib::SecureRecommendations::Server:

Public Types

typedef std::vector
< Paillier::Ciphertext
EncryptedSvmValues
 Vector of encrypted SVM evaluations.
 
typedef std::vector
< Paillier::Ciphertext
EncryptedClusterVotes
 Container for the encrypted cluster votes.
 

Public Member Functions

 Server (const PaillierPublicKey &key)
 Constructor. More...
 
 ~Server ()
 Destructor.
 
void SetClient (const std::shared_ptr< const Hub > &client)
 Sets a reference to the client. More...
 
void Initialize ()
 Initializes the internal SVM instances. More...
 
void InteractiveSecureDivision (const BigInteger &numerator, SecureSvm::EncryptedVector &denominators) const
 Performs the interactive secure division protocol. More...
 
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 predictions for accuracy analysis. More...
 
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 safety block predictions for performance analysis. More...
 
std::vector< std::string > GetSafetyBlockSvmsUnsafeClasses () const
 Returns the unsafe classes for each safety SVM. More...
 
std::deque< std::string > GetSafetyBlockModelFiles () const
 Returns the names of the model files for the safety block. More...
 
void DebugValue (const Paillier::Ciphertext &value) const
 Sends a request to the client to debug an encrypted value. More...
 

Private Types

typedef std::vector< std::pair
< size_t, size_t > > 
PermutationVector
 Define the permutation map container.
 

Private Member Functions

void loadMedicalRelevanceSvmModels (const std::string &modelsDirectory)
 Loads the Medical Relevance block SVM models. More...
 
void loadSafetySvmModels (const std::string &modelsDirectory)
 Loads the Safety block SVM models. More...
 
Server::EncryptedClusterVotes getTotalClusterVotes (Server::EncryptedSvmValues &votes) const
 Returns the total number of votes per cluster. More...
 
void interactiveSignEvaluation (Server::EncryptedSvmValues &data) const
 Performs the interactive sign evaluation protocol inplace. More...
 
void interactiveMaximumEvaluation (Server::EncryptedClusterVotes &data) const
 Performs the interactive maximum evaluation protocol inplace. More...
 
 Server (Server const &)
 Copy constructor - not implemented.
 
Server operator= (Server const &)
 Copy assignment operator - not implemented.
 

Private Attributes

std::weak_ptr< const Hubclient
 
Paillier cryptoProvider
 The crypto provider.
 
PaillierPublicKey clientPublicKey
 The client public key.
 
SecureSvm::KernelTypes kernel
 The SVM kernel type.
 
unsigned int contentItemCount
 The number of content items.
 
std::vector< BigInteger > dummyContentItems
 Dummy vector of content items.
 
std::vector< Paillier::CiphertextdummyEncryptedPreferenceScores
 Dummy vector of encrypted preference scores.
 
unsigned int blindingFactorSize
 The maximum size of the blinding factors.
 
std::string modelFileExtension
 The model files extension.
 
std::string medicalRelevanceModelsDirectory
 Medical relevance models folder.
 
std::string safetyModelsDirectory
 The full path to the safety block models directory.
 
std::deque< std::string > safetySvmModelFiles
 The safety block model files.
 
std::vector< std::unique_ptr
< SecureSvm > > 
medicalRelevanceSvms
 Medical Relevance Block SVM models.
 
std::vector< std::unique_ptr
< SecureSvm > > 
safetySvms
 Safety Block SVM models.
 
unsigned int medicalRelevanceClusterCount
 Number of clusters for the Medical Relevance Block.
 
Server::EncryptedClusterVotes encryptedClusterVotes
 Stores the number of votes received for each cluster after evaluating the SVMs.
 
Paillier::Ciphertext encryptedZero
 Precompute [0] for optimization purposes.
 
Paillier::Ciphertext encryptedOne
 Precompute [1] for optimization purposes.
 

Detailed Description

Medical Recommendations Server.

Definition at line 62 of file secure_recommendations/server.h.

Constructor & Destructor Documentation

SeComLib::SecureRecommendations::Server::Server ( const PaillierPublicKey key)

Constructor.

Initializes the client's public key

Precomputes required data

Parameters
keyThe client public key

Initialize the medical relevance SVM models parameters

Initialize the safety SVM models parameters

Precompute [0] and [1] for optimization purposes

Definition at line 41 of file secure_recommendations/server.cpp.

Member Function Documentation

void SeComLib::SecureRecommendations::Server::DebugValue ( const Paillier::Ciphertext value) const

Sends a request to the client to debug an encrypted value.

Parameters
valuethe value to debug

Definition at line 277 of file secure_recommendations/server.cpp.

void SeComLib::SecureRecommendations::Server::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 predictions for accuracy analysis.

Determines the cluster with the highest number of votes.

Given N, the number of clusters, for each cluster we must perform binary clasification and then sum the votes for each cluster. The cluster having the highest number of votes is determined with an interactive protocol.

Evaluates the safety block SVMs.

Parameters
clusterVotesreturns a vector containing [1] at the index of the cluster with the maximum number of votes and [0] everywhere else
safetyPredictionsreturns a vector which, for each safety SVM, contains [1] if the SVM produced a positive value and [0] otherwise
medicalRelevanceTestDatathe medical relevance test data
safetyTestDatathe safety test data
Exceptions
Missingsafety test data

First, we evaluate all the medical relevance SVMs

We also evaluate the safety SVMs (we will pop these out later, because we want to perform the interactive sign evaluation in a single step)

Todo:
Throw a custom exception here...

Ask the client to determine the sign with an interactive secure permutation algorithm, such that for each value we will contain either [0] or [1]

Compute the total number of votes for each cluster (we add the elements on each column together)

Ask the client to evaluate the cluster with the maximum number of votes The results vector will contain [1] at the index of the maximum and [0] at the other indexes

Definition at line 166 of file secure_recommendations/server.cpp.

void SeComLib::SecureRecommendations::Server::GetPerformancePredictions ( SecureSvm::EncryptedVector firstTwoBlocksPredictions,
SecureSvm::EncryptedVector safetyPredictions,
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 safety block predictions for performance analysis.

Evaluates the output of the first two blocks:

  • Produces a vecor of sum_j(dummyEncryptedContentItems[i] * vote[j])
  • Adds the above vector homomorphically to the dummyEncryptedPreferenceScores and obtains the firstTwoBlocksPredictions
  • Sets the first 5 elements of the dummyEncryptedSafetyScores to the value obtained by evaluating the safety SVM
Parameters
firstTwoBlocksPredictionsreturns a vector containing the combined predictions of the first two blocks
safetyPredictionsreturns a vector which, for each safety SVM, contains [1] if the SVM produced a positive value and [0] otherwise
medicalRelevanceTestDatathe medical relevance test data
safetyTestDatathe safety test data

Evaluate the medical relevance votes and the safety prediction

Compute the outptut of the first two blocks

Definition at line 233 of file secure_recommendations/server.cpp.

std::deque< std::string > SeComLib::SecureRecommendations::Server::GetSafetyBlockModelFiles ( ) const

Returns the names of the model files for the safety block.

Returns
a vector containing the names of the model files for the safety block

Definition at line 270 of file secure_recommendations/server.cpp.

std::vector< std::string > SeComLib::SecureRecommendations::Server::GetSafetyBlockSvmsUnsafeClasses ( ) const

Returns the unsafe classes for each safety SVM.

Returns
a vector containing the set of unsafe classes for each safety SVM

Definition at line 257 of file secure_recommendations/server.cpp.

Server::EncryptedClusterVotes SeComLib::SecureRecommendations::Server::getTotalClusterVotes ( Server::EncryptedSvmValues votes) const
private

Returns the total number of votes per cluster.

Parameters
votesa vector containing the encrypted values predicted by the SVMs
Returns
Vector containing the votes for each cluster

We want to compute the sum of elements on each column, so we iterate over the lines in the inner loop

We computed only the SVM predictions for cluster(i, j), where i < j, because for i > j, prediction(i, j) = 1 - prediction(j, i)

Definition at line 324 of file secure_recommendations/server.cpp.

void SeComLib::SecureRecommendations::Server::Initialize ( )

Initializes the internal SVM instances.

This method needs to be called first!

Loads the medical relevance and the safety SVMs.

Generates dummy data for the content items, the preferences block and the safety block.

Load medical relevance block SVMs

Load safety block SVMs

Generate a dummy vector of content items with values from 0 to 10 and scale them with 10.

Generate a dummy vector of encrypted preferences block scores with values from 1 to 10.

Todo:
Is the range really from 1 to 10 or is it 0 to 10?

Definition at line 78 of file secure_recommendations/server.cpp.

void SeComLib::SecureRecommendations::Server::interactiveMaximumEvaluation ( Server::EncryptedClusterVotes data) const
private

Performs the interactive maximum evaluation protocol inplace.

Overwrites the input data with a vector containing [1] at the location of the maximum and [0] everywhere else.

Permutes the values.

Blinds the values multiplicatively and additively \( [w_i r_1 + r_2] = [w_i]^{r_1} r_2 \).

Calls the client's EvaluateMaximum method.

Reverses the permutation.

Parameters
dataa vector of encrypted cluster votes

Get a random permutation

Permute the input vector

Multiplicatively blind the values with a random factor \( r_1 > 0 \)

Additively blind the values with a random factor \( r_2 \)

Interact with the client

Reverse the permutation

Definition at line 407 of file secure_recommendations/server.cpp.

void SeComLib::SecureRecommendations::Server::InteractiveSecureDivision ( const BigInteger &  numerator,
SecureSvm::EncryptedVector denominators 
) const

Performs the interactive secure division protocol.

Blinds each denominator multiplicatively with a factor \( r_i \), such that it does not generate overflows.

Permutes all the denominators randomly.

Sends the permuted vector of blinded denominators to the client and receives the results of \( 1 / d_i \).

Undoes the random permutation and homomorphically multiplies each result by \( r_i \), in order to get the desired values.

Parameters
numeratorthe value of the numerator
denominatorsvector of encrypted denominators. Will be overwritten by the kernel values

Blind the encrypted denominators. Store the blinding factors.

\( r_i \) must always be > 0!

Get a random permutation

Permute the blinded encrypted denominators.

Interact with the client

Reverse the permutation

Undo the blinding

Definition at line 119 of file secure_recommendations/server.cpp.

void SeComLib::SecureRecommendations::Server::interactiveSignEvaluation ( Server::EncryptedSvmValues data) const
private

Performs the interactive sign evaluation protocol inplace.

Overwrites the input data with a vector of votes ([0] or [1]) for each value in the input vector.

Permutes the values.

Multiplicatively blinds the values: \( [f_i(x)]^{r_i} \).

Calls the client's EvaluateSign method.

Reverses the permutation.

Parameters
dataa vector containing the encypted values predicted by the SVMs

Get a random permutation

Permute the input vector

Multiplicatively blind the values with a random factor \( r \)

Interact with the client

Reverse the permutation

Definition at line 374 of file secure_recommendations/server.cpp.

void SeComLib::SecureRecommendations::Server::loadMedicalRelevanceSvmModels ( const std::string &  modelsDirectory)
private

Loads the Medical Relevance block SVM models.

The SVMs are binary classifiers between two clusters.

Since the SVMs are symmetric ( \( SVM_{jvi} = 1 - SVM_{ivj} \)), we only load the ones where \( i < j \)

Parameters
modelsDirectorythe path to the medical relevance SVM models directory

Definition at line 288 of file secure_recommendations/server.cpp.

void SeComLib::SecureRecommendations::Server::loadSafetySvmModels ( const std::string &  modelsDirectory)
private

Loads the Safety block SVM models.

Parameters
modelsDirectorythe path to the safety SVM models directory
Todo:
Throw a custom error.

Definition at line 305 of file secure_recommendations/server.cpp.

void SeComLib::SecureRecommendations::Server::SetClient ( const std::shared_ptr< const Hub > &  client)

Sets a reference to the client.

Associates the server with the client instance

Parameters
clienta client instance

Definition at line 67 of file secure_recommendations/server.cpp.

Member Data Documentation

std::weak_ptr<const Hub> SeComLib::SecureRecommendations::Server::client
private

A reference to the client. Use weak_ptr here in order to avoid a circular deadlock with the client which holds a reference back to the server

Definition at line 106 of file secure_recommendations/server.h.


The documentation for this class was generated from the following files: