nvflare.app_common.workflows.lr.fedavg module

Federated Averaging for Logistic Regression with Newton-Raphson method using Numpy

class FedAvgLR(damping_factor: float, epsilon: float = 1.0, model_dir: str = 'models', model_name: str = 'weights.npy', n_features: int = 13, aggregator: ~nvflare.app_common.aggregators.weighted_aggregation_helper.WeightedAggregationHelper = <nvflare.app_common.aggregators.weighted_aggregation_helper.WeightedAggregationHelper object>, persistor: ~nvflare.app_common.np.np_model_persistor.NPModelPersistor | None = None, *args, **kwargs)[source]

Bases: BaseFedAvg

Initialize the FedAvgLR class for Federated Averaging with Newton-Raphson optimization.

Parameters:
  • damping_factor (float) – Damping factor for Newton-Raphson updates, used to control the step size.

  • epsilon (float, optional) – Regularization factor to avoid empty Hessian matrix inversion. Defaults to 1.0.

  • model_dir (str, optional) – Directory to save and load the model. Defaults to “models”.

  • model_name (str, optional) – Name of the model file. Defaults to “weights.npy”.

  • n_features (int, optional) – Number of features in the dataset. Defaults to 13.

  • aggregator (WeightedAggregationHelper, optional) – Helper for weighted aggregation of model updates.

  • persistor (Optional[NPModelPersistor], optional) – Custom persistor for model saving and loading. If not provided, a default LRModelPersistor is used.

  • *args – Additional positional arguments passed to the base class.

  • **kwargs – Additional keyword arguments passed to the base class.

This class implements the Federated Averaging algorithm using the Newton-Raphson method for optimization. It supports flexible model persistence through customizable persistors, allowing integration with different storage backends or model formats.

load_model() FLModel[source]

Load initial model from persistor. If persistor is not configured, returns empty FLModel.

Returns:

FLModel

newton_raphson_aggregator_fn(results: List[FLModel])[source]

Custom aggregator function for second order Newton-Raphson optimization.

This uses the default thread-safe WeightedAggregationHelper, which implement a weighted average of all values received from a result dictionary.

Parameters:

results – a list of FLModel`s. Each `FLModel is received from a client. The field params is a dictionary that contains values to be aggregated: the gradient and hessian.

run() None[source]

The run function executes the logic of federated second order Newton-Raphson optimization.

save_model(model: FLModel) None[source]

Saves model with persistor. If persistor is not configured, does not save.

Parameters:

model (FLModel) – model to save.

Returns:

None

update_model(model, model_update, replace_meta=True) FLModel[source]

Update logistic regression parameters based on aggregated gradient and hessian.