Trainer Set

Trainer Set#

class rizemind.strategies.contribution.shapley.trainer_set.TrainerSet(id: str, members: list[ChecksumAddress])[source]

Bases: object

A set of trainers forming a coalition.

id

Unique identifier for this trainer set.

Type:

str

members

List of trainer addresses that are members of this set.

Type:

list[eth_typing.evm.ChecksumAddress]

id: str
members: list[ChecksumAddress]
size() int[source]

Get the number of trainers in this set.

Returns:

The count of member trainers.

class rizemind.strategies.contribution.shapley.trainer_set.TrainerSetAggregate(id: str, members: list[ChecksumAddress], parameters: Parameters, config: dict[str, bool | bytes | float | int | str])[source]

Bases: TrainerSet

A trainer set with aggregated model parameters and configuration dictionary.

parameters

Aggregated model parameters for this coalition.

Type:

flwr.common.typing.Parameters

config

Configuration dictionary.

Type:

dict[str, bool | bytes | float | int | str]

config: dict[str, bool | bytes | float | int | str]
get_loss(aggregator: ~collections.abc.Callable[[list[float]], float] = <function mean>)[source]

Get the aggregated loss for this coalition.

Parameters:
  • aggregator – Function to aggregate multiple loss values.

  • mean. (Defaults to)

Returns:

The aggregated loss value, or infinity if no evaluations exist.

get_metric(name: str, default: bool | bytes | float | int | str, aggregator: Callable)[source]

Get an aggregated metric value for this coalition.

Parameters:
  • name – The metric name to retrieve.

  • default – Default value to return if metric is unavailable.

  • aggregator – Function to aggregate multiple metric values.

Returns:

The aggregated metric value, or default if not all evaluations contain this metric.

insert_res(eval_res: EvaluateRes)[source]

Add an evaluation result to this coalition.

Parameters:

eval_res – The evaluation result to store.

parameters: Parameters
class rizemind.strategies.contribution.shapley.trainer_set.TrainerSetAggregateStore[source]

Bases: object

Storage system for trainer set aggregates.

Maintains a collection of coalition aggregates indexed by their ids.

set_aggregates

Dictionary mapping coalition IDs to their aggregates.

Type:

dict[str, rizemind.strategies.contribution.shapley.trainer_set.TrainerSetAggregate]

clear() None[source]

Remove all coalition aggregates from the store.

get_set(id: str) TrainerSetAggregate[source]

Retrieve a specific coalition aggregate by ID.

Parameters:

id – The unique identifier of the coalition.

Returns:

The requested coalition aggregate.

Raises:

Exception – If no coalition with the given ID exists.

get_sets() list[TrainerSetAggregate][source]

Get all coalition aggregates.

Returns:

List of all stored coalition aggregates.

insert(aggregate: TrainerSetAggregate) None[source]

Insert a coalition aggregate in the store.

Parameters:

aggregate – The coalition aggregate to store.

is_available(id: str) bool[source]

Check if a coalition aggregate exists in the store.

Parameters:

id – The unique identifier to check.

Returns:

True if the coalition exists, False otherwise.

set_aggregates: dict[str, TrainerSetAggregate]