jaxabm.AgentCollection
- class jaxabm.AgentCollection(agent_type, num_agents)[source]
Bases:
objectCollection of agents of the same type.
This class manages a collection of agents of the same type, providing methods for initialization, updating, and accessing agent states.
- agent_type
The type of agent in the collection
- num_agents
Number of agents in the collection
- model_config
Model configuration associated with this collection (set during Model.initialize)
- _states
Dictionary of agent state variables, with each variable having shape (num_agents, …)
- _key
The JAX PRNGKey used to initialize this collection
- __init__(agent_type, num_agents)[source]
Initialize agent collection placeholder.
The actual state initialization happens during the init method, which is typically called by Model.initialize().
- Parameters:
agent_type (
AgentType) – The type of agent in this collection (must adhere to AgentType protocol)num_agents (
int) – The number of agents to create in this collection.
Methods
__init__(agent_type, num_agents)Initialize agent collection placeholder.
aggregate(variable[, fn])Aggregate a state variable across agents.
filter(condition)Filter agents based on a condition.
Get agent states (alias for states property for backward compatibility).
init(key, model_config)Initialize agent states.
update(model_state, key, model_config)Update all agents in the collection using JAX vmap.
Attributes
Get agent states.
- init(key, model_config)[source]
Initialize agent states.
This method initializes the states of all agents in the collection using the agent type’s init_state method. It is typically called by Model.initialize().
- Parameters:
key (
Any) – Random key for stochastic initialization.model_config (
ModelConfig) – Model configuration settings passed from the Model.
- Return type:
- update(model_state, key, model_config)[source]
Update all agents in the collection using JAX vmap.
This method updates the internal states (self._states) of all agents using their agent type’s update method, vectorized with jax.vmap. It assumes the agent type adheres to the AgentType protocol and its update method returns only the updated AgentState.