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, training_strategy='iptw', cox_fit_cols=None, propensity_fit_cols=None, 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) –

  • training_strategy (str) –

  • cox_fit_cols (None | list) –

  • propensity_fit_cols (None | list) –

  • store_hessian (bool) –

  • with_batch_norm_parameters (bool) –

  • use_gpu (bool) –

  • robust (bool) –

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:

X input to the Cox model, y target of Cox model, weights propensity weights

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]