Random Neighbor Selector

class defSim.neighbor_selector_sim.RandomNeighborSelector.RandomNeighborSelector(**kwargs)

Bases: defSim.neighbor_selector_sim.neighbor_selector_sim.NeighborSelector

Implements the neighborSelector in such a way that either all neighbors are selected in the case of one-to-many and many-to-one communication, or a random neighbor in the case of one-to-one communication.

select_neighbors(network: networkx.classes.graph.Graph, focal_agent: int, regime: str, **kwargs) → Iterable[int]

Selects a random agent from the direct neighborhood of the focal agent in the case of one-to-one communication, and all direct neighbors otherwise.

Parameters
  • network – A NetworkX object

  • focal_agent – The index of the focal agent, who is either the source (for “one-to-one” or “one-to-many” communication) or target (for “many-to-one”) of influence.

  • regime – Whether the focal agent interacts with only one or many agents from his or her neighborhood. If “one-to-one”: One neighbor to which the focal agent has an outgoing tie is selected. If “one-to-many”: All neighbors to which the focal agent has an outgoing tie are selected. If “many-to-one”: All neighbors from which the focal agent has an incoming tie are selected.

  • kwargs – Additional parameters specific to the implementation of the InfluenceOperator.

Raises

ValueError if not one of the possible options for the communication_regime is chosen.

Returns

A list of the indices of the relevant other agents.