kaplan_meier.data_owner module
Module implements the data owners Alice and Bob.
- class kaplan_meier.data_owner.Alice(*args, nr_of_threads=4, time_label='time', event_label='event', **kwargs)[source]
- Bases: - DataOwner- Alice player in the MPC protocol - __init__(*args, nr_of_threads=4, time_label='time', event_label='event', **kwargs)[source]
- Initializes player Alice - Parameters:
- nr_of_threads ( - int) – the number of threads to use for randomness generation
- time_label ( - str) – the label used to represent the ‘time’ column in the data set
- event_label ( - str) – the label used to represent the ‘event’ column in the data set
- args ( - Any) – arguments to pass on to base class
- kwargs ( - Any) – keyword arguments to pass on to base class
 
 
 - Number of columns in the hidden table. Two columns per group; one for the number of events on a given event time and one for the number of people at risk at that time. - Returns:
- number of columns in the hidden table 
 
 - compute_factors()[source]
- Pre-computes several factors for in the computation of the log- rank statistic, leveraging information known by Alice only. - Computes the following factors: dev_factors, var_factors, var_factors_2. These factors satisfy the following relations: :rtype: - None- Expected number of deaths in group i =
- dev_factors[i] * at_risk_group[i] 
- Variance of deaths in group i =
- (var_factors_2[i] - var_factors[i] * at_risk_group[i]) * at_risk_group[i] 
 
 - Method to compute the hidden table of the protocol. - Return type:
- None
 
 - Generates additive secret shares. - Return type:
- None
 
 - property groups: int
- Number of groups in the datasets - Returns:
- number of groups 
- Raises:
- ValueError – raised when number of groups is not available (yet) 
 
 - Hidden table - Returns:
- the constructed hidden table 
- Raises:
- ValueError – raised when hidden table is not yet available. 
 
 - Masks the hidden table. - Return type:
- ndarray[- Any,- dtype[- float64]]
- Returns:
- a masked hidden table 
 
 - property plain_table: ndarray[Any, dtype[int32]]
- Plain table - Returns:
- plaintext result of some computation in table format 
- Raises:
- ValueError – raised when plain table is not yet available. 
 
 - static re_randomize(ciphertext)[source]
- Re-randomises a ciphertext - Parameters:
- ciphertext ( - PaillierCiphertext) – ciphertext to randomize
- Return type:
- None
 
 - async receive_encrypted_group_data()[source]
- Method to receive the encrypted group data from party Bob. - Return type:
- None
 
 - async receive_number_of_groups()[source]
- Method to receive the number of groups identified by party Bob. - Return type:
- None
 
 - async receive_paillier_scheme()[source]
- Method to receive the Paillier scheme that is used by party Bob. - Return type:
- None
 
 - Number of rows in the hidden table. Equals number of unique event times (ignoring censorings). - Returns:
- number of rows in the hidden table 
 
 - Sends additive secret share to party Bob. - Return type:
- None
 
 
- class kaplan_meier.data_owner.Bob(*args, paillier_scheme=<tno.mpc.encryption_schemes.paillier.paillier.Paillier object>, **kwargs)[source]
- Bases: - DataOwner- Bob player in the MPC protocol - __init__(*args, paillier_scheme=<tno.mpc.encryption_schemes.paillier.paillier.Paillier object>, **kwargs)[source]
- Initializes player Bob - Parameters:
- paillier_scheme ( - Paillier) – the Paillier scheme to use for encryption
- args ( - Any) – arguments to pass on to base class
- kwargs ( - Any) – keyword arguments to pass on to base class
 
 
 - Decrypt share - Parameters:
- data ( - ndarray[- Any,- dtype[- object_]]) – the dataset (share) to decrypt
- Return type:
- ndarray[- Any,- dtype[- float64]]
- Returns:
- decrypted data set 
 
 - property groups: int
- Number of groups in the loaded dataset - Returns:
- number of groups 
 
 - Receive additive secret share produced by party Alice. - Return type:
- None
 
 
- class kaplan_meier.data_owner.DataOwner(data, pool, *args, **kwargs)[source]
- Bases: - Player- Data owner in the MPC protocol - __init__(data, pool, *args, **kwargs)[source]
- Initializes data owner - Parameters:
- data ( - DataFrame) – the data to use for this data owner
- pool ( - Pool) – a communication pool
- args ( - Any) – arguments to pass on to base class
- kwargs ( - Any) – keyword arguments to pass on to base class
 
 
 - property data: DataFrame | ndarray[Any, dtype[int32]]
- The loaded dataset - Returns:
- dataset 
- Raises:
- ValueError – raised when there is no data available 
 
 - decrypt(data)[source]
- Method to decrypt a dataset using the initialized Paillier scheme - Parameters:
- data ( - ndarray[- Any,- dtype[- object_]]) – the dataset to decrypt
- Return type:
- ndarray[- Any,- dtype[- float64]]
- Returns:
- a decrypted dataset 
 
 - encrypt(data)[source]
- Method to encrypt a dataset using the initialized Paillier scheme - Parameters:
- data ( - ndarray[- Any,- dtype[- float64]]) – the dataset to encrypt
- Return type:
- ndarray[- Any,- dtype[- object_]]
- Returns:
- an encrypted dataset 
 
 - property groups: int
- Number of groups in the loaded datasets - Returns:
- number of groups 
- Raises:
- NotImplementedError – raised when not implemented 
 
 - property paillier_scheme: Paillier
- The Paillier scheme - Returns:
- Paillier scheme 
- Raises:
- ValueError – raised when Paillier scheme is not available yet. 
 
 - async receive_message(party, msg_id=None)[source]
- Receives a message from a party (belonging to an optional message identifier) - Parameters:
- party ( - str) – the party to receive a message from
- msg_id ( - Optional[- str]) – the message id
 
- Return type:
- Any
- Returns:
- the received message 
 
 - property records: int
- Number of records in the loaded dataset - Returns:
- number of records