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

property cols_in_hidden_table: int

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]

compute_hidden_table()[source]

Method to compute the hidden table of the protocol.

Return type:

None

generate_share()[source]

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)

property hidden_table: ndarray[Any, dtype[object_]]

Hidden table

Returns:

the constructed hidden table

Raises:

ValueError – raised when hidden table is not yet available.

mask_hidden_table()[source]

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.

re_randomise_ht()[source]

Re-randomises the hidden table

Return type:

None

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

property rows_in_hidden_table: int

Number of rows in the hidden table. Equals number of unique event times (ignoring censorings).

Returns:

number of rows in the hidden table

async send_share()[source]

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

async start_protocol()[source]

Starts and runs the protocol

Return type:

None

start_randomness_generation()[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).

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

async decrypt_share(data)[source]

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

async receive_share()[source]

Receive additive secret share produced by party Alice.

Return type:

None

async send_encrypted_data()[source]

Sends the encrypted dataset to party Alice.

Return type:

None

async send_number_of_groups()[source]

Sends the number of groups to party Alice.

Return type:

None

async send_paillier_scheme()[source]

Sends the used Paillier scheme to party Alice.

Return type:

None

async start_protocol()[source]

Starts and runs the protocol

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

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 to

  • message (Any) – the message to send

  • msg_id (Optional[str]) – the message id

Return type:

None

stop_randomness_generation()[source]

Stop generation of randomness.

Return type:

None