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 generation

  • 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.

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

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

Return type

int

Returns

number of groups

Raises

ValueError – raised when number of groups is not available (yet)

property hidden_table: ndarray[PaillierCiphertext]

Hidden table

Return type

ndarray[PaillierCiphertext]

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[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.

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).

Return type

int

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[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

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: 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 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

Return type

int

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