fedeca.algorithms

class TorchWebDiscoAlgo(model, batch_size, *args, duration_col='T', event_col='E', treated_col=None, initial_step_size=0.95, learning_rate_strategy='lifelines', standardize_data=True, tol=1e-16, penalizer=0.0, l1_ratio=0.0, propensity_model=None, propensity_strategy='iptw', store_hessian=False, with_batch_norm_parameters=False, use_gpu=True, robust=False, **kwargs)

Bases: TorchAlgo

WebDiscoAlgo class.

Parameters:
  • model (Module) –

  • batch_size (int | None) –

  • duration_col (str) –

  • event_col (str) –

  • treated_col (str) –

  • initial_step_size (float) –

  • learning_rate_strategy (str) –

  • standardize_data (bool) –

  • tol (float) –

  • penalizer (float) –

  • l1_ratio (float) –

  • propensity_model (Module) –

  • propensity_strategy (str) –

  • store_hessian (bool) –

  • with_batch_norm_parameters (bool) –

  • use_gpu (bool) –

  • robust (bool) –

build_X_y(data_from_opener, shared_state={})

Build appropriate X and y times from output of opener.

This function 1. uses the event column to inject the censorship information present in the duration column (given in absolute values) in the form of a negative sign. 2. Drop every covariate except treatment if self.strategy == “iptw”. 3. Standardize the data if self.standardize_data AND if it receives an outmodel. 4. Return the (unstandardized) input to the propensity model Xprop if necessary as well as the treated column to be able to compute the propensity weights.

Parameters:
  • data_from_opener (pd.DataFrame) – The output of the opener

  • shared_state (dict, optional) – Outmodel containing global means and stds. by default {}

Returns:

standardized X, signed times, treatment column and unstandardized propensity model input

Return type:

tuple

compute_X_y_and_propensity_weights(data_from_opener, shared_state)

Build appropriate X, y and weights from raw output of opener.

Uses the helper function build_X_y and the propensity model to build the weights.

Parameters:
  • data_from_opener (pd.DataFrame) – Raw output from opener

  • shared_state (dict, optional) – Outmodel containing global means and stds, by default {}

Returns:

_description_

Return type:

tuple

compute_local_phi_stats(data_from_opener, shared_state=None)

Compute local updates.

Parameters:
  • data_from_opener (Any) – _description_

  • shared_state (Optional[WebDiscoAveragedStates], optional) – _description_. Defaults to None.

Returns:

_description_

Return type:

WebDiscoSharedState

local_uncentered_moments(data_from_opener, shared_state=None)

Compute the local uncentered moments.

This method is transformed by the decorator to meet Substra API, and is executed in the training nodes. See build_compute_plan.

Parameters:
  • data_from_opener (pd.DataFrame) – Dataframe returned by the opener.

  • shared_state (None, optional) – Given by the aggregation node, here nothing, by default None.

Returns:

Local results to be shared via shared_state to the aggregation node.

Return type:

dict

predict(data_from_opener, shared_state=None)

Predict function.

Execute the following operations:

  • Create the test torch dataset.

  • Execute and return the results of the self._local_predict method

Parameters:
  • data_from_opener (typing.Any) – Input data

  • shared_state (typing.Any) – Latest train task shared state (output of the train method)

Return type:

Any

summary()

Summary of the class to be exposed in the experiment summary file.

Returns:

A json-serializable dict with the attributes the user wants to store

Return type:

dict

train(data_from_opener, shared_state=None)

Local train function.

Parameters:
  • data_from_opener (Any) – _description_

  • shared_state (Optional[WebDiscoAveragedStates], optional) – description_. Defaults to None.

Raises:

NotImplementedError – _description_

Returns:

_description_

Return type:

WebDiscoSharedState

property strategies: List[StrategyName]

List of compatible strategies.

Returns:

List of compatible strategies.

Return type:

typing.List[StrategyName]