cognac.env.BinaryConsensus package
Submodules
cognac.env.BinaryConsensus.env module
- class cognac.env.BinaryConsensus.env.BinaryConsensusNetworkEnvironment(influence_graph: ~numpy.ndarray, max_steps: int = 100, show_neighborhood_state: bool = True, reward_class: type = <class 'cognac.env.BinaryConsensus.rewards.FactoredRewardModel'>, is_global_reward: bool = False)
Bases:
ParallelEnv
A multi-agent consensus environment where agents attempt to reach a binary consensus based on an influence graph.
- action_space(agent: int) Discrete
Define the action space for an agent.
- Args:
agent (int): Agent index.
- Returns:
Discrete: Action space (binary choice: 0 or 1).
- get_majority_value() int
Get the current majority value in the system.
- Returns:
int: 1 if majority is 1, 0 if majority is 0, -1 if tied.
- get_obs() dict
Retrieve the observation dictionary for all agents.
- Returns:
dict: Dictionary mapping agent indices to their respective observations.
- metadata: dict[str, Any] = {'name': 'consensus_binary_environment_v0'}
- observation_space(agent: int) MultiDiscrete
Define the observation space for a given agent.
- Args:
agent (int): Agent index.
- Returns:
MultiDiscrete: Observation space of the agent.
- render(save_frame: bool = False, fig=None, ax=None) None
Render the current state of the environment.
- Args:
save_frame (bool, optional): Whether to save the current frame as an image. Defaults to False. fig (matplotlib.figure.Figure, optional): Figure for rendering. Defaults to None. ax (matplotlib.axes.Axes, optional): Axes for rendering. Defaults to None.
- reset(seed: int = None, options: dict = None) tuple
Reset the environment to its initial state.
- Args:
seed (int, optional): Random seed. Defaults to None. options (dict, optional): Options for initialization, such as initial state vector. Defaults to None.
- Returns:
tuple: Observations and information dictionary.
- step(actions: dict) tuple
Execute one step in the environment given agents’ actions.
- Args:
actions (dict): Dictionary mapping agent indices to their actions.
- Returns:
tuple: Observations, rewards, terminations, truncations, and info.
cognac.env.BinaryConsensus.rewards module
- class cognac.env.BinaryConsensus.rewards.FactoredRewardModel(max_reward=100.0, min_reward=-100.0)
Bases:
BaseReward
- get_consensus_value(env) int
- Returns:
int : Current number of majority vote
- class cognac.env.BinaryConsensus.rewards.RewardWInitTarget(max_reward=10.0, min_reward=-10.0)
Bases:
BaseReward
- reset(init_state)