kaplan_meier.data_owner module¶
Module implements the data owners Alice and Bob.
- class kaplan_meier.data_owner.Alice(*args, time_label='time', event_label='event', security_level=40, **kwargs)[source]¶
Bases:
DataOwner
Alice player in the MPC protocol
- __init__(*args, time_label='time', event_label='event', security_level=40, **kwargs)[source]¶
Initializes player Alice
- Parameters:
time_label (
str
) – the label used to represent the ‘time’ column in the data setevent_label (
str
) – the label used to represent the ‘event’ column in the data setsecurity_level (
int
|None
) – the statistical security level to use for the additive masking (in bits)args (
Any
) – arguments to pass on to base classkwargs (
Any
) – keyword arguments to pass on to base class
- compute_kaplan_meier_minimal_statistics()[source]¶
Method to compute the minimal statistics of the protocol.
- Return type:
None
- compute_logrank_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: expectation_factors, variance_factors, variance_factors_2. These factors satisfy the following relations: :rtype:
None
- Expected number of observations in group i =
expectation_factors[i] * at_risk_group[i]
- Variance of observations in group i =
(variance_factors_2[i] - variance_factors[i] * at_risk_group[i]) * at_risk_group[i]
Generates additive secret shares.
- Return type:
None
- property kaplan_meier_statistics_group: ndarray[Any, dtype[object_]]¶
Encrypted table with Kaplan-Meier statistics per group.
Row i contains data for the i-th unique event times. The first set of (groups-1) columns contains the number of observed events for group 1, 2, …, groups-1. The second set of (groups-1) columns contains the number of individuals at risk for those groups.
- Returns:
the constructed table
- Raises:
ValueError – raised when table is not yet available
- property kaplan_meier_statistics_total: ndarray[Any, dtype[int64]]¶
Table with Kaplan-Meier statistics of the entire population.
Row i contains data for the i-th unique event times. The first column contains the number of observed events for the entire population. The second column contains the number of individuals at risk for the entire population.
- Returns:
the constructed table
- Raises:
ValueError – raised when table is not yet available
- mask_kaplan_meier_statistics_group()[source]¶
Masks the table with Kaplan-meier group statistics.
- Return type:
ndarray
[Any
,dtype
[object_
]]- Returns:
the masked table
- property nr_groups: int¶
Number of groups in the datasets.
- Returns:
number of groups
- Raises:
ValueError – raised when number of groups is not available (yet)
- property nr_unique_event_times: int¶
Number of unique event times.
- Returns:
number of unique event times
- 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
Sends additive secret share to party Bob.
- Return type:
None
- signed_randomness()[source]¶
Returns a signed random plaintext value.
- Return type:
SupportsInt
- Returns:
signed random plaintext value
- property unique_event_times: ndarray[Any, dtype[int64]]¶
List of unique event times.
- Returns:
unique event times
- 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 encryptionargs (
Any
) – arguments to pass on to base classkwargs (
Any
) – keyword arguments to pass on to base class
- 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
[int64
]]- Returns:
a decrypted dataset
Decrypt share
- Parameters:
data (
ndarray
[Any
,dtype
[object_
]]) – the dataset (share) to decrypt- Return type:
ndarray
[Any
,dtype
[int64
]]- Returns:
decrypted data set
- property nr_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 ownerpool (
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¶
The loaded dataset
- Returns:
dataset
- Raises:
ValueError – raised when there is no data available
- encrypt(data)[source]¶
Method to encrypt a dataset using the initialized Paillier scheme
- Parameters:
data (
ndarray
[Any
,dtype
[int64
]]) – the dataset to encrypt- Return type:
ndarray
[Any
,dtype
[object_
]]- Returns:
an encrypted dataset
- property nr_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 frommsg_id (
str
|None
) – the message id
- Return type:
Any
- Returns:
the received message
- property records: int¶
Number of records in the loaded dataset
- Returns:
number of records
- async send_message(receiver, message, msg_id=None)[source]¶
Sends a message to a party (with an optional message identifier)
- Parameters:
receiver (
str
) – the party to send a message tomessage (
Any
) – the message to sendmsg_id (
str
|None
) – the message id
- Return type:
None
- start_randomness_generation(amount)[source]¶
Kicks off the randomness generation. This boosts performance. In particular will this decrease the total runtime (as data owners can already generate randomness before they need it).
- Parameters:
amount (
int
) – amount of randomness to precompute.- Return type:
None
- kaplan_meier.data_owner.randomize_ndarray(arr)[source]¶
Randomize all elements in an numpy array with ciphertexts.
This function calls ‘RandomizableCiphertext.randomize’ ‘arr.size’ times, as expected. Note that this contrasts with the ‘arr.size+1’ calls made by ‘np.vectorize(lambda _: _.randomize())(arr)’.
- Parameters:
arr (
ndarray
[Any
,dtype
[object_
]]) – array to be randomized- Return type:
None