Trainer Mapping

Trainer Mapping#

class rizemind.strategies.contribution.shapley.trainer_mapping.ParticipantMapping[source]

Bases: object

Mapping between trainer addresses and their ids.

This class maintains a bijective mapping between trainer addresses and integer IDs, enabling efficient bit-mask representation of trainer coalitions for Shapley value calculation.

participant_ids

Dictionary mapping trainer addresses to their unique IDs.

Type:

dict[eth_typing.evm.ChecksumAddress, int]

add_participant(participant: ChecksumAddress) None[source]

Add a participant to the mapping.

If the participant doesn’t already exist, assigns them the next available ID.

Parameters:

participant – The trainer address to add.

exclude_participants(participants: ChecksumAddress | list[ChecksumAddress], id: str | None = None)[source]

Remove participants from a set.

Parameters:
  • participants – Single trainer address or list of addresses to exclude.

  • id – The set identifier to modify. If None, starts with empty set.

Returns:

String representation of the updated set bit mask.

get_participant_id(participant: ChecksumAddress) int[source]

Get the numerical ID for a participant.

Parameters:

participant – The trainer address to look up.

Returns:

The numerical ID assigned to this participant.

Raises:

ValueError – If the participant is not in the mapping.

get_participant_mask(participant: ChecksumAddress) int[source]

Get the bit mask for a participant.

Parameters:

participant – The trainer address.

Returns:

An integer with a single bit set representing this participant.

get_participant_set_id(participants: list[ChecksumAddress]) str[source]

Generate a unique set ID for a group of participants.

Parameters:

participants – List of trainer addresses in the set.

Returns:

String representation of the bit mask identifying this set.

get_participants() list[ChecksumAddress][source]

Get all participant addresses.

Returns:

List of all trainer addresses in the mapping.

get_total_participants() int[source]

Get the total number of participants.

Returns:

The count of unique participants in the mapping.

in_set(trainer: ChecksumAddress, id: str) bool[source]

Check if a trainer is a member of a set.

Parameters:
  • trainer – The trainer address to check.

  • id – The set identifier (bit mask as string).

Returns:

True if the trainer is in the set, False otherwise.

include_participants(participants: ChecksumAddress | list[ChecksumAddress], id: str | None = None)[source]

Add participants to a set.

Parameters:
  • participants – Single trainer address or list of addresses to include.

  • id – The set identifier to modify. If None, starts with empty set.

Returns:

String representation of the updated set bit mask.

participant_ids: dict[ChecksumAddress, int]