fl4health.utils.metric_aggregation module

evaluate_metrics_aggregation_fn(all_client_metrics)[source]

Function for evaluate that computes a weighted aggregation of the client metrics and normalizes by the total number of samples.

Parameters:

all_client_metrics (list[tuple[int, Metrics]]) – A list of tuples with the sample counts and metrics for each client.

Returns:

The aggregated normalized metrics.

Return type:

Metrics

fit_metrics_aggregation_fn(all_client_metrics)[source]

Function for fit that computes a weighted aggregation of the client metrics and normalizes by the total number of samples.

Parameters:

all_client_metrics (list[tuple[int, Metrics]]) – A list of tuples with the sample counts and metrics for each client.

Returns:

The aggregated normalized metrics.

Return type:

Metrics

metric_aggregation(all_client_metrics)[source]

Function that computes a weighted aggregation of metrics normalized by the total number of samples.

Parameters:

all_client_metrics (list[tuple[int, Metrics]]) – A list of tuples with the sample counts and metrics for each client.

Returns:

The total number of examples along with aggregated metrics.

Return type:

tuple[int, Metrics]

normalize_metrics(total_examples, aggregated_metrics)[source]

Function that normalizes metrics by provided sample count.

Parameters:
  • total_examples (int) – The total number of samples across all client datasets.

  • aggregated_metrics (Metrics) – Metrics that have been aggregated across clients.

Returns:

The metrics normalized by total_examples.

Return type:

Metrics

uniform_evaluate_metrics_aggregation_fn(all_client_metrics)[source]

Function for evaluate that computes aggregation of the client metrics and normalizes by the number of clients that contributed to the metric.

Parameters:

all_client_metrics (list[tuple[int, Metrics]]) – A list of tuples with the sample counts and metrics for each client.

Returns:

The aggregated normalized metrics.

Return type:

Metrics

uniform_metric_aggregation(all_client_metrics)[source]

Function that aggregates client metrics and divides by the number of clients that contributed to metric.

Parameters:

all_client_metrics (list[tuple[int, Metrics]]) – A list of tuples with the sample counts and metrics for each client.

Returns:

Client counts per metric and the uniformly aggregated metrics.

Return type:

tuple[defaultdict[str, int], Metrics]

uniform_normalize_metrics(total_client_count_by_metric, aggregated_metrics)[source]

Function that normalizes metrics based on how many clients contributed to the metric.

Parameters:
  • total_client_count_by_metric (defaultdict[str, int]) – The count of clients that contributed to each metric.

  • aggregated_metrics (Metrics) – Metrics that have been aggregated across clients.

Returns:

The normalized metrics.

Return type:

Metrics