kaplan_meier.data_owner module
Module implements the data owners Alice and Bob.
- class kaplan_meier.data_owner.Alice(*args, nr_of_threads=4, **kwargs)[source]
Bases:
DataOwner
Alice player in the MPC protocol
- __init__(*args, nr_of_threads=4, **kwargs)[source]
Initializes player Alice
- Parameters
nr_of_threads (
int
) – the number of threads to use for randomness generationargs (
Any
) – arguments to pass on to base classkwargs (
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.
- Return type
int
- 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:
- 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]
- Return type
None
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
- Return type
int
- Returns
number of groups
- Raises
ValueError – raised when number of groups is not available (yet)
Hidden table
- Return type
ndarray
[PaillierCiphertext
]- Returns
the constructed hidden table
- Raises
ValueError – raised when hidden table is not yet available.
Masks the hidden table.
- Return type
ndarray
[float64
]- Returns
a masked hidden table
- property plain_table: ndarray[int32]
Plain table
- Return type
ndarray
[int32
]- 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).
- Return type
int
- 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 encryptionargs (
Any
) – arguments to pass on to base classkwargs (
Any
) – keyword arguments to pass on to base class
Decrypt share
- Parameters
data (
ndarray
[PaillierCiphertext
]) – the dataset (share) to decrypt- Return type
Any
- Returns
decrypted data set
- property groups: int
Number of groups in the loaded dataset
- Return type
int
- 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 poolargs (
Any
) – arguments to pass on to base classkwargs (
Any
) – keyword arguments to pass on to base class
- property data: Union[DataFrame, ndarray[int32]]
The loaded dataset
- Return type
Union
[DataFrame
,ndarray
[int32
]]- 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
[PaillierCiphertext
]) – the dataset to decrypt- Return type
ndarray
[Any
]- Returns
a decrypted dataset
- encrypt(data)[source]
Method to encrypt a dataset using the initialized Paillier scheme
- Parameters
data (
ndarray
[float64
]) – the dataset to encrypt- Return type
ndarray
[PaillierCiphertext
]- Returns
an encrypted dataset
- property groups: int
Number of groups in the loaded datasets
- Return type
int
- Returns
number of groups
- Raises
NotImplementedError – raised when not implemented
- property paillier_scheme: Paillier
The Paillier scheme
- Return type
Paillier
- 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 (
Optional
[str
]) – the message id
- Return type
Any
- Returns
the received message
- property records: int
Number of records in the loaded dataset
- Return type
int
- Returns
number of records