Medical Recommendations Server. More...
#include <server.h>
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 Hub > | client |
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::Ciphertext > | dummyEncryptedPreferenceScores |
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. | |
Medical Recommendations Server.
Definition at line 62 of file secure_recommendations/server.h.
SeComLib::SecureRecommendations::Server::Server | ( | const PaillierPublicKey & | key | ) |
Constructor.
Initializes the client's public key
Precomputes required data
key | The 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.
void SeComLib::SecureRecommendations::Server::DebugValue | ( | const Paillier::Ciphertext & | value | ) | const |
Sends a request to the client to debug an encrypted value.
value | the 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.
clusterVotes | returns a vector containing [1] at the index of the cluster with the maximum number of votes and [0] everywhere else |
safetyPredictions | returns a vector which, for each safety SVM, contains [1] if the SVM produced a positive value and [0] otherwise |
medicalRelevanceTestData | the medical relevance test data |
safetyTestData | the safety test data |
Missing | safety 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)
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:
firstTwoBlocksPredictions | returns a vector containing the combined predictions of the first two blocks |
safetyPredictions | returns a vector which, for each safety SVM, contains [1] if the SVM produced a positive value and [0] otherwise |
medicalRelevanceTestData | the medical relevance test data |
safetyTestData | the 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.
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.
Definition at line 257 of file secure_recommendations/server.cpp.
|
private |
Returns the total number of votes per cluster.
votes | a vector containing the encrypted values predicted by the SVMs |
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.
Definition at line 78 of file secure_recommendations/server.cpp.
|
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.
data | a 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.
numerator | the value of the numerator |
denominators | vector 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.
|
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.
data | a 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.
|
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 \)
modelsDirectory | the path to the medical relevance SVM models directory |
Definition at line 288 of file secure_recommendations/server.cpp.
|
private |
Loads the Safety block SVM models.
modelsDirectory | the path to the safety SVM models directory |
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
client | a client instance |
Definition at line 67 of file secure_recommendations/server.cpp.
|
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.